summaryrefslogtreecommitdiff
path: root/src/backends
diff options
context:
space:
mode:
Diffstat (limited to 'src/backends')
-rw-r--r--src/backends/edid-parse.c542
-rw-r--r--src/backends/edid.h193
-rw-r--r--src/backends/gsm-inhibitor-flag.h36
-rw-r--r--src/backends/meta-backend-private.h203
-rw-r--r--src/backends/meta-backend-types.h69
-rw-r--r--src/backends/meta-backend.c1663
-rw-r--r--src/backends/meta-barrier-private.h66
-rw-r--r--src/backends/meta-barrier.c365
-rw-r--r--src/backends/meta-crtc-mode.c200
-rw-r--r--src/backends/meta-crtc-mode.h93
-rw-r--r--src/backends/meta-crtc.c246
-rw-r--r--src/backends/meta-crtc.h77
-rw-r--r--src/backends/meta-cursor-renderer.c492
-rw-r--r--src/backends/meta-cursor-renderer.h82
-rw-r--r--src/backends/meta-cursor-sprite-xcursor.c371
-rw-r--r--src/backends/meta-cursor-sprite-xcursor.h43
-rw-r--r--src/backends/meta-cursor-tracker-private.h56
-rw-r--r--src/backends/meta-cursor-tracker.c514
-rw-r--r--src/backends/meta-cursor.c240
-rw-r--r--src/backends/meta-cursor.h85
-rw-r--r--src/backends/meta-dbus-session-watcher.c237
-rw-r--r--src/backends/meta-dbus-session-watcher.h52
-rw-r--r--src/backends/meta-display-config-shared.h39
-rw-r--r--src/backends/meta-dnd-private.h41
-rw-r--r--src/backends/meta-egl-ext.h103
-rw-r--r--src/backends/meta-egl.c1154
-rw-r--r--src/backends/meta-egl.h272
-rw-r--r--src/backends/meta-gles3-table.h36
-rw-r--r--src/backends/meta-gles3.c163
-rw-r--r--src/backends/meta-gles3.h83
-rw-r--r--src/backends/meta-gpu.c226
-rw-r--r--src/backends/meta-gpu.h72
-rw-r--r--src/backends/meta-idle-manager.c379
-rw-r--r--src/backends/meta-idle-manager.h39
-rw-r--r--src/backends/meta-idle-monitor-private.h53
-rw-r--r--src/backends/meta-idle-monitor.c530
-rw-r--r--src/backends/meta-input-device-private.h48
-rw-r--r--src/backends/meta-input-device.c138
-rw-r--r--src/backends/meta-input-mapper-private.h52
-rw-r--r--src/backends/meta-input-mapper.c986
-rw-r--r--src/backends/meta-input-settings-dummy.c295
-rw-r--r--src/backends/meta-input-settings-dummy.h34
-rw-r--r--src/backends/meta-input-settings-private.h204
-rw-r--r--src/backends/meta-input-settings.c1762
-rw-r--r--src/backends/meta-keymap-utils.c56
-rw-r--r--src/backends/meta-keymap-utils.h28
-rw-r--r--src/backends/meta-logical-monitor.c343
-rw-r--r--src/backends/meta-logical-monitor.h107
-rw-r--r--src/backends/meta-monitor-config-manager.c1899
-rw-r--r--src/backends/meta-monitor-config-manager.h201
-rw-r--r--src/backends/meta-monitor-config-migration.c1233
-rw-r--r--src/backends/meta-monitor-config-migration.h41
-rw-r--r--src/backends/meta-monitor-config-store.c1683
-rw-r--r--src/backends/meta-monitor-config-store.h60
-rw-r--r--src/backends/meta-monitor-manager-dummy.c816
-rw-r--r--src/backends/meta-monitor-manager-dummy.h48
-rw-r--r--src/backends/meta-monitor-manager-private.h439
-rw-r--r--src/backends/meta-monitor-manager.c3471
-rw-r--r--src/backends/meta-monitor-transform.c128
-rw-r--r--src/backends/meta-monitor-transform.h74
-rw-r--r--src/backends/meta-monitor.c1988
-rw-r--r--src/backends/meta-monitor.h280
-rw-r--r--src/backends/meta-orientation-manager.c335
-rw-r--r--src/backends/meta-orientation-manager.h44
-rw-r--r--src/backends/meta-output.c465
-rw-r--r--src/backends/meta-output.h192
-rw-r--r--src/backends/meta-pointer-constraint.c146
-rw-r--r--src/backends/meta-pointer-constraint.h77
-rw-r--r--src/backends/meta-profiler.c203
-rw-r--r--src/backends/meta-profiler.h41
-rw-r--r--src/backends/meta-remote-access-controller-private.h38
-rw-r--r--src/backends/meta-remote-access-controller.c283
-rw-r--r--src/backends/meta-remote-desktop-session.c1725
-rw-r--r--src/backends/meta-remote-desktop-session.h60
-rw-r--r--src/backends/meta-remote-desktop.c342
-rw-r--r--src/backends/meta-remote-desktop.h54
-rw-r--r--src/backends/meta-renderer-view.c247
-rw-r--r--src/backends/meta-renderer-view.h34
-rw-r--r--src/backends/meta-renderer.c405
-rw-r--r--src/backends/meta-renderer.h78
-rw-r--r--src/backends/meta-screen-cast-area-stream-src.c652
-rw-r--r--src/backends/meta-screen-cast-area-stream-src.h37
-rw-r--r--src/backends/meta-screen-cast-area-stream.c181
-rw-r--r--src/backends/meta-screen-cast-area-stream.h49
-rw-r--r--src/backends/meta-screen-cast-monitor-stream-src.c793
-rw-r--r--src/backends/meta-screen-cast-monitor-stream-src.h40
-rw-r--r--src/backends/meta-screen-cast-monitor-stream.c295
-rw-r--r--src/backends/meta-screen-cast-monitor-stream.h50
-rw-r--r--src/backends/meta-screen-cast-session.c825
-rw-r--r--src/backends/meta-screen-cast-session.h72
-rw-r--r--src/backends/meta-screen-cast-stream-src.c1237
-rw-r--r--src/backends/meta-screen-cast-stream-src.h117
-rw-r--r--src/backends/meta-screen-cast-stream.c383
-rw-r--r--src/backends/meta-screen-cast-stream.h74
-rw-r--r--src/backends/meta-screen-cast-virtual-stream-src.c612
-rw-r--r--src/backends/meta-screen-cast-virtual-stream-src.h38
-rw-r--r--src/backends/meta-screen-cast-virtual-stream.c121
-rw-r--r--src/backends/meta-screen-cast-virtual-stream.h40
-rw-r--r--src/backends/meta-screen-cast-window-stream-src.c614
-rw-r--r--src/backends/meta-screen-cast-window-stream-src.h37
-rw-r--r--src/backends/meta-screen-cast-window-stream.c285
-rw-r--r--src/backends/meta-screen-cast-window-stream.h46
-rw-r--r--src/backends/meta-screen-cast-window.c99
-rw-r--r--src/backends/meta-screen-cast-window.h93
-rw-r--r--src/backends/meta-screen-cast.c385
-rw-r--r--src/backends/meta-screen-cast.h69
-rw-r--r--src/backends/meta-settings-private.h81
-rw-r--r--src/backends/meta-settings.c559
-rw-r--r--src/backends/meta-stage-impl-private.h76
-rw-r--r--src/backends/meta-stage-impl.c756
-rw-r--r--src/backends/meta-stage-private.h79
-rw-r--r--src/backends/meta-stage-view-private.h51
-rw-r--r--src/backends/meta-stage-view.c204
-rw-r--r--src/backends/meta-stage.c485
-rw-r--r--src/backends/meta-viewport-info.c223
-rw-r--r--src/backends/meta-viewport-info.h61
-rw-r--r--src/backends/meta-virtual-monitor.c238
-rw-r--r--src/backends/meta-virtual-monitor.h71
-rw-r--r--src/backends/native/dbus-utils.c107
-rw-r--r--src/backends/native/dbus-utils.h32
-rwxr-xr-xsrc/backends/native/gen-default-modes.py127
-rw-r--r--src/backends/native/meta-backend-native-private.h35
-rw-r--r--src/backends/native/meta-backend-native-types.h41
-rw-r--r--src/backends/native/meta-backend-native.c768
-rw-r--r--src/backends/native/meta-backend-native.h55
-rw-r--r--src/backends/native/meta-barrier-native.c652
-rw-r--r--src/backends/native/meta-barrier-native.h52
-rw-r--r--src/backends/native/meta-clutter-backend-native.c111
-rw-r--r--src/backends/native/meta-clutter-backend-native.h38
-rw-r--r--src/backends/native/meta-cogl-utils.c85
-rw-r--r--src/backends/native/meta-cogl-utils.h38
-rw-r--r--src/backends/native/meta-crtc-kms.c386
-rw-r--r--src/backends/native/meta-crtc-kms.h83
-rw-r--r--src/backends/native/meta-crtc-mode-kms.c81
-rw-r--r--src/backends/native/meta-crtc-mode-kms.h39
-rw-r--r--src/backends/native/meta-crtc-mode-virtual.c70
-rw-r--r--src/backends/native/meta-crtc-mode-virtual.h34
-rw-r--r--src/backends/native/meta-crtc-native.c44
-rw-r--r--src/backends/native/meta-crtc-native.h41
-rw-r--r--src/backends/native/meta-crtc-virtual.c60
-rw-r--r--src/backends/native/meta-crtc-virtual.h32
-rw-r--r--src/backends/native/meta-cursor-renderer-native.c1878
-rw-r--r--src/backends/native/meta-cursor-renderer-native.h42
-rw-r--r--src/backends/native/meta-device-pool-private.h35
-rw-r--r--src/backends/native/meta-device-pool.c390
-rw-r--r--src/backends/native/meta-device-pool.h68
-rw-r--r--src/backends/native/meta-drm-buffer-dumb.c287
-rw-r--r--src/backends/native/meta-drm-buffer-dumb.h45
-rw-r--r--src/backends/native/meta-drm-buffer-gbm.c474
-rw-r--r--src/backends/native/meta-drm-buffer-gbm.h49
-rw-r--r--src/backends/native/meta-drm-buffer-import.c209
-rw-r--r--src/backends/native/meta-drm-buffer-import.h55
-rw-r--r--src/backends/native/meta-drm-buffer-private.h64
-rw-r--r--src/backends/native/meta-drm-buffer.c296
-rw-r--r--src/backends/native/meta-drm-buffer.h53
-rw-r--r--src/backends/native/meta-gpu-kms.c422
-rw-r--r--src/backends/native/meta-gpu-kms.h74
-rw-r--r--src/backends/native/meta-input-device-native.c1599
-rw-r--r--src/backends/native/meta-input-device-native.h162
-rw-r--r--src/backends/native/meta-input-device-tool-native.c183
-rw-r--r--src/backends/native/meta-input-device-tool-native.h90
-rw-r--r--src/backends/native/meta-input-settings-native.c876
-rw-r--r--src/backends/native/meta-input-settings-native.h56
-rw-r--r--src/backends/native/meta-input-thread.h33
-rw-r--r--src/backends/native/meta-keymap-native.c152
-rw-r--r--src/backends/native/meta-keymap-native.h43
-rw-r--r--src/backends/native/meta-kms-connector-private.h54
-rw-r--r--src/backends/native/meta-kms-connector.c700
-rw-r--r--src/backends/native/meta-kms-connector.h77
-rw-r--r--src/backends/native/meta-kms-crtc-private.h51
-rw-r--r--src/backends/native/meta-kms-crtc.c399
-rw-r--r--src/backends/native/meta-kms-crtc.h79
-rw-r--r--src/backends/native/meta-kms-device-private.h36
-rw-r--r--src/backends/native/meta-kms-device.c439
-rw-r--r--src/backends/native/meta-kms-device.h69
-rw-r--r--src/backends/native/meta-kms-impl-device-atomic.c1202
-rw-r--r--src/backends/native/meta-kms-impl-device-atomic.h29
-rw-r--r--src/backends/native/meta-kms-impl-device-dummy.c127
-rw-r--r--src/backends/native/meta-kms-impl-device-dummy.h30
-rw-r--r--src/backends/native/meta-kms-impl-device-simple.c1678
-rw-r--r--src/backends/native/meta-kms-impl-device-simple.h29
-rw-r--r--src/backends/native/meta-kms-impl-device.c1070
-rw-r--r--src/backends/native/meta-kms-impl-device.h178
-rw-r--r--src/backends/native/meta-kms-impl.c204
-rw-r--r--src/backends/native/meta-kms-impl.h52
-rw-r--r--src/backends/native/meta-kms-mode-private.h34
-rw-r--r--src/backends/native/meta-kms-mode.c143
-rw-r--r--src/backends/native/meta-kms-mode.h47
-rw-r--r--src/backends/native/meta-kms-page-flip-private.h65
-rw-r--r--src/backends/native/meta-kms-page-flip.c288
-rw-r--r--src/backends/native/meta-kms-plane-private.h64
-rw-r--r--src/backends/native/meta-kms-plane.c537
-rw-r--r--src/backends/native/meta-kms-plane.h65
-rw-r--r--src/backends/native/meta-kms-private.h65
-rw-r--r--src/backends/native/meta-kms-types.h75
-rw-r--r--src/backends/native/meta-kms-update-private.h157
-rw-r--r--src/backends/native/meta-kms-update.c645
-rw-r--r--src/backends/native/meta-kms-update.h181
-rw-r--r--src/backends/native/meta-kms-utils.c103
-rw-r--r--src/backends/native/meta-kms-utils.h43
-rw-r--r--src/backends/native/meta-kms.c754
-rw-r--r--src/backends/native/meta-kms.h74
-rw-r--r--src/backends/native/meta-launcher.c410
-rw-r--r--src/backends/native/meta-launcher.h40
-rw-r--r--src/backends/native/meta-monitor-manager-native.c825
-rw-r--r--src/backends/native/meta-monitor-manager-native.h49
-rw-r--r--src/backends/native/meta-onscreen-native.c2137
-rw-r--r--src/backends/native/meta-onscreen-native.h59
-rw-r--r--src/backends/native/meta-output-kms.c414
-rw-r--r--src/backends/native/meta-output-kms.h55
-rw-r--r--src/backends/native/meta-output-native.c43
-rw-r--r--src/backends/native/meta-output-native.h39
-rw-r--r--src/backends/native/meta-output-virtual.c80
-rw-r--r--src/backends/native/meta-output-virtual.h36
-rw-r--r--src/backends/native/meta-pointer-constraint-native.c694
-rw-r--r--src/backends/native/meta-pointer-constraint-native.h46
-rw-r--r--src/backends/native/meta-renderer-native-gles3.c160
-rw-r--r--src/backends/native/meta-renderer-native-gles3.h40
-rw-r--r--src/backends/native/meta-renderer-native-private.h115
-rw-r--r--src/backends/native/meta-renderer-native.c2264
-rw-r--r--src/backends/native/meta-renderer-native.h71
-rw-r--r--src/backends/native/meta-seat-impl.c3542
-rw-r--r--src/backends/native/meta-seat-impl.h254
-rw-r--r--src/backends/native/meta-seat-native.c634
-rw-r--r--src/backends/native/meta-seat-native.h133
-rw-r--r--src/backends/native/meta-stage-native.c191
-rw-r--r--src/backends/native/meta-stage-native.h37
-rw-r--r--src/backends/native/meta-udev.c274
-rw-r--r--src/backends/native/meta-udev.h49
-rw-r--r--src/backends/native/meta-virtual-input-device-native.c1110
-rw-r--r--src/backends/native/meta-virtual-input-device-native.h31
-rw-r--r--src/backends/native/meta-virtual-monitor-native.c80
-rw-r--r--src/backends/native/meta-virtual-monitor-native.h45
-rw-r--r--src/backends/native/meta-xkb-utils.c137
-rw-r--r--src/backends/native/meta-xkb-utils.h43
-rw-r--r--src/backends/x11/cm/meta-backend-x11-cm.c550
-rw-r--r--src/backends/x11/cm/meta-backend-x11-cm.h31
-rw-r--r--src/backends/x11/cm/meta-cursor-sprite-xfixes.c231
-rw-r--r--src/backends/x11/cm/meta-cursor-sprite-xfixes.h36
-rw-r--r--src/backends/x11/cm/meta-renderer-x11-cm.c113
-rw-r--r--src/backends/x11/cm/meta-renderer-x11-cm.h42
-rw-r--r--src/backends/x11/meta-backend-x11.c996
-rw-r--r--src/backends/x11/meta-backend-x11.h63
-rw-r--r--src/backends/x11/meta-barrier-x11.c212
-rw-r--r--src/backends/x11/meta-barrier-x11.h42
-rw-r--r--src/backends/x11/meta-clutter-backend-x11.c745
-rw-r--r--src/backends/x11/meta-clutter-backend-x11.h96
-rw-r--r--src/backends/x11/meta-crtc-xrandr.c308
-rw-r--r--src/backends/x11/meta-crtc-xrandr.h57
-rw-r--r--src/backends/x11/meta-cursor-renderer-x11.c114
-rw-r--r--src/backends/x11/meta-cursor-renderer-x11.h52
-rw-r--r--src/backends/x11/meta-cursor-tracker-x11.c186
-rw-r--r--src/backends/x11/meta-cursor-tracker-x11.h34
-rw-r--r--src/backends/x11/meta-event-x11.c114
-rw-r--r--src/backends/x11/meta-event-x11.h33
-rw-r--r--src/backends/x11/meta-gpu-xrandr.c277
-rw-r--r--src/backends/x11/meta-gpu-xrandr.h42
-rw-r--r--src/backends/x11/meta-input-device-tool-x11.c56
-rw-r--r--src/backends/x11/meta-input-device-tool-x11.h51
-rw-r--r--src/backends/x11/meta-input-device-x11.c795
-rw-r--r--src/backends/x11/meta-input-device-x11.h102
-rw-r--r--src/backends/x11/meta-input-settings-x11.c948
-rw-r--r--src/backends/x11/meta-input-settings-x11.h49
-rw-r--r--src/backends/x11/meta-keymap-x11.c949
-rw-r--r--src/backends/x11/meta-keymap-x11.h61
-rw-r--r--src/backends/x11/meta-monitor-manager-xrandr.c1151
-rw-r--r--src/backends/x11/meta-monitor-manager-xrandr.h41
-rw-r--r--src/backends/x11/meta-output-xrandr.c987
-rw-r--r--src/backends/x11/meta-output-xrandr.h52
-rw-r--r--src/backends/x11/meta-renderer-x11.c107
-rw-r--r--src/backends/x11/meta-renderer-x11.h42
-rw-r--r--src/backends/x11/meta-seat-x11.c2422
-rw-r--r--src/backends/x11/meta-seat-x11.h44
-rw-r--r--src/backends/x11/meta-stage-x11.c853
-rw-r--r--src/backends/x11/meta-stage-x11.h96
-rw-r--r--src/backends/x11/meta-virtual-input-device-x11.c253
-rw-r--r--src/backends/x11/meta-virtual-input-device-x11.h31
-rw-r--r--src/backends/x11/meta-xkb-a11y-x11.c339
-rw-r--r--src/backends/x11/meta-xkb-a11y-x11.h39
-rw-r--r--src/backends/x11/nested/meta-backend-x11-nested.c320
-rw-r--r--src/backends/x11/nested/meta-backend-x11-nested.h40
-rw-r--r--src/backends/x11/nested/meta-cursor-renderer-x11-nested.c91
-rw-r--r--src/backends/x11/nested/meta-cursor-renderer-x11-nested.h38
-rw-r--r--src/backends/x11/nested/meta-renderer-x11-nested.c248
-rw-r--r--src/backends/x11/nested/meta-renderer-x11-nested.h37
-rw-r--r--src/backends/x11/nested/meta-stage-x11-nested.c236
-rw-r--r--src/backends/x11/nested/meta-stage-x11-nested.h35
287 files changed, 0 insertions, 89939 deletions
diff --git a/src/backends/edid-parse.c b/src/backends/edid-parse.c
deleted file mode 100644
index a7b9fd225..000000000
--- a/src/backends/edid-parse.c
+++ /dev/null
@@ -1,542 +0,0 @@
-/*
- * Copyright 2007 Red Hat, Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * on the rights to use, copy, modify, merge, publish, distribute, sub
- * license, and/or sell copies of the Software, and to permit persons to whom
- * the Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
- * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-/* Author: Soren Sandmann <sandmann@redhat.com> */
-
-#include "config.h"
-
-#include <stdlib.h>
-#include <string.h>
-#include <math.h>
-#include <glib.h>
-
-#include "backends/edid.h"
-
-static int
-get_bit (int in, int bit)
-{
- return (in & (1 << bit)) >> bit;
-}
-
-static int
-get_bits (int in, int begin, int end)
-{
- int mask = (1 << (end - begin + 1)) - 1;
-
- return (in >> begin) & mask;
-}
-
-static int
-decode_header (const uchar *edid)
-{
- if (memcmp (edid, "\x00\xff\xff\xff\xff\xff\xff\x00", 8) == 0)
- return TRUE;
- return FALSE;
-}
-
-static int
-decode_vendor_and_product_identification (const uchar *edid, MonitorInfo *info)
-{
- int is_model_year;
-
- /* Manufacturer Code */
- info->manufacturer_code[0] = get_bits (edid[0x08], 2, 6);
- info->manufacturer_code[1] = get_bits (edid[0x08], 0, 1) << 3;
- info->manufacturer_code[1] |= get_bits (edid[0x09], 5, 7);
- info->manufacturer_code[2] = get_bits (edid[0x09], 0, 4);
- info->manufacturer_code[3] = '\0';
-
- info->manufacturer_code[0] += 'A' - 1;
- info->manufacturer_code[1] += 'A' - 1;
- info->manufacturer_code[2] += 'A' - 1;
-
- /* Product Code */
- info->product_code = edid[0x0b] << 8 | edid[0x0a];
-
- /* Serial Number */
- info->serial_number =
- edid[0x0c] | edid[0x0d] << 8 | edid[0x0e] << 16 | edid[0x0f] << 24;
-
- /* Week and Year */
- is_model_year = FALSE;
- switch (edid[0x10])
- {
- case 0x00:
- info->production_week = -1;
- break;
-
- case 0xff:
- info->production_week = -1;
- is_model_year = TRUE;
- break;
-
- default:
- info->production_week = edid[0x10];
- break;
- }
-
- if (is_model_year)
- {
- info->production_year = -1;
- info->model_year = 1990 + edid[0x11];
- }
- else
- {
- info->production_year = 1990 + edid[0x11];
- info->model_year = -1;
- }
-
- return TRUE;
-}
-
-static int
-decode_edid_version (const uchar *edid, MonitorInfo *info)
-{
- info->major_version = edid[0x12];
- info->minor_version = edid[0x13];
-
- return TRUE;
-}
-
-static int
-decode_display_parameters (const uchar *edid, MonitorInfo *info)
-{
- /* Digital vs Analog */
- info->is_digital = get_bit (edid[0x14], 7);
-
- if (info->is_digital)
- {
- int bits;
-
- static const int bit_depth[8] =
- {
- -1, 6, 8, 10, 12, 14, 16, -1
- };
-
- static const Interface interfaces[6] =
- {
- UNDEFINED, DVI, HDMI_A, HDMI_B, MDDI, DISPLAY_PORT
- };
-
- bits = get_bits (edid[0x14], 4, 6);
- info->connector.digital.bits_per_primary = bit_depth[bits];
-
- bits = get_bits (edid[0x14], 0, 3);
-
- if (bits <= 5)
- info->connector.digital.interface = interfaces[bits];
- else
- info->connector.digital.interface = UNDEFINED;
- }
- else
- {
- int bits = get_bits (edid[0x14], 5, 6);
-
- static const double levels[][3] =
- {
- { 0.7, 0.3, 1.0 },
- { 0.714, 0.286, 1.0 },
- { 1.0, 0.4, 1.4 },
- { 0.7, 0.0, 0.7 },
- };
-
- info->connector.analog.video_signal_level = levels[bits][0];
- info->connector.analog.sync_signal_level = levels[bits][1];
- info->connector.analog.total_signal_level = levels[bits][2];
-
- info->connector.analog.blank_to_black = get_bit (edid[0x14], 4);
-
- info->connector.analog.separate_hv_sync = get_bit (edid[0x14], 3);
- info->connector.analog.composite_sync_on_h = get_bit (edid[0x14], 2);
- info->connector.analog.composite_sync_on_green = get_bit (edid[0x14], 1);
-
- info->connector.analog.serration_on_vsync = get_bit (edid[0x14], 0);
- }
-
- /* Screen Size / Aspect Ratio */
- if (edid[0x15] == 0 && edid[0x16] == 0)
- {
- info->width_mm = -1;
- info->height_mm = -1;
- info->aspect_ratio = -1.0;
- }
- else if (edid[0x16] == 0)
- {
- info->width_mm = -1;
- info->height_mm = -1;
- info->aspect_ratio = 100.0 / (edid[0x15] + 99);
- }
- else if (edid[0x15] == 0)
- {
- info->width_mm = -1;
- info->height_mm = -1;
- info->aspect_ratio = 100.0 / (edid[0x16] + 99);
- info->aspect_ratio = 1/info->aspect_ratio; /* portrait */
- }
- else
- {
- info->width_mm = 10 * edid[0x15];
- info->height_mm = 10 * edid[0x16];
- }
-
- /* Gamma */
- if (edid[0x17] == 0xFF)
- info->gamma = -1.0;
- else
- info->gamma = (edid[0x17] + 100.0) / 100.0;
-
- /* Features */
- info->standby = get_bit (edid[0x18], 7);
- info->suspend = get_bit (edid[0x18], 6);
- info->active_off = get_bit (edid[0x18], 5);
-
- if (info->is_digital)
- {
- info->connector.digital.rgb444 = TRUE;
- if (get_bit (edid[0x18], 3))
- info->connector.digital.ycrcb444 = 1;
- if (get_bit (edid[0x18], 4))
- info->connector.digital.ycrcb422 = 1;
- }
- else
- {
- int bits = get_bits (edid[0x18], 3, 4);
- ColorType color_type[4] =
- {
- MONOCHROME, RGB, OTHER_COLOR, UNDEFINED_COLOR
- };
-
- info->connector.analog.color_type = color_type[bits];
- }
-
- info->srgb_is_standard = get_bit (edid[0x18], 2);
-
- /* In 1.3 this is called "has preferred timing" */
- info->preferred_timing_includes_native = get_bit (edid[0x18], 1);
-
- /* FIXME: In 1.3 this indicates whether the monitor accepts GTF */
- info->continuous_frequency = get_bit (edid[0x18], 0);
- return TRUE;
-}
-
-static double
-decode_fraction (int high, int low)
-{
- double result = 0.0;
- int i;
-
- high = (high << 2) | low;
-
- for (i = 0; i < 10; ++i)
- result += get_bit (high, i) * pow (2, i - 10);
-
- return result;
-}
-
-static int
-decode_color_characteristics (const uchar *edid, MonitorInfo *info)
-{
- info->red_x = decode_fraction (edid[0x1b], get_bits (edid[0x19], 6, 7));
- info->red_y = decode_fraction (edid[0x1c], get_bits (edid[0x19], 5, 4));
- info->green_x = decode_fraction (edid[0x1d], get_bits (edid[0x19], 2, 3));
- info->green_y = decode_fraction (edid[0x1e], get_bits (edid[0x19], 0, 1));
- info->blue_x = decode_fraction (edid[0x1f], get_bits (edid[0x1a], 6, 7));
- info->blue_y = decode_fraction (edid[0x20], get_bits (edid[0x1a], 4, 5));
- info->white_x = decode_fraction (edid[0x21], get_bits (edid[0x1a], 2, 3));
- info->white_y = decode_fraction (edid[0x22], get_bits (edid[0x1a], 0, 1));
-
- return TRUE;
-}
-
-static int
-decode_established_timings (const uchar *edid, MonitorInfo *info)
-{
- static const Timing established[][8] =
- {
- {
- { 800, 600, 60 },
- { 800, 600, 56 },
- { 640, 480, 75 },
- { 640, 480, 72 },
- { 640, 480, 67 },
- { 640, 480, 60 },
- { 720, 400, 88 },
- { 720, 400, 70 }
- },
- {
- { 1280, 1024, 75 },
- { 1024, 768, 75 },
- { 1024, 768, 70 },
- { 1024, 768, 60 },
- { 1024, 768, 87 },
- { 832, 624, 75 },
- { 800, 600, 75 },
- { 800, 600, 72 }
- },
- {
- { 0, 0, 0 },
- { 0, 0, 0 },
- { 0, 0, 0 },
- { 0, 0, 0 },
- { 0, 0, 0 },
- { 0, 0, 0 },
- { 0, 0, 0 },
- { 1152, 870, 75 }
- },
- };
-
- int i, j, idx;
-
- idx = 0;
- for (i = 0; i < 3; ++i)
- {
- for (j = 0; j < 8; ++j)
- {
- int byte = edid[0x23 + i];
-
- if (get_bit (byte, j) && established[i][j].frequency != 0)
- info->established[idx++] = established[i][j];
- }
- }
- return TRUE;
-}
-
-static int
-decode_standard_timings (const uchar *edid, MonitorInfo *info)
-{
- int i;
-
- for (i = 0; i < 8; i++)
- {
- int first = edid[0x26 + 2 * i];
- int second = edid[0x27 + 2 * i];
-
- if (first != 0x01 && second != 0x01)
- {
- int w = 8 * (first + 31);
- int h = 0;
-
- switch (get_bits (second, 6, 7))
- {
- case 0x00: h = (w / 16) * 10; break;
- case 0x01: h = (w / 4) * 3; break;
- case 0x02: h = (w / 5) * 4; break;
- case 0x03: h = (w / 16) * 9; break;
- }
-
- info->standard[i].width = w;
- info->standard[i].height = h;
- info->standard[i].frequency = get_bits (second, 0, 5) + 60;
- }
- }
-
- return TRUE;
-}
-
-static void
-decode_lf_string (const uchar *s, int n_chars, char *result)
-{
- int i;
- for (i = 0; i < n_chars; ++i)
- {
- if (s[i] == 0x0a)
- {
- *result++ = '\0';
- break;
- }
- else if (s[i] == 0x00)
- {
- /* Convert embedded 0's to spaces */
- *result++ = ' ';
- }
- else
- {
- *result++ = s[i];
- }
- }
-}
-
-static void
-decode_display_descriptor (const uchar *desc,
- MonitorInfo *info)
-{
- switch (desc[0x03])
- {
- case 0xFC:
- decode_lf_string (desc + 5, 13, info->dsc_product_name);
- break;
- case 0xFF:
- decode_lf_string (desc + 5, 13, info->dsc_serial_number);
- break;
- case 0xFE:
- decode_lf_string (desc + 5, 13, info->dsc_string);
- break;
- case 0xFD:
- /* Range Limits */
- break;
- case 0xFB:
- /* Color Point */
- break;
- case 0xFA:
- /* Timing Identifications */
- break;
- case 0xF9:
- /* Color Management */
- break;
- case 0xF8:
- /* Timing Codes */
- break;
- case 0xF7:
- /* Established Timings */
- break;
- case 0x10:
- break;
- }
-}
-
-static void
-decode_detailed_timing (const uchar *timing,
- DetailedTiming *detailed)
-{
- int bits;
- StereoType stereo[] =
- {
- NO_STEREO, NO_STEREO, FIELD_RIGHT, FIELD_LEFT,
- TWO_WAY_RIGHT_ON_EVEN, TWO_WAY_LEFT_ON_EVEN,
- FOUR_WAY_INTERLEAVED, SIDE_BY_SIDE
- };
-
- detailed->pixel_clock = (timing[0x00] | timing[0x01] << 8) * 10000;
- detailed->h_addr = timing[0x02] | ((timing[0x04] & 0xf0) << 4);
- detailed->h_blank = timing[0x03] | ((timing[0x04] & 0x0f) << 8);
- detailed->v_addr = timing[0x05] | ((timing[0x07] & 0xf0) << 4);
- detailed->v_blank = timing[0x06] | ((timing[0x07] & 0x0f) << 8);
- detailed->h_front_porch = timing[0x08] | get_bits (timing[0x0b], 6, 7) << 8;
- detailed->h_sync = timing[0x09] | get_bits (timing[0x0b], 4, 5) << 8;
- detailed->v_front_porch =
- get_bits (timing[0x0a], 4, 7) | get_bits (timing[0x0b], 2, 3) << 4;
- detailed->v_sync =
- get_bits (timing[0x0a], 0, 3) | get_bits (timing[0x0b], 0, 1) << 4;
- detailed->width_mm = timing[0x0c] | get_bits (timing[0x0e], 4, 7) << 8;
- detailed->height_mm = timing[0x0d] | get_bits (timing[0x0e], 0, 3) << 8;
- detailed->right_border = timing[0x0f];
- detailed->top_border = timing[0x10];
-
- detailed->interlaced = get_bit (timing[0x11], 7);
-
- /* Stereo */
- bits = get_bits (timing[0x11], 5, 6) << 1 | get_bit (timing[0x11], 0);
- detailed->stereo = stereo[bits];
-
- /* Sync */
- bits = timing[0x11];
-
- detailed->digital_sync = get_bit (bits, 4);
- if (detailed->digital_sync)
- {
- detailed->connector.digital.composite = !get_bit (bits, 3);
-
- if (detailed->connector.digital.composite)
- {
- detailed->connector.digital.serrations = get_bit (bits, 2);
- detailed->connector.digital.negative_vsync = FALSE;
- }
- else
- {
- detailed->connector.digital.serrations = FALSE;
- detailed->connector.digital.negative_vsync = !get_bit (bits, 2);
- }
-
- detailed->connector.digital.negative_hsync = !get_bit (bits, 0);
- }
- else
- {
- detailed->connector.analog.bipolar = get_bit (bits, 3);
- detailed->connector.analog.serrations = get_bit (bits, 2);
- detailed->connector.analog.sync_on_green = !get_bit (bits, 1);
- }
-}
-
-static int
-decode_descriptors (const uchar *edid, MonitorInfo *info)
-{
- int i;
- int timing_idx;
-
- timing_idx = 0;
-
- for (i = 0; i < 4; ++i)
- {
- int index = 0x36 + i * 18;
-
- if (edid[index + 0] == 0x00 && edid[index + 1] == 0x00)
- {
- decode_display_descriptor (edid + index, info);
- }
- else
- {
- decode_detailed_timing (edid + index, &(info->detailed_timings[timing_idx++]));
- }
- }
-
- info->n_detailed_timings = timing_idx;
-
- return TRUE;
-}
-
-static void
-decode_check_sum (const uchar *edid,
- MonitorInfo *info)
-{
- int i;
- uchar check = 0;
-
- for (i = 0; i < 128; ++i)
- check += edid[i];
-
- info->checksum = check;
-}
-
-MonitorInfo *
-decode_edid (const uchar *edid)
-{
- MonitorInfo *info = g_new0 (MonitorInfo, 1);
-
- decode_check_sum (edid, info);
-
- if (decode_header (edid)
- && decode_vendor_and_product_identification (edid, info)
- && decode_edid_version (edid, info)
- && decode_display_parameters (edid, info)
- && decode_color_characteristics (edid, info)
- && decode_established_timings (edid, info)
- && decode_standard_timings (edid, info)
- && decode_descriptors (edid, info))
- {
- return info;
- }
- else
- {
- g_free (info);
- return NULL;
- }
-}
diff --git a/src/backends/edid.h b/src/backends/edid.h
deleted file mode 100644
index f07fd9e55..000000000
--- a/src/backends/edid.h
+++ /dev/null
@@ -1,193 +0,0 @@
-/* edid.h
- *
- * Copyright 2007, 2008, Red Hat, Inc.
- *
- * This file is part of the Gnome Library.
- *
- * The Gnome Library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * The Gnome Library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with the Gnome Library; see the file COPYING.LIB. If not,
- * write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
- *
- * Author: Soren Sandmann <sandmann@redhat.com>
- */
-
-#ifndef EDID_H
-#define EDID_H
-
-typedef unsigned char uchar;
-typedef struct MonitorInfo MonitorInfo;
-typedef struct Timing Timing;
-typedef struct DetailedTiming DetailedTiming;
-
-typedef enum
-{
- UNDEFINED,
- DVI,
- HDMI_A,
- HDMI_B,
- MDDI,
- DISPLAY_PORT
-} Interface;
-
-typedef enum
-{
- UNDEFINED_COLOR,
- MONOCHROME,
- RGB,
- OTHER_COLOR
-} ColorType;
-
-typedef enum
-{
- NO_STEREO,
- FIELD_RIGHT,
- FIELD_LEFT,
- TWO_WAY_RIGHT_ON_EVEN,
- TWO_WAY_LEFT_ON_EVEN,
- FOUR_WAY_INTERLEAVED,
- SIDE_BY_SIDE
-} StereoType;
-
-struct Timing
-{
- int width;
- int height;
- int frequency;
-};
-
-struct DetailedTiming
-{
- int pixel_clock;
- int h_addr;
- int h_blank;
- int h_sync;
- int h_front_porch;
- int v_addr;
- int v_blank;
- int v_sync;
- int v_front_porch;
- int width_mm;
- int height_mm;
- int right_border;
- int top_border;
- int interlaced;
- StereoType stereo;
-
- int digital_sync;
- union
- {
- struct
- {
- int bipolar;
- int serrations;
- int sync_on_green;
- } analog;
-
- struct
- {
- int composite;
- int serrations;
- int negative_vsync;
- int negative_hsync;
- } digital;
- } connector;
-};
-
-struct MonitorInfo
-{
- int checksum;
- char manufacturer_code[4];
- int product_code;
- unsigned int serial_number;
-
- int production_week; /* -1 if not specified */
- int production_year; /* -1 if not specified */
- int model_year; /* -1 if not specified */
-
- int major_version;
- int minor_version;
-
- int is_digital;
-
- union
- {
- struct
- {
- int bits_per_primary;
- Interface interface;
- int rgb444;
- int ycrcb444;
- int ycrcb422;
- } digital;
-
- struct
- {
- double video_signal_level;
- double sync_signal_level;
- double total_signal_level;
-
- int blank_to_black;
-
- int separate_hv_sync;
- int composite_sync_on_h;
- int composite_sync_on_green;
- int serration_on_vsync;
- ColorType color_type;
- } analog;
- } connector;
-
- int width_mm; /* -1 if not specified */
- int height_mm; /* -1 if not specified */
- double aspect_ratio; /* -1.0 if not specififed */
-
- double gamma; /* -1.0 if not specified */
-
- int standby;
- int suspend;
- int active_off;
-
- int srgb_is_standard;
- int preferred_timing_includes_native;
- int continuous_frequency;
-
- double red_x;
- double red_y;
- double green_x;
- double green_y;
- double blue_x;
- double blue_y;
- double white_x;
- double white_y;
-
- Timing established[24]; /* Terminated by 0x0x0 */
- Timing standard[8];
-
- int n_detailed_timings;
- DetailedTiming detailed_timings[4]; /* If monitor has a preferred
- * mode, it is the first one
- * (whether it has, is
- * determined by the
- * preferred_timing_includes
- * bit.
- */
-
- /* Optional product description */
- char dsc_serial_number[14];
- char dsc_product_name[14];
- char dsc_string[14]; /* Unspecified ASCII data */
-};
-
-MonitorInfo *decode_edid (const uchar *data);
-
-#endif
diff --git a/src/backends/gsm-inhibitor-flag.h b/src/backends/gsm-inhibitor-flag.h
deleted file mode 100644
index 40698f96a..000000000
--- a/src/backends/gsm-inhibitor-flag.h
+++ /dev/null
@@ -1,36 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
- *
- * Copyright (C) 2008 Red Hat, Inc.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef __GSM_INHIBITOR_FLAG_H__
-#define __GSM_INHIBITOR_FLAG_H__
-
-#include <glib-object.h>
-
-G_BEGIN_DECLS
-
-typedef enum {
- GSM_INHIBITOR_FLAG_LOGOUT = 1 << 0,
- GSM_INHIBITOR_FLAG_SWITCH_USER = 1 << 1,
- GSM_INHIBITOR_FLAG_SUSPEND = 1 << 2,
- GSM_INHIBITOR_FLAG_IDLE = 1 << 3,
- GSM_INHIBITOR_FLAG_AUTOMOUNT = 1 << 4
-} GsmInhibitorFlag;
-
-G_END_DECLS
-
-#endif /* __GSM_INHIBITOR_FLAG_H__ */
diff --git a/src/backends/meta-backend-private.h b/src/backends/meta-backend-private.h
deleted file mode 100644
index 81104e2d0..000000000
--- a/src/backends/meta-backend-private.h
+++ /dev/null
@@ -1,203 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2014 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Written by:
- * Jasper St. Pierre <jstpierre@mecheye.net>
- */
-
-
-#ifndef META_BACKEND_PRIVATE_H
-#define META_BACKEND_PRIVATE_H
-
-#include <glib-object.h>
-#include <xkbcommon/xkbcommon.h>
-
-#include "meta/meta-backend.h"
-#include "meta/meta-idle-monitor.h"
-#include "backends/meta-backend-types.h"
-#include "backends/meta-cursor-renderer.h"
-#include "backends/meta-egl.h"
-#include "backends/meta-input-mapper-private.h"
-#include "backends/meta-input-settings-private.h"
-#include "backends/meta-monitor-manager-private.h"
-#include "backends/meta-orientation-manager.h"
-#include "backends/meta-pointer-constraint.h"
-#include "backends/meta-renderer.h"
-#include "backends/meta-settings-private.h"
-#include "core/meta-context-private.h"
-#include "core/util-private.h"
-
-#define DEFAULT_XKB_RULES_FILE "evdev"
-#define DEFAULT_XKB_MODEL "pc105+inet"
-
-typedef enum
-{
- META_SEQUENCE_NONE,
- META_SEQUENCE_ACCEPTED,
- META_SEQUENCE_REJECTED,
- META_SEQUENCE_PENDING_END
-} MetaSequenceState;
-
-struct _MetaBackendClass
-{
- GObjectClass parent_class;
-
- ClutterBackend * (* create_clutter_backend) (MetaBackend *backend);
-
- void (* post_init) (MetaBackend *backend);
-
- MetaMonitorManager * (* create_monitor_manager) (MetaBackend *backend,
- GError **error);
- MetaCursorRenderer * (* get_cursor_renderer) (MetaBackend *backend,
- ClutterInputDevice *device);
- MetaCursorTracker * (* create_cursor_tracker) (MetaBackend *backend);
- MetaRenderer * (* create_renderer) (MetaBackend *backend,
- GError **error);
- MetaInputSettings * (* get_input_settings) (MetaBackend *backend);
-
- ClutterSeat * (* create_default_seat) (MetaBackend *backend,
- GError **error);
-
- gboolean (* grab_device) (MetaBackend *backend,
- int device_id,
- uint32_t timestamp);
- gboolean (* ungrab_device) (MetaBackend *backend,
- int device_id,
- uint32_t timestamp);
-
- void (* finish_touch_sequence) (MetaBackend *backend,
- ClutterEventSequence *sequence,
- MetaSequenceState state);
- MetaLogicalMonitor * (* get_current_logical_monitor) (MetaBackend *backend);
-
- void (* set_keymap) (MetaBackend *backend,
- const char *layouts,
- const char *variants,
- const char *options);
-
- gboolean (* is_lid_closed) (MetaBackend *backend);
-
- struct xkb_keymap * (* get_keymap) (MetaBackend *backend);
-
- xkb_layout_index_t (* get_keymap_layout_group) (MetaBackend *backend);
-
- void (* lock_layout_group) (MetaBackend *backend,
- guint idx);
-
- void (* update_screen_size) (MetaBackend *backend, int width, int height);
- void (* select_stage_events) (MetaBackend *backend);
-
- void (* set_pointer_constraint) (MetaBackend *backend,
- MetaPointerConstraint *constraint);
-};
-
-void meta_backend_destroy (MetaBackend *backend);
-
-void meta_backend_prepare_shutdown (MetaBackend *backend);
-
-ClutterBackend * meta_backend_get_clutter_backend (MetaBackend *backend);
-
-ClutterSeat * meta_backend_get_default_seat (MetaBackend *bakcend);
-
-MetaIdleMonitor * meta_backend_get_idle_monitor (MetaBackend *backend,
- ClutterInputDevice *device);
-
-MetaIdleManager * meta_backend_get_idle_manager (MetaBackend *backend);
-
-META_EXPORT_TEST
-MetaMonitorManager * meta_backend_get_monitor_manager (MetaBackend *backend);
-MetaOrientationManager * meta_backend_get_orientation_manager (MetaBackend *backend);
-MetaCursorTracker * meta_backend_get_cursor_tracker (MetaBackend *backend);
-MetaCursorRenderer * meta_backend_get_cursor_renderer_for_device (MetaBackend *backend,
- ClutterInputDevice *device);
-MetaCursorRenderer * meta_backend_get_cursor_renderer (MetaBackend *backend);
-META_EXPORT_TEST
-MetaRenderer * meta_backend_get_renderer (MetaBackend *backend);
-MetaEgl * meta_backend_get_egl (MetaBackend *backend);
-
-#ifdef HAVE_REMOTE_DESKTOP
-MetaRemoteDesktop * meta_backend_get_remote_desktop (MetaBackend *backend);
-
-MetaScreenCast * meta_backend_get_screen_cast (MetaBackend *backend);
-#endif
-
-gboolean meta_backend_grab_device (MetaBackend *backend,
- int device_id,
- uint32_t timestamp);
-gboolean meta_backend_ungrab_device (MetaBackend *backend,
- int device_id,
- uint32_t timestamp);
-
-void meta_backend_finish_touch_sequence (MetaBackend *backend,
- ClutterEventSequence *sequence,
- MetaSequenceState state);
-
-MetaLogicalMonitor * meta_backend_get_current_logical_monitor (MetaBackend *backend);
-
-struct xkb_keymap * meta_backend_get_keymap (MetaBackend *backend);
-
-xkb_layout_index_t meta_backend_get_keymap_layout_group (MetaBackend *backend);
-
-gboolean meta_backend_is_lid_closed (MetaBackend *backend);
-
-void meta_backend_update_last_device (MetaBackend *backend,
- ClutterInputDevice *device);
-
-MetaPointerConstraint * meta_backend_get_client_pointer_constraint (MetaBackend *backend);
-void meta_backend_set_client_pointer_constraint (MetaBackend *backend,
- MetaPointerConstraint *constraint);
-
-void meta_backend_monitors_changed (MetaBackend *backend);
-
-META_EXPORT_TEST
-gboolean meta_is_stage_views_enabled (void);
-
-gboolean meta_is_stage_views_scaled (void);
-
-MetaInputMapper *meta_backend_get_input_mapper (MetaBackend *backend);
-MetaInputSettings *meta_backend_get_input_settings (MetaBackend *backend);
-
-void meta_backend_notify_keymap_changed (MetaBackend *backend);
-
-void meta_backend_notify_keymap_layout_group_changed (MetaBackend *backend,
- unsigned int locked_group);
-
-void meta_backend_notify_ui_scaling_factor_changed (MetaBackend *backend);
-
-META_EXPORT_TEST
-void meta_backend_add_gpu (MetaBackend *backend,
- MetaGpu *gpu);
-
-META_EXPORT_TEST
-GList * meta_backend_get_gpus (MetaBackend *backend);
-
-#ifdef HAVE_LIBWACOM
-WacomDeviceDatabase * meta_backend_get_wacom_database (MetaBackend *backend);
-#endif
-
-void meta_backend_add_hw_cursor_inhibitor (MetaBackend *backend,
- MetaHwCursorInhibitor *inhibitor);
-
-void meta_backend_remove_hw_cursor_inhibitor (MetaBackend *backend,
- MetaHwCursorInhibitor *inhibitor);
-
-gboolean meta_backend_is_hw_cursors_inhibited (MetaBackend *backend);
-
-#endif /* META_BACKEND_PRIVATE_H */
diff --git a/src/backends/meta-backend-types.h b/src/backends/meta-backend-types.h
deleted file mode 100644
index c5e46d87a..000000000
--- a/src/backends/meta-backend-types.h
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * Copyright (C) 2001 Havoc Pennington
- * Copyright (C) 2003 Rob Adams
- * Copyright (C) 2004-2006 Elijah Newren
- * Copyright (C) 2013-2018 Red Hat Inc.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef META_BACKEND_TYPE_H
-#define META_BACKEND_TYPE_H
-
-typedef struct _MetaBackend MetaBackend;
-
-typedef struct _MetaMonitorManager MetaMonitorManager;
-
-typedef struct _MetaMonitorConfigManager MetaMonitorConfigManager;
-typedef struct _MetaMonitorConfigStore MetaMonitorConfigStore;
-typedef struct _MetaMonitorsConfig MetaMonitorsConfig;
-
-typedef struct _MetaMonitor MetaMonitor;
-typedef struct _MetaMonitorNormal MetaMonitorNormal;
-typedef struct _MetaMonitorTiled MetaMonitorTiled;
-typedef struct _MetaMonitorSpec MetaMonitorSpec;
-typedef struct _MetaLogicalMonitor MetaLogicalMonitor;
-
-typedef enum _MetaMonitorTransform MetaMonitorTransform;
-
-typedef struct _MetaMonitorMode MetaMonitorMode;
-
-typedef struct _MetaGpu MetaGpu;
-
-typedef struct _MetaCrtc MetaCrtc;
-typedef struct _MetaOutput MetaOutput;
-typedef struct _MetaCrtcMode MetaCrtcMode;
-typedef struct _MetaCrtcAssignment MetaCrtcAssignment;
-typedef struct _MetaOutputAssignment MetaOutputAssignment;
-
-typedef struct _MetaTileInfo MetaTileInfo;
-
-typedef struct _MetaRenderer MetaRenderer;
-typedef struct _MetaRendererView MetaRendererView;
-
-typedef struct _MetaRemoteDesktop MetaRemoteDesktop;
-typedef struct _MetaScreenCast MetaScreenCast;
-typedef struct _MetaScreenCastSession MetaScreenCastSession;
-typedef struct _MetaScreenCastStream MetaScreenCastStream;
-
-typedef struct _MetaVirtualMonitor MetaVirtualMonitor;
-typedef struct _MetaVirtualMonitorInfo MetaVirtualMonitorInfo;
-
-typedef struct _MetaIdleManager MetaIdleManager;
-
-#ifdef HAVE_REMOTE_DESKTOP
-typedef struct _MetaRemoteDesktop MetaRemoteDesktop;
-#endif
-
-#endif /* META_BACKEND_TYPE_H */
diff --git a/src/backends/meta-backend.c b/src/backends/meta-backend.c
deleted file mode 100644
index d4cd5d10f..000000000
--- a/src/backends/meta-backend.c
+++ /dev/null
@@ -1,1663 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2014 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Written by:
- * Jasper St. Pierre <jstpierre@mecheye.net>
- */
-
-/**
- * SECTION:meta-backend
- * @title: MetaBackend
- * @short_description: Handles monitor config, modesetting, cursor sprites, ...
- *
- * MetaBackend is the abstraction that deals with several things like:
- * - Modesetting (depending on the backend, this can be done either by X or KMS)
- * - Initializing the #MetaSettings
- * - Setting up Monitor configuration
- * - Input device configuration (using the #ClutterDeviceManager)
- * - Creating the #MetaRenderer
- * - Setting up the stage of the scene graph (using #MetaStage)
- * - Creating the object that deals with the cursor (using #MetaCursorTracker)
- * and its possible pointer constraint (using #MetaPointerConstraint)
- * - Setting the cursor sprite (using #MetaCursorRenderer)
- * - Interacting with logind (using the appropriate D-Bus interface)
- * - Querying UPower (over D-Bus) to know when the lid is closed
- * - Setup Remote Desktop / Screencasting (#MetaRemoteDesktop)
- * - Setup the #MetaEgl object
- *
- * Note that the #MetaBackend is not a subclass of #ClutterBackend. It is
- * responsible for creating the correct one, based on the backend that is
- * used (#MetaBackendNative or #MetaBackendX11).
- */
-
-#include "config.h"
-
-#include "backends/meta-backend-private.h"
-
-#include <stdlib.h>
-
-#include "backends/meta-cursor-renderer.h"
-#include "backends/meta-cursor-tracker-private.h"
-#include "backends/meta-idle-manager.h"
-#include "backends/meta-idle-monitor-private.h"
-#include "backends/meta-input-mapper-private.h"
-#include "backends/meta-input-settings-private.h"
-#include "backends/meta-logical-monitor.h"
-#include "backends/meta-monitor-manager-dummy.h"
-#include "backends/meta-settings-private.h"
-#include "backends/meta-stage-private.h"
-#include "backends/x11/meta-backend-x11.h"
-#include "clutter/clutter-mutter.h"
-#include "clutter/clutter-seat-private.h"
-#include "core/meta-context-private.h"
-#include "meta/main.h"
-#include "meta/meta-backend.h"
-#include "meta/meta-context.h"
-#include "meta/util.h"
-
-#ifdef HAVE_PROFILER
-#include "backends/meta-profiler.h"
-#endif
-
-#ifdef HAVE_REMOTE_DESKTOP
-#include "backends/meta-dbus-session-watcher.h"
-#include "backends/meta-remote-access-controller-private.h"
-#include "backends/meta-remote-desktop.h"
-#include "backends/meta-screen-cast.h"
-#endif
-
-#ifdef HAVE_NATIVE_BACKEND
-#include "backends/native/meta-backend-native.h"
-#endif
-
-#ifdef HAVE_WAYLAND
-#include "wayland/meta-wayland.h"
-#endif
-
-enum
-{
- PROP_0,
-
- PROP_CONTEXT,
-
- N_PROPS
-};
-
-static GParamSpec *obj_props[N_PROPS];
-
-enum
-{
- KEYMAP_CHANGED,
- KEYMAP_LAYOUT_GROUP_CHANGED,
- LAST_DEVICE_CHANGED,
- LID_IS_CLOSED_CHANGED,
- GPU_ADDED,
- PREPARE_SHUTDOWN,
-
- N_SIGNALS
-};
-
-static guint signals[N_SIGNALS];
-
-static MetaBackend *_backend;
-
-static gboolean stage_views_disabled = FALSE;
-
-/**
- * meta_get_backend:
- *
- * Accessor for the singleton MetaBackend.
- *
- * Returns: (transfer none): The only #MetaBackend there is.
- */
-MetaBackend *
-meta_get_backend (void)
-{
- return _backend;
-}
-
-struct _MetaBackendPrivate
-{
- MetaContext *context;
-
- MetaMonitorManager *monitor_manager;
- MetaOrientationManager *orientation_manager;
- MetaCursorTracker *cursor_tracker;
- MetaInputMapper *input_mapper;
- MetaIdleManager *idle_manager;
- MetaRenderer *renderer;
-#ifdef HAVE_EGL
- MetaEgl *egl;
-#endif
- MetaSettings *settings;
-#ifdef HAVE_REMOTE_DESKTOP
- MetaRemoteAccessController *remote_access_controller;
- MetaDbusSessionWatcher *dbus_session_watcher;
- MetaScreenCast *screen_cast;
- MetaRemoteDesktop *remote_desktop;
-#endif
-
-#ifdef HAVE_PROFILER
- MetaProfiler *profiler;
-#endif
-
-#ifdef HAVE_LIBWACOM
- WacomDeviceDatabase *wacom_db;
-#endif
-
- ClutterBackend *clutter_backend;
- ClutterSeat *default_seat;
- ClutterActor *stage;
-
- GList *gpus;
- GList *hw_cursor_inhibitors;
-
- gboolean is_pointer_position_initialized;
-
- guint device_update_idle_id;
-
- ClutterInputDevice *current_device;
-
- MetaPointerConstraint *client_pointer_constraint;
- MetaDnd *dnd;
-
- guint upower_watch_id;
- GDBusProxy *upower_proxy;
- gboolean lid_is_closed;
-
- guint sleep_signal_id;
- GCancellable *cancellable;
- GDBusConnection *system_bus;
-};
-typedef struct _MetaBackendPrivate MetaBackendPrivate;
-
-typedef struct _MetaBackendSource MetaBackendSource;
-
-struct _MetaBackendSource
-{
- GSource parent;
- MetaBackend *backend;
-};
-
-static void
-initable_iface_init (GInitableIface *initable_iface);
-
-G_DEFINE_ABSTRACT_TYPE_WITH_CODE (MetaBackend, meta_backend, G_TYPE_OBJECT,
- G_ADD_PRIVATE (MetaBackend)
- G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE,
- initable_iface_init));
-
-static void
-meta_backend_dispose (GObject *object)
-{
- MetaBackend *backend = META_BACKEND (object);
- MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
-
- _backend = NULL;
-
- g_clear_pointer (&priv->cursor_tracker, meta_cursor_tracker_destroy);
- g_clear_object (&priv->current_device);
- g_clear_object (&priv->monitor_manager);
- g_clear_object (&priv->orientation_manager);
-#ifdef HAVE_REMOTE_DESKTOP
- g_clear_object (&priv->remote_desktop);
- g_clear_object (&priv->screen_cast);
- g_clear_object (&priv->dbus_session_watcher);
- g_clear_object (&priv->remote_access_controller);
-#endif
-
-#ifdef HAVE_LIBWACOM
- g_clear_pointer (&priv->wacom_db, libwacom_database_destroy);
-#endif
-
- if (priv->sleep_signal_id)
- {
- g_dbus_connection_signal_unsubscribe (priv->system_bus, priv->sleep_signal_id);
- priv->sleep_signal_id = 0;
- }
-
- if (priv->upower_watch_id)
- {
- g_bus_unwatch_name (priv->upower_watch_id);
- priv->upower_watch_id = 0;
- }
-
- g_cancellable_cancel (priv->cancellable);
- g_clear_object (&priv->cancellable);
- g_clear_object (&priv->system_bus);
- g_clear_object (&priv->upower_proxy);
-
- g_clear_handle_id (&priv->device_update_idle_id, g_source_remove);
-
- g_clear_object (&priv->settings);
-
-#ifdef HAVE_PROFILER
- g_clear_object (&priv->profiler);
-#endif
-
- g_clear_pointer (&priv->default_seat, clutter_seat_destroy);
- g_clear_pointer (&priv->stage, clutter_actor_destroy);
- g_clear_pointer (&priv->clutter_backend, clutter_backend_destroy);
- g_clear_pointer (&priv->idle_manager, meta_idle_manager_free);
- g_clear_object (&priv->renderer);
- g_clear_list (&priv->gpus, g_object_unref);
-
- G_OBJECT_CLASS (meta_backend_parent_class)->dispose (object);
-}
-
-void
-meta_backend_destroy (MetaBackend *backend)
-{
- g_object_run_dispose (G_OBJECT (backend));
- g_object_unref (backend);
-}
-
-static void
-meta_backend_sync_screen_size (MetaBackend *backend)
-{
- MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
- int width, height;
-
- meta_monitor_manager_get_screen_size (priv->monitor_manager, &width, &height);
-
- META_BACKEND_GET_CLASS (backend)->update_screen_size (backend, width, height);
-}
-
-static void
-reset_pointer_position (MetaBackend *backend)
-{
- MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
- MetaMonitorManager *monitor_manager = priv->monitor_manager;
- ClutterSeat *seat = clutter_backend_get_default_seat (priv->clutter_backend);
- MetaLogicalMonitor *primary;
-
- primary =
- meta_monitor_manager_get_primary_logical_monitor (monitor_manager);
-
- /* Move the pointer out of the way to avoid hovering over reactive
- * elements (e.g. users list at login) causing undesired behaviour. */
- clutter_seat_warp_pointer (seat,
- primary->rect.x + primary->rect.width * 0.9,
- primary->rect.y + primary->rect.height * 0.9);
-}
-
-static gboolean
-should_have_cursor_renderer (ClutterInputDevice *device)
-{
- switch (clutter_input_device_get_device_type (device))
- {
- case CLUTTER_POINTER_DEVICE:
- if (clutter_input_device_get_device_mode (device) ==
- CLUTTER_INPUT_MODE_LOGICAL)
- return TRUE;
-
- return FALSE;
- case CLUTTER_TABLET_DEVICE:
- return TRUE;
- default:
- return FALSE;
- }
-}
-
-static void
-update_cursors (MetaBackend *backend)
-{
- MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
- ClutterSeat *seat = clutter_backend_get_default_seat (priv->clutter_backend);
- MetaCursorRenderer *cursor_renderer;
- ClutterInputDevice *pointer, *device;
- GList *devices, *l;
-
- pointer = clutter_seat_get_pointer (seat);
- devices = clutter_seat_list_devices (seat);
- devices = g_list_prepend (devices, pointer);
-
- for (l = devices; l; l = l->next)
- {
- device = l->data;
-
- if (!should_have_cursor_renderer (device))
- continue;
-
- cursor_renderer = meta_backend_get_cursor_renderer_for_device (backend,
- device);
- if (cursor_renderer)
- meta_cursor_renderer_force_update (cursor_renderer);
- }
-
- g_list_free (devices);
-}
-
-void
-meta_backend_monitors_changed (MetaBackend *backend)
-{
- MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
- MetaMonitorManager *monitor_manager =
- meta_backend_get_monitor_manager (backend);
- ClutterSeat *seat = clutter_backend_get_default_seat (priv->clutter_backend);
- ClutterInputDevice *device = clutter_seat_get_pointer (seat);
- graphene_point_t point;
-
- meta_backend_sync_screen_size (backend);
-
- if (clutter_seat_query_state (seat, device, NULL, &point, NULL))
- {
- /* If we're outside all monitors, warp the pointer back inside */
- if ((!meta_monitor_manager_get_logical_monitor_at (monitor_manager,
- point.x, point.y) ||
- !priv->is_pointer_position_initialized) &&
- !meta_monitor_manager_is_headless (monitor_manager))
- {
- reset_pointer_position (backend);
- priv->is_pointer_position_initialized = TRUE;
- }
- }
-
- update_cursors (backend);
-}
-
-static inline gboolean
-check_has_pointing_device (ClutterSeat *seat)
-{
- GList *l, *devices;
- gboolean found = FALSE;
-
- devices = clutter_seat_list_devices (seat);
-
- for (l = devices; l; l = l->next)
- {
- ClutterInputDevice *device = l->data;
-
- if (clutter_input_device_get_device_mode (device) == CLUTTER_INPUT_MODE_LOGICAL)
- continue;
- if (clutter_input_device_get_device_type (device) == CLUTTER_TOUCHSCREEN_DEVICE ||
- clutter_input_device_get_device_type (device) == CLUTTER_KEYBOARD_DEVICE)
- continue;
-
- found = TRUE;
- break;
- }
-
- g_list_free (devices);
-
- return found;
-}
-
-static void
-on_device_added (ClutterSeat *seat,
- ClutterInputDevice *device,
- gpointer user_data)
-{
- MetaBackend *backend = META_BACKEND (user_data);
- MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
- ClutterInputDeviceType device_type;
-
- if (clutter_input_device_get_device_mode (device) ==
- CLUTTER_INPUT_MODE_LOGICAL)
- return;
-
- device_type = clutter_input_device_get_device_type (device);
-
- if (device_type == CLUTTER_TOUCHSCREEN_DEVICE)
- meta_cursor_tracker_set_pointer_visible (priv->cursor_tracker, FALSE);
- else if (device_type == CLUTTER_POINTER_DEVICE &&
- !clutter_seat_has_touchscreen (seat))
- meta_cursor_tracker_set_pointer_visible (priv->cursor_tracker, TRUE);
-
- if (device_type == CLUTTER_TOUCHSCREEN_DEVICE ||
- device_type == CLUTTER_TABLET_DEVICE ||
- device_type == CLUTTER_PEN_DEVICE ||
- device_type == CLUTTER_ERASER_DEVICE ||
- device_type == CLUTTER_CURSOR_DEVICE ||
- device_type == CLUTTER_PAD_DEVICE)
- meta_input_mapper_add_device (priv->input_mapper, device);
-}
-
-static void
-on_device_removed (ClutterSeat *seat,
- ClutterInputDevice *device,
- gpointer user_data)
-{
- MetaBackend *backend = META_BACKEND (user_data);
- MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
-
- if (clutter_input_device_get_device_mode (device) ==
- CLUTTER_INPUT_MODE_LOGICAL)
- return;
-
- meta_input_mapper_remove_device (priv->input_mapper, device);
-
- /* If the device the user last interacted goes away, check again pointer
- * visibility.
- */
- if (priv->current_device == device)
- {
- MetaCursorTracker *cursor_tracker = priv->cursor_tracker;
- gboolean has_touchscreen, has_pointing_device;
- ClutterInputDeviceType device_type;
-
- g_clear_object (&priv->current_device);
- g_clear_handle_id (&priv->device_update_idle_id, g_source_remove);
-
- device_type = clutter_input_device_get_device_type (device);
- has_touchscreen = clutter_seat_has_touchscreen (seat);
-
- if (device_type == CLUTTER_TOUCHSCREEN_DEVICE && has_touchscreen)
- {
- /* There's more touchscreens left, keep the pointer hidden */
- meta_cursor_tracker_set_pointer_visible (cursor_tracker, FALSE);
- }
- else if (device_type != CLUTTER_KEYBOARD_DEVICE)
- {
- has_pointing_device = check_has_pointing_device (seat);
- meta_cursor_tracker_set_pointer_visible (cursor_tracker,
- has_pointing_device &&
- !has_touchscreen);
- }
- }
-
- if (priv->current_device == device)
- meta_backend_update_last_device (backend, NULL);
-}
-
-static void
-input_mapper_device_mapped_cb (MetaInputMapper *mapper,
- ClutterInputDevice *device,
- float matrix[6],
- MetaInputSettings *input_settings)
-{
- meta_input_settings_set_device_matrix (input_settings, device, matrix);
-}
-
-static void
-input_mapper_device_enabled_cb (MetaInputMapper *mapper,
- ClutterInputDevice *device,
- gboolean enabled,
- MetaInputSettings *input_settings)
-{
- meta_input_settings_set_device_enabled (input_settings, device, enabled);
-}
-
-static void
-input_mapper_device_aspect_ratio_cb (MetaInputMapper *mapper,
- ClutterInputDevice *device,
- double aspect_ratio,
- MetaInputSettings *input_settings)
-{
- meta_input_settings_set_device_aspect_ratio (input_settings, device, aspect_ratio);
-}
-
-static void
-on_stage_shown_cb (MetaBackend *backend)
-{
- MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
- ClutterSeat *seat = clutter_backend_get_default_seat (priv->clutter_backend);
- g_autoptr (GList) devices = NULL;
- const GList *l;
-
- devices = clutter_seat_list_devices (seat);
- for (l = devices; l; l = l->next)
- {
- ClutterInputDevice *device = l->data;
-
- if (clutter_input_device_get_device_mode (device) ==
- CLUTTER_INPUT_MODE_LOGICAL)
- continue;
-
- if (clutter_input_device_get_device_type (device) !=
- CLUTTER_POINTER_DEVICE)
- continue;
-
- meta_cursor_tracker_set_pointer_visible (priv->cursor_tracker, TRUE);
- break;
- }
-}
-
-static void
-meta_backend_real_post_init (MetaBackend *backend)
-{
- MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
- ClutterSeat *seat = clutter_backend_get_default_seat (priv->clutter_backend);
- MetaInputSettings *input_settings;
-
- priv->stage = meta_stage_new (backend);
- clutter_actor_realize (priv->stage);
- META_BACKEND_GET_CLASS (backend)->select_stage_events (backend);
- g_signal_connect_object (priv->stage, "show",
- G_CALLBACK (on_stage_shown_cb), backend,
- G_CONNECT_SWAPPED);
-
- meta_monitor_manager_setup (priv->monitor_manager);
-
- meta_backend_sync_screen_size (backend);
-
- priv->idle_manager = meta_idle_manager_new (backend);
-
- g_signal_connect_object (seat, "device-added",
- G_CALLBACK (on_device_added), backend, 0);
- g_signal_connect_object (seat, "device-removed",
- G_CALLBACK (on_device_removed), backend,
- G_CONNECT_AFTER);
-
- priv->input_mapper = meta_input_mapper_new ();
-
- input_settings = meta_backend_get_input_settings (backend);
-
- if (input_settings)
- {
- g_signal_connect (priv->input_mapper, "device-mapped",
- G_CALLBACK (input_mapper_device_mapped_cb),
- input_settings);
- g_signal_connect (priv->input_mapper, "device-enabled",
- G_CALLBACK (input_mapper_device_enabled_cb),
- input_settings);
- g_signal_connect (priv->input_mapper, "device-aspect-ratio",
- G_CALLBACK (input_mapper_device_aspect_ratio_cb),
- input_settings);
- }
-
-#ifdef HAVE_REMOTE_DESKTOP
- priv->dbus_session_watcher = g_object_new (META_TYPE_DBUS_SESSION_WATCHER, NULL);
- priv->screen_cast = meta_screen_cast_new (backend,
- priv->dbus_session_watcher);
- priv->remote_desktop = meta_remote_desktop_new (backend,
- priv->dbus_session_watcher);
- priv->remote_access_controller =
- meta_remote_access_controller_new (priv->remote_desktop, priv->screen_cast);
-#endif /* HAVE_REMOTE_DESKTOP */
-
- if (!meta_monitor_manager_is_headless (priv->monitor_manager))
- {
- reset_pointer_position (backend);
- priv->is_pointer_position_initialized = TRUE;
- }
-
- meta_monitor_manager_post_init (priv->monitor_manager);
-}
-
-static gboolean
-meta_backend_real_grab_device (MetaBackend *backend,
- int device_id,
- uint32_t timestamp)
-{
- /* Do nothing */
- return TRUE;
-}
-
-static gboolean
-meta_backend_real_ungrab_device (MetaBackend *backend,
- int device_id,
- uint32_t timestamp)
-{
- /* Do nothing */
- return TRUE;
-}
-
-static void
-meta_backend_real_select_stage_events (MetaBackend *backend)
-{
- /* Do nothing */
-}
-
-static gboolean
-meta_backend_real_is_lid_closed (MetaBackend *backend)
-{
- MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
-
- return priv->lid_is_closed;
-}
-
-static MetaCursorTracker *
-meta_backend_real_create_cursor_tracker (MetaBackend *backend)
-{
- return g_object_new (META_TYPE_CURSOR_TRACKER,
- "backend", backend,
- NULL);
-}
-
-gboolean
-meta_backend_is_lid_closed (MetaBackend *backend)
-{
- return META_BACKEND_GET_CLASS (backend)->is_lid_closed (backend);
-}
-
-static void
-upower_properties_changed (GDBusProxy *proxy,
- GVariant *changed_properties,
- GStrv invalidated_properties,
- gpointer user_data)
-{
- MetaBackend *backend = user_data;
- MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
- GVariant *v;
- gboolean lid_is_closed;
-
- v = g_variant_lookup_value (changed_properties,
- "LidIsClosed",
- G_VARIANT_TYPE_BOOLEAN);
- if (!v)
- return;
-
- lid_is_closed = g_variant_get_boolean (v);
- g_variant_unref (v);
-
- if (lid_is_closed == priv->lid_is_closed)
- return;
-
- priv->lid_is_closed = lid_is_closed;
- g_signal_emit (backend, signals[LID_IS_CLOSED_CHANGED], 0,
- priv->lid_is_closed);
-
- if (lid_is_closed)
- return;
-
- meta_idle_manager_reset_idle_time (priv->idle_manager);
-}
-
-static void
-upower_ready_cb (GObject *source_object,
- GAsyncResult *res,
- gpointer user_data)
-{
- MetaBackend *backend;
- MetaBackendPrivate *priv;
- GDBusProxy *proxy;
- GError *error = NULL;
- GVariant *v;
-
- proxy = g_dbus_proxy_new_finish (res, &error);
- if (!proxy)
- {
- if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
- g_warning ("Failed to create UPower proxy: %s", error->message);
- g_error_free (error);
- return;
- }
-
- backend = META_BACKEND (user_data);
- priv = meta_backend_get_instance_private (backend);
-
- priv->upower_proxy = proxy;
- g_signal_connect (proxy, "g-properties-changed",
- G_CALLBACK (upower_properties_changed), backend);
-
- v = g_dbus_proxy_get_cached_property (proxy, "LidIsClosed");
- if (!v)
- return;
- priv->lid_is_closed = g_variant_get_boolean (v);
- g_variant_unref (v);
-
- if (priv->lid_is_closed)
- {
- g_signal_emit (backend, signals[LID_IS_CLOSED_CHANGED], 0,
- priv->lid_is_closed);
- }
-}
-
-static void
-upower_appeared (GDBusConnection *connection,
- const gchar *name,
- const gchar *name_owner,
- gpointer user_data)
-{
- MetaBackend *backend = META_BACKEND (user_data);
- MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
-
- g_dbus_proxy_new (connection,
- G_DBUS_PROXY_FLAGS_NONE,
- NULL,
- "org.freedesktop.UPower",
- "/org/freedesktop/UPower",
- "org.freedesktop.UPower",
- priv->cancellable,
- upower_ready_cb,
- backend);
-}
-
-static void
-upower_vanished (GDBusConnection *connection,
- const gchar *name,
- gpointer user_data)
-{
- MetaBackend *backend = META_BACKEND (user_data);
- MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
-
- g_clear_object (&priv->upower_proxy);
-}
-
-static void
-meta_backend_constructed (GObject *object)
-{
- MetaBackend *backend = META_BACKEND (object);
- MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
- MetaBackendClass *backend_class =
- META_BACKEND_GET_CLASS (backend);
-
- g_assert (priv->context);
-
-#ifdef HAVE_LIBWACOM
- priv->wacom_db = libwacom_database_new ();
- if (!priv->wacom_db)
- {
- g_warning ("Could not create database of Wacom devices, "
- "expect tablets to misbehave");
- }
-#endif
-
- if (backend_class->is_lid_closed != meta_backend_real_is_lid_closed)
- return;
-
- priv->upower_watch_id = g_bus_watch_name (G_BUS_TYPE_SYSTEM,
- "org.freedesktop.UPower",
- G_BUS_NAME_WATCHER_FLAGS_NONE,
- upower_appeared,
- upower_vanished,
- backend,
- NULL);
-}
-
-static void
-meta_backend_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- MetaBackend *backend = META_BACKEND (object);
- MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
-
- switch (prop_id)
- {
- case PROP_CONTEXT:
- priv->context = g_value_get_object (value);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-
-static void
-meta_backend_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- MetaBackend *backend = META_BACKEND (object);
- MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
-
- switch (prop_id)
- {
- case PROP_CONTEXT:
- g_value_set_object (value, priv->context);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-
-static void
-meta_backend_class_init (MetaBackendClass *klass)
-{
- const gchar *mutter_stage_views;
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- object_class->dispose = meta_backend_dispose;
- object_class->constructed = meta_backend_constructed;
- object_class->set_property = meta_backend_set_property;
- object_class->get_property = meta_backend_get_property;
-
- klass->post_init = meta_backend_real_post_init;
- klass->grab_device = meta_backend_real_grab_device;
- klass->ungrab_device = meta_backend_real_ungrab_device;
- klass->select_stage_events = meta_backend_real_select_stage_events;
- klass->is_lid_closed = meta_backend_real_is_lid_closed;
- klass->create_cursor_tracker = meta_backend_real_create_cursor_tracker;
-
- obj_props[PROP_CONTEXT] =
- g_param_spec_object ("context",
- "context",
- "MetaContext",
- META_TYPE_CONTEXT,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT_ONLY |
- G_PARAM_STATIC_STRINGS);
- g_object_class_install_properties (object_class, N_PROPS, obj_props);
-
- signals[KEYMAP_CHANGED] =
- g_signal_new ("keymap-changed",
- G_TYPE_FROM_CLASS (object_class),
- G_SIGNAL_RUN_LAST,
- 0,
- NULL, NULL, NULL,
- G_TYPE_NONE, 0);
- signals[KEYMAP_LAYOUT_GROUP_CHANGED] =
- g_signal_new ("keymap-layout-group-changed",
- G_TYPE_FROM_CLASS (object_class),
- G_SIGNAL_RUN_LAST,
- 0,
- NULL, NULL, NULL,
- G_TYPE_NONE, 1, G_TYPE_UINT);
- signals[LAST_DEVICE_CHANGED] =
- g_signal_new ("last-device-changed",
- G_TYPE_FROM_CLASS (object_class),
- G_SIGNAL_RUN_LAST,
- 0,
- NULL, NULL, NULL,
- G_TYPE_NONE, 1, CLUTTER_TYPE_INPUT_DEVICE);
- signals[LID_IS_CLOSED_CHANGED] =
- g_signal_new ("lid-is-closed-changed",
- G_TYPE_FROM_CLASS (object_class),
- G_SIGNAL_RUN_LAST,
- 0,
- NULL, NULL, NULL,
- G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
- /**
- * MetaBackend::gpu-added: (skip)
- * @backend: the #MetaBackend
- * @gpu: the #MetaGpu
- */
- signals[GPU_ADDED] =
- g_signal_new ("gpu-added",
- G_TYPE_FROM_CLASS (klass),
- G_SIGNAL_RUN_LAST,
- 0,
- NULL, NULL, NULL,
- G_TYPE_NONE, 1, META_TYPE_GPU);
- signals[PREPARE_SHUTDOWN] =
- g_signal_new ("prepare-shutdown",
- G_TYPE_FROM_CLASS (klass),
- G_SIGNAL_RUN_LAST,
- 0,
- NULL, NULL, NULL,
- G_TYPE_NONE, 0);
-
- mutter_stage_views = g_getenv ("MUTTER_STAGE_VIEWS");
- stage_views_disabled = g_strcmp0 (mutter_stage_views, "0") == 0;
-}
-
-static MetaMonitorManager *
-meta_backend_create_monitor_manager (MetaBackend *backend,
- GError **error)
-{
- return META_BACKEND_GET_CLASS (backend)->create_monitor_manager (backend,
- error);
-}
-
-static MetaRenderer *
-meta_backend_create_renderer (MetaBackend *backend,
- GError **error)
-{
- return META_BACKEND_GET_CLASS (backend)->create_renderer (backend, error);
-}
-
-static void
-prepare_for_sleep_cb (GDBusConnection *connection,
- const gchar *sender_name,
- const gchar *object_path,
- const gchar *interface_name,
- const gchar *signal_name,
- GVariant *parameters,
- gpointer user_data)
-{
- MetaBackend *backend = user_data;
- MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
- gboolean suspending;
-
- g_variant_get (parameters, "(b)", &suspending);
- if (suspending)
- return;
-
- meta_idle_manager_reset_idle_time (priv->idle_manager);
-}
-
-static void
-system_bus_gotten_cb (GObject *object,
- GAsyncResult *res,
- gpointer user_data)
-{
- MetaBackend *backend = user_data;
- MetaBackendPrivate *priv;
- GDBusConnection *bus;
-
- bus = g_bus_get_finish (res, NULL);
- if (!bus)
- return;
-
- priv = meta_backend_get_instance_private (backend);
- priv->system_bus = bus;
- priv->sleep_signal_id =
- g_dbus_connection_signal_subscribe (priv->system_bus,
- "org.freedesktop.login1",
- "org.freedesktop.login1.Manager",
- "PrepareForSleep",
- "/org/freedesktop/login1",
- NULL,
- G_DBUS_SIGNAL_FLAGS_NONE,
- prepare_for_sleep_cb,
- backend,
- NULL);
-}
-
-/* Mutter is responsible for pulling events off the X queue, so Clutter
- * doesn't need (and shouldn't) run its normal event source which polls
- * the X fd, but we do have to deal with dispatching events that accumulate
- * in the clutter queue. This happens, for example, when clutter generate
- * enter/leave events on mouse motion - several events are queued in the
- * clutter queue but only one dispatched. It could also happen because of
- * explicit calls to clutter_event_put(). We add a very simple custom
- * event loop source which is simply responsible for pulling events off
- * of the queue and dispatching them before we block for new events.
- */
-
-static gboolean
-clutter_source_prepare (GSource *source,
- int *timeout)
-{
- *timeout = -1;
-
- return clutter_events_pending ();
-}
-
-static gboolean
-clutter_source_check (GSource *source)
-{
- return clutter_events_pending ();
-}
-
-static gboolean
-clutter_source_dispatch (GSource *source,
- GSourceFunc callback,
- gpointer user_data)
-{
- MetaBackendSource *backend_source = (MetaBackendSource *) source;
- ClutterEvent *event = clutter_event_get ();
-
- if (event)
- {
- event->any.stage =
- CLUTTER_STAGE (meta_backend_get_stage (backend_source->backend));
- clutter_do_event (event);
- clutter_event_free (event);
- }
-
- return TRUE;
-}
-
-static GSourceFuncs clutter_source_funcs = {
- clutter_source_prepare,
- clutter_source_check,
- clutter_source_dispatch
-};
-
-static ClutterBackend *
-meta_get_clutter_backend (void)
-{
- MetaBackend *backend = meta_get_backend ();
-
- return meta_backend_get_clutter_backend (backend);
-}
-
-static ClutterSeat *
-meta_backend_create_default_seat (MetaBackend *backend,
- GError **error)
-{
- return META_BACKEND_GET_CLASS (backend)->create_default_seat (backend, error);
-}
-
-static gboolean
-init_clutter (MetaBackend *backend,
- GError **error)
-{
- MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
- MetaBackendSource *backend_source;
- GSource *source;
-
- clutter_set_custom_backend_func (meta_get_clutter_backend);
-
- if (clutter_init (NULL, NULL) != CLUTTER_INIT_SUCCESS)
- {
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- "Unable to initialize Clutter");
- return FALSE;
- }
-
- priv->default_seat = meta_backend_create_default_seat (backend, error);
- if (!priv->default_seat)
- return FALSE;
-
- source = g_source_new (&clutter_source_funcs, sizeof (MetaBackendSource));
- backend_source = (MetaBackendSource *) source;
- backend_source->backend = backend;
- g_source_attach (source, NULL);
- g_source_unref (source);
-
- return TRUE;
-}
-
-static void
-meta_backend_post_init (MetaBackend *backend)
-{
- MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
-
- META_BACKEND_GET_CLASS (backend)->post_init (backend);
-
- meta_settings_post_init (priv->settings);
-}
-
-static gboolean
-meta_backend_initable_init (GInitable *initable,
- GCancellable *cancellable,
- GError **error)
-{
- MetaBackend *backend = META_BACKEND (initable);
- MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
-
- priv->settings = meta_settings_new (backend);
-
-#ifdef HAVE_EGL
- priv->egl = g_object_new (META_TYPE_EGL, NULL);
-#endif
-
- priv->orientation_manager = g_object_new (META_TYPE_ORIENTATION_MANAGER, NULL);
-
- priv->monitor_manager = meta_backend_create_monitor_manager (backend, error);
- if (!priv->monitor_manager)
- return FALSE;
-
- priv->renderer = meta_backend_create_renderer (backend, error);
- if (!priv->renderer)
- return FALSE;
-
- priv->cursor_tracker =
- META_BACKEND_GET_CLASS (backend)->create_cursor_tracker (backend);
-
- priv->dnd = g_object_new (META_TYPE_DND, NULL);
-
- priv->cancellable = g_cancellable_new ();
- g_bus_get (G_BUS_TYPE_SYSTEM,
- priv->cancellable,
- system_bus_gotten_cb,
- backend);
-
-#ifdef HAVE_PROFILER
- priv->profiler = meta_profiler_new ();
-#endif
-
- if (!init_clutter (backend, error))
- return FALSE;
-
- meta_backend_post_init (backend);
-
- return TRUE;
-}
-
-static void
-initable_iface_init (GInitableIface *initable_iface)
-{
- initable_iface->init = meta_backend_initable_init;
-}
-
-static void
-meta_backend_init (MetaBackend *backend)
-{
- _backend = backend;
-}
-
-/**
- * meta_backend_get_idle_monitor: (skip)
- */
-MetaIdleMonitor *
-meta_backend_get_idle_monitor (MetaBackend *backend,
- ClutterInputDevice *device)
-{
- MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
-
- return meta_idle_manager_get_monitor (priv->idle_manager, device);
-}
-
-/**
- * meta_backend_get_core_idle_monitor:
- *
- * Returns: (transfer none): the #MetaIdleMonitor that tracks server-global
- * idle time for all devices.
- */
-MetaIdleMonitor *
-meta_backend_get_core_idle_monitor (MetaBackend *backend)
-{
- MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
-
- return meta_idle_manager_get_core_monitor (priv->idle_manager);
-}
-
-/**
- * meta_backend_get_idle_manager: (skip)
- */
-MetaIdleManager *
-meta_backend_get_idle_manager (MetaBackend *backend)
-{
- MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
-
- return priv->idle_manager;
-}
-
-/**
- * meta_backend_get_monitor_manager: (skip)
- */
-MetaMonitorManager *
-meta_backend_get_monitor_manager (MetaBackend *backend)
-{
- MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
-
- return priv->monitor_manager;
-}
-
-/**
- * meta_backend_get_orientation_manager: (skip)
- */
-MetaOrientationManager *
-meta_backend_get_orientation_manager (MetaBackend *backend)
-{
- MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
-
- return priv->orientation_manager;
-}
-
-MetaCursorTracker *
-meta_backend_get_cursor_tracker (MetaBackend *backend)
-{
- MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
-
- return priv->cursor_tracker;
-}
-
-/**
- * meta_backend_get_cursor_renderer: (skip)
- */
-MetaCursorRenderer *
-meta_backend_get_cursor_renderer (MetaBackend *backend)
-{
- MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
- ClutterInputDevice *pointer;
- ClutterSeat *seat;
-
- seat = clutter_backend_get_default_seat (priv->clutter_backend);
- pointer = clutter_seat_get_pointer (seat);
-
- return meta_backend_get_cursor_renderer_for_device (backend, pointer);
-}
-
-MetaCursorRenderer *
-meta_backend_get_cursor_renderer_for_device (MetaBackend *backend,
- ClutterInputDevice *device)
-{
- g_return_val_if_fail (META_IS_BACKEND (backend), NULL);
- g_return_val_if_fail (CLUTTER_IS_INPUT_DEVICE (device), NULL);
- g_return_val_if_fail (clutter_input_device_get_device_type (device) !=
- CLUTTER_KEYBOARD_DEVICE, NULL);
-
- return META_BACKEND_GET_CLASS (backend)->get_cursor_renderer (backend,
- device);
-}
-
-/**
- * meta_backend_get_renderer: (skip)
- */
-MetaRenderer *
-meta_backend_get_renderer (MetaBackend *backend)
-{
- MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
-
- return priv->renderer;
-}
-
-#ifdef HAVE_EGL
-/**
- * meta_backend_get_egl: (skip)
- */
-MetaEgl *
-meta_backend_get_egl (MetaBackend *backend)
-{
- MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
-
- return priv->egl;
-}
-#endif /* HAVE_EGL */
-
-/**
- * meta_backend_get_settings: (skip)
- */
-MetaSettings *
-meta_backend_get_settings (MetaBackend *backend)
-{
- MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
-
- return priv->settings;
-}
-
-#ifdef HAVE_REMOTE_DESKTOP
-/**
- * meta_backend_get_remote_desktop: (skip)
- */
-MetaRemoteDesktop *
-meta_backend_get_remote_desktop (MetaBackend *backend)
-{
- MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
-
- return priv->remote_desktop;
-}
-
-/**
- * meta_backend_get_screen_cast: (skip)
- */
-MetaScreenCast *
-meta_backend_get_screen_cast (MetaBackend *backend)
-{
- MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
-
- return priv->screen_cast;
-}
-#endif /* HAVE_REMOTE_DESKTOP */
-
-/**
- * meta_backend_get_remote_access_controller:
- * @backend: A #MetaBackend
- *
- * Return Value: (transfer none): The #MetaRemoteAccessController
- */
-MetaRemoteAccessController *
-meta_backend_get_remote_access_controller (MetaBackend *backend)
-{
-#ifdef HAVE_REMOTE_DESKTOP
- MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
-
- return priv->remote_access_controller;
-#else
- return NULL;
-#endif
-}
-
-/**
- * meta_backend_is_rendering_hardware_accelerated:
- * @backend: A #MetaBackend
- *
- * Returns: %TRUE if the rendering is hardware accelerated, otherwise
- * %FALSE.
- */
-gboolean
-meta_backend_is_rendering_hardware_accelerated (MetaBackend *backend)
-{
- MetaRenderer *renderer = meta_backend_get_renderer (backend);
-
- return meta_renderer_is_hardware_accelerated (renderer);
-}
-
-/**
- * meta_backend_grab_device: (skip)
- */
-gboolean
-meta_backend_grab_device (MetaBackend *backend,
- int device_id,
- uint32_t timestamp)
-{
- return META_BACKEND_GET_CLASS (backend)->grab_device (backend, device_id, timestamp);
-}
-
-/**
- * meta_backend_get_context:
- * @backend: the #MetaBackend
- *
- * Returns: (transfer none): The #MetaContext
- */
-MetaContext *
-meta_backend_get_context (MetaBackend *backend)
-{
- MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
-
- return priv->context;
-}
-
-/**
- * meta_backend_ungrab_device: (skip)
- */
-gboolean
-meta_backend_ungrab_device (MetaBackend *backend,
- int device_id,
- uint32_t timestamp)
-{
- return META_BACKEND_GET_CLASS (backend)->ungrab_device (backend, device_id, timestamp);
-}
-
-/**
- * meta_backend_finish_touch_sequence: (skip)
- */
-void
-meta_backend_finish_touch_sequence (MetaBackend *backend,
- ClutterEventSequence *sequence,
- MetaSequenceState state)
-{
- if (META_BACKEND_GET_CLASS (backend)->finish_touch_sequence)
- META_BACKEND_GET_CLASS (backend)->finish_touch_sequence (backend,
- sequence,
- state);
-}
-
-MetaLogicalMonitor *
-meta_backend_get_current_logical_monitor (MetaBackend *backend)
-{
- return META_BACKEND_GET_CLASS (backend)->get_current_logical_monitor (backend);
-}
-
-void
-meta_backend_set_keymap (MetaBackend *backend,
- const char *layouts,
- const char *variants,
- const char *options)
-{
- META_BACKEND_GET_CLASS (backend)->set_keymap (backend, layouts, variants, options);
-}
-
-/**
- * meta_backend_get_keymap: (skip)
- */
-struct xkb_keymap *
-meta_backend_get_keymap (MetaBackend *backend)
-
-{
- return META_BACKEND_GET_CLASS (backend)->get_keymap (backend);
-}
-
-xkb_layout_index_t
-meta_backend_get_keymap_layout_group (MetaBackend *backend)
-{
- return META_BACKEND_GET_CLASS (backend)->get_keymap_layout_group (backend);
-}
-
-void
-meta_backend_lock_layout_group (MetaBackend *backend,
- guint idx)
-{
- META_BACKEND_GET_CLASS (backend)->lock_layout_group (backend, idx);
-}
-
-/**
- * meta_backend_get_stage:
- * @backend: A #MetaBackend
- *
- * Gets the global #ClutterStage that's managed by this backend.
- *
- * Returns: (transfer none): the #ClutterStage
- */
-ClutterActor *
-meta_backend_get_stage (MetaBackend *backend)
-{
- MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
- return priv->stage;
-}
-
-ClutterSeat *
-meta_backend_get_default_seat (MetaBackend *backend)
-{
- MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
-
- return priv->default_seat;
-}
-
-static gboolean
-update_last_device (MetaBackend *backend)
-{
- MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
- MetaCursorTracker *cursor_tracker = priv->cursor_tracker;
- ClutterInputDeviceType device_type;
-
- priv->device_update_idle_id = 0;
- device_type = clutter_input_device_get_device_type (priv->current_device);
-
- g_signal_emit (backend, signals[LAST_DEVICE_CHANGED], 0,
- priv->current_device);
-
- switch (device_type)
- {
- case CLUTTER_KEYBOARD_DEVICE:
- break;
- case CLUTTER_TOUCHSCREEN_DEVICE:
- meta_cursor_tracker_set_pointer_visible (cursor_tracker, FALSE);
- break;
- default:
- meta_cursor_tracker_set_pointer_visible (cursor_tracker, TRUE);
- break;
- }
-
- return G_SOURCE_REMOVE;
-}
-
-void
-meta_backend_update_last_device (MetaBackend *backend,
- ClutterInputDevice *device)
-{
- MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
-
- if (priv->current_device == device)
- return;
-
- if (!device ||
- clutter_input_device_get_device_mode (device) == CLUTTER_INPUT_MODE_LOGICAL)
- return;
-
- g_set_object (&priv->current_device, device);
-
- if (priv->device_update_idle_id == 0)
- {
- priv->device_update_idle_id =
- g_idle_add ((GSourceFunc) update_last_device, backend);
- g_source_set_name_by_id (priv->device_update_idle_id,
- "[mutter] update_last_device");
- }
-}
-
-MetaPointerConstraint *
-meta_backend_get_client_pointer_constraint (MetaBackend *backend)
-{
- MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
-
- return priv->client_pointer_constraint;
-}
-
-/**
- * meta_backend_set_client_pointer_constraint:
- * @backend: a #MetaBackend object.
- * @constraint: (nullable): the client constraint to follow.
- *
- * Sets the current pointer constraint and removes (and unrefs) the previous
- * one. If @constraint is %NULL, this means that there is no
- * #MetaPointerConstraint active.
- */
-void
-meta_backend_set_client_pointer_constraint (MetaBackend *backend,
- MetaPointerConstraint *constraint)
-{
- MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
-
- META_BACKEND_GET_CLASS (backend)->set_pointer_constraint (backend, constraint);
- g_set_object (&priv->client_pointer_constraint, constraint);
-}
-
-ClutterBackend *
-meta_backend_get_clutter_backend (MetaBackend *backend)
-{
- MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
-
- if (!priv->clutter_backend)
- {
- priv->clutter_backend =
- META_BACKEND_GET_CLASS (backend)->create_clutter_backend (backend);
- }
-
- return priv->clutter_backend;
-}
-
-void
-meta_backend_prepare_shutdown (MetaBackend *backend)
-{
- g_signal_emit (backend, signals[PREPARE_SHUTDOWN], 0);
-}
-
-/**
- * meta_is_stage_views_enabled:
- *
- * Returns whether the #ClutterStage can be rendered using multiple stage views.
- * In practice, this means we can define a separate framebuffer for each
- * #MetaLogicalMonitor, rather than rendering everything into a single
- * framebuffer. For example: in X11, onle one single framebuffer is allowed.
- */
-gboolean
-meta_is_stage_views_enabled (void)
-{
- if (!meta_is_wayland_compositor ())
- return FALSE;
-
- return !stage_views_disabled;
-}
-
-gboolean
-meta_is_stage_views_scaled (void)
-{
- MetaBackend *backend = meta_get_backend ();
- MetaMonitorManager *monitor_manager =
- meta_backend_get_monitor_manager (backend);
- MetaLogicalMonitorLayoutMode layout_mode;
-
- if (!meta_is_stage_views_enabled ())
- return FALSE;
-
- layout_mode = monitor_manager->layout_mode;
-
- return layout_mode == META_LOGICAL_MONITOR_LAYOUT_MODE_LOGICAL;
-}
-
-MetaInputMapper *
-meta_backend_get_input_mapper (MetaBackend *backend)
-{
- MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
-
- return priv->input_mapper;
-}
-
-MetaInputSettings *
-meta_backend_get_input_settings (MetaBackend *backend)
-{
- return META_BACKEND_GET_CLASS (backend)->get_input_settings (backend);
-}
-
-/**
- * meta_backend_get_dnd:
- * @backend: A #MetaDnd
- *
- * Gets the global #MetaDnd that's managed by this backend.
- *
- * Returns: (transfer none): the #MetaDnd
- */
-MetaDnd *
-meta_backend_get_dnd (MetaBackend *backend)
-{
- MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
-
- return priv->dnd;
-}
-
-void
-meta_backend_notify_keymap_changed (MetaBackend *backend)
-{
- g_signal_emit (backend, signals[KEYMAP_CHANGED], 0);
-}
-
-void
-meta_backend_notify_keymap_layout_group_changed (MetaBackend *backend,
- unsigned int locked_group)
-{
- g_signal_emit (backend, signals[KEYMAP_LAYOUT_GROUP_CHANGED], 0,
- locked_group);
-}
-
-void
-meta_backend_add_gpu (MetaBackend *backend,
- MetaGpu *gpu)
-{
- MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
-
- priv->gpus = g_list_append (priv->gpus, gpu);
-
- g_signal_emit (backend, signals[GPU_ADDED], 0, gpu);
-}
-
-GList *
-meta_backend_get_gpus (MetaBackend *backend)
-{
- MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
-
- return priv->gpus;
-}
-
-#ifdef HAVE_LIBWACOM
-WacomDeviceDatabase *
-meta_backend_get_wacom_database (MetaBackend *backend)
-{
- MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
-
- return priv->wacom_db;
-}
-#endif
-
-void
-meta_backend_add_hw_cursor_inhibitor (MetaBackend *backend,
- MetaHwCursorInhibitor *inhibitor)
-{
- MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
-
- priv->hw_cursor_inhibitors = g_list_prepend (priv->hw_cursor_inhibitors,
- inhibitor);
-}
-
-void
-meta_backend_remove_hw_cursor_inhibitor (MetaBackend *backend,
- MetaHwCursorInhibitor *inhibitor)
-{
- MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
-
- priv->hw_cursor_inhibitors = g_list_remove (priv->hw_cursor_inhibitors,
- inhibitor);
-}
-
-gboolean
-meta_backend_is_hw_cursors_inhibited (MetaBackend *backend)
-{
- MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
- GList *l;
-
- for (l = priv->hw_cursor_inhibitors; l; l = l->next)
- {
- MetaHwCursorInhibitor *inhibitor = l->data;
-
- if (meta_hw_cursor_inhibitor_is_cursor_inhibited (inhibitor))
- return TRUE;
- }
-
- return FALSE;
-}
diff --git a/src/backends/meta-barrier-private.h b/src/backends/meta-barrier-private.h
deleted file mode 100644
index d0483e43c..000000000
--- a/src/backends/meta-barrier-private.h
+++ /dev/null
@@ -1,66 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2014-2015 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Written by:
- * Jasper St. Pierre <jstpierre@mecheye.net>
- * Jonas Ådahl <jadahl@gmail.com>
- */
-
-#ifndef META_BARRIER_PRIVATE_H
-#define META_BARRIER_PRIVATE_H
-
-#include "core/meta-border.h"
-#include "meta/barrier.h"
-
-G_BEGIN_DECLS
-
-#define META_TYPE_BARRIER_IMPL (meta_barrier_impl_get_type ())
-G_DECLARE_DERIVABLE_TYPE (MetaBarrierImpl,
- meta_barrier_impl,
- META, BARRIER_IMPL,
- GObject)
-
-struct _MetaBarrierImplClass
-{
- GObjectClass parent_class;
-
- gboolean (*is_active) (MetaBarrierImpl *barrier);
- void (*release) (MetaBarrierImpl *barrier,
- MetaBarrierEvent *event);
- void (*destroy) (MetaBarrierImpl *barrier);
-};
-
-void _meta_barrier_emit_hit_signal (MetaBarrier *barrier,
- MetaBarrierEvent *event);
-void _meta_barrier_emit_left_signal (MetaBarrier *barrier,
- MetaBarrierEvent *event);
-
-void meta_barrier_event_unref (MetaBarrierEvent *event);
-
-G_END_DECLS
-
-struct _MetaBarrierPrivate
-{
- MetaDisplay *display;
- MetaBorder border;
- MetaBarrierImpl *impl;
-};
-
-#endif /* META_BARRIER_PRIVATE_H */
diff --git a/src/backends/meta-barrier.c b/src/backends/meta-barrier.c
deleted file mode 100644
index d924d0ab3..000000000
--- a/src/backends/meta-barrier.c
+++ /dev/null
@@ -1,365 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; c-basic-offset: 2; -*- */
-
-/**
- * SECTION:barrier
- * @Title: MetaBarrier
- * @Short_Description: Pointer barriers
- */
-
-#include "config.h"
-
-#include "meta/barrier.h"
-#include "backends/meta-barrier-private.h"
-
-#include <glib-object.h>
-
-#include "backends/x11/meta-backend-x11.h"
-#include "backends/x11/meta-barrier-x11.h"
-#include "meta/meta-enum-types.h"
-#include "meta/util.h"
-
-#ifdef HAVE_NATIVE_BACKEND
-#include "backends/native/meta-backend-native.h"
-#include "backends/native/meta-barrier-native.h"
-#endif
-
-G_DEFINE_TYPE_WITH_PRIVATE (MetaBarrier, meta_barrier, G_TYPE_OBJECT)
-G_DEFINE_TYPE (MetaBarrierImpl, meta_barrier_impl, G_TYPE_OBJECT)
-
-enum
-{
- PROP_0,
-
- PROP_DISPLAY,
-
- PROP_X1,
- PROP_Y1,
- PROP_X2,
- PROP_Y2,
- PROP_DIRECTIONS,
-
- PROP_LAST,
-};
-
-static GParamSpec *obj_props[PROP_LAST];
-
-enum
-{
- HIT,
- LEFT,
-
- LAST_SIGNAL,
-};
-
-static guint obj_signals[LAST_SIGNAL];
-
-
-static void
-meta_barrier_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- MetaBarrier *barrier = META_BARRIER (object);
- MetaBarrierPrivate *priv = barrier->priv;
- switch (prop_id)
- {
- case PROP_DISPLAY:
- g_value_set_object (value, priv->display);
- break;
- case PROP_X1:
- g_value_set_int (value, priv->border.line.a.x);
- break;
- case PROP_Y1:
- g_value_set_int (value, priv->border.line.a.y);
- break;
- case PROP_X2:
- g_value_set_int (value, priv->border.line.b.x);
- break;
- case PROP_Y2:
- g_value_set_int (value, priv->border.line.b.y);
- break;
- case PROP_DIRECTIONS:
- g_value_set_flags (value,
- meta_border_get_allows_directions (&priv->border));
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-
-static void
-meta_barrier_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- MetaBarrier *barrier = META_BARRIER (object);
- MetaBarrierPrivate *priv = barrier->priv;
- switch (prop_id)
- {
- case PROP_DISPLAY:
- priv->display = g_value_get_object (value);
- break;
- case PROP_X1:
- priv->border.line.a.x = g_value_get_int (value);
- break;
- case PROP_Y1:
- priv->border.line.a.y = g_value_get_int (value);
- break;
- case PROP_X2:
- priv->border.line.b.x = g_value_get_int (value);
- break;
- case PROP_Y2:
- priv->border.line.b.y = g_value_get_int (value);
- break;
- case PROP_DIRECTIONS:
- meta_border_set_allows_directions (&priv->border,
- g_value_get_flags (value));
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-
-static void
-meta_barrier_dispose (GObject *object)
-{
- MetaBarrier *barrier = META_BARRIER (object);
- MetaBarrierPrivate *priv = barrier->priv;
-
- if (meta_barrier_is_active (barrier))
- {
- meta_bug ("MetaBarrier %p was destroyed while it was still active.",
- barrier);
- }
-
- g_clear_object (&priv->impl);
-
- G_OBJECT_CLASS (meta_barrier_parent_class)->dispose (object);
-}
-
-gboolean
-meta_barrier_is_active (MetaBarrier *barrier)
-{
- MetaBarrierImpl *impl = barrier->priv->impl;
-
- if (impl)
- return META_BARRIER_IMPL_GET_CLASS (impl)->is_active (impl);
- else
- return FALSE;
-}
-
-/**
- * meta_barrier_release:
- * @barrier: The barrier to release
- * @event: The event to release the pointer for
- *
- * In XI2.3, pointer barriers provide a feature where they can
- * be temporarily released so that the pointer goes through
- * them. Pass a #MetaBarrierEvent to release the barrier for
- * this event sequence.
- */
-void
-meta_barrier_release (MetaBarrier *barrier,
- MetaBarrierEvent *event)
-{
- MetaBarrierImpl *impl = barrier->priv->impl;
-
- if (impl)
- META_BARRIER_IMPL_GET_CLASS (impl)->release (impl, event);
-}
-
-static void
-meta_barrier_constructed (GObject *object)
-{
- MetaBarrier *barrier = META_BARRIER (object);
- MetaBarrierPrivate *priv = barrier->priv;
-
- g_return_if_fail (priv->border.line.a.x == priv->border.line.b.x ||
- priv->border.line.a.y == priv->border.line.b.y);
- g_return_if_fail (priv->border.line.a.x >= 0);
- g_return_if_fail (priv->border.line.a.y >= 0);
- g_return_if_fail (priv->border.line.b.x >= 0);
- g_return_if_fail (priv->border.line.b.y >= 0);
-
-#if defined(HAVE_NATIVE_BACKEND)
- if (META_IS_BACKEND_NATIVE (meta_get_backend ()))
- priv->impl = meta_barrier_impl_native_new (barrier);
-#endif
- if (META_IS_BACKEND_X11 (meta_get_backend ()) &&
- !meta_is_wayland_compositor ())
- priv->impl = meta_barrier_impl_x11_new (barrier);
-
- if (priv->impl == NULL)
- g_warning ("Created a non-working barrier");
-
- /* Take a ref that we'll release in destroy() so that the object stays
- * alive while active. */
- g_object_ref (barrier);
-
- G_OBJECT_CLASS (meta_barrier_parent_class)->constructed (object);
-}
-
-static void
-meta_barrier_class_init (MetaBarrierClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- object_class->get_property = meta_barrier_get_property;
- object_class->set_property = meta_barrier_set_property;
- object_class->dispose = meta_barrier_dispose;
- object_class->constructed = meta_barrier_constructed;
-
- obj_props[PROP_DISPLAY] =
- g_param_spec_object ("display",
- "Display",
- "The display to construct the pointer barrier on",
- META_TYPE_DISPLAY,
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
-
- obj_props[PROP_X1] =
- g_param_spec_int ("x1",
- "X1",
- "The first X coordinate of the barrier",
- 0, G_MAXSHORT, 0,
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
-
- obj_props[PROP_Y1] =
- g_param_spec_int ("y1",
- "Y1",
- "The first Y coordinate of the barrier",
- 0, G_MAXSHORT, 0,
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
-
- obj_props[PROP_X2] =
- g_param_spec_int ("x2",
- "X2",
- "The second X coordinate of the barrier",
- 0, G_MAXSHORT, G_MAXSHORT,
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
-
- obj_props[PROP_Y2] =
- g_param_spec_int ("y2",
- "Y2",
- "The second Y coordinate of the barrier",
- 0, G_MAXSHORT, G_MAXSHORT,
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
-
- obj_props[PROP_DIRECTIONS] =
- g_param_spec_flags ("directions",
- "Directions",
- "A set of directions to let the pointer through",
- META_TYPE_BARRIER_DIRECTION,
- 0,
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
-
- g_object_class_install_properties (object_class, PROP_LAST, obj_props);
-
- /**
- * MetaBarrier::hit:
- * @barrier: The #MetaBarrier that was hit
- * @event: A #MetaBarrierEvent that has the details of how
- * the barrier was hit.
- *
- * When a pointer barrier is hit, this will trigger. This
- * requires an XI2-enabled server.
- */
- obj_signals[HIT] =
- g_signal_new ("hit",
- G_TYPE_FROM_CLASS (object_class),
- G_SIGNAL_RUN_FIRST,
- 0,
- NULL, NULL, NULL,
- G_TYPE_NONE, 1,
- META_TYPE_BARRIER_EVENT);
-
- /**
- * MetaBarrier::left:
- * @barrier: The #MetaBarrier that was left
- * @event: A #MetaBarrierEvent that has the details of how
- * the barrier was left.
- *
- * When a pointer barrier hitbox was left, this will trigger.
- * This requires an XI2-enabled server.
- */
- obj_signals[LEFT] =
- g_signal_new ("left",
- G_TYPE_FROM_CLASS (object_class),
- G_SIGNAL_RUN_FIRST,
- 0,
- NULL, NULL, NULL,
- G_TYPE_NONE, 1,
- META_TYPE_BARRIER_EVENT);
-}
-
-void
-meta_barrier_destroy (MetaBarrier *barrier)
-{
- MetaBarrierImpl *impl = barrier->priv->impl;
-
- if (impl)
- META_BARRIER_IMPL_GET_CLASS (impl)->destroy (impl);
-
- g_object_unref (barrier);
-}
-
-static void
-meta_barrier_init (MetaBarrier *barrier)
-{
- barrier->priv = meta_barrier_get_instance_private (barrier);
-}
-
-void
-_meta_barrier_emit_hit_signal (MetaBarrier *barrier,
- MetaBarrierEvent *event)
-{
- g_signal_emit (barrier, obj_signals[HIT], 0, event);
-}
-
-void
-_meta_barrier_emit_left_signal (MetaBarrier *barrier,
- MetaBarrierEvent *event)
-{
- g_signal_emit (barrier, obj_signals[LEFT], 0, event);
-}
-
-static void
-meta_barrier_impl_class_init (MetaBarrierImplClass *klass)
-{
- klass->is_active = NULL;
- klass->release = NULL;
- klass->destroy = NULL;
-}
-
-static void
-meta_barrier_impl_init (MetaBarrierImpl *impl)
-{
-}
-
-static MetaBarrierEvent *
-meta_barrier_event_ref (MetaBarrierEvent *event)
-{
- g_return_val_if_fail (event != NULL, NULL);
- g_return_val_if_fail (event->ref_count > 0, NULL);
-
- g_atomic_int_inc ((volatile int *)&event->ref_count);
- return event;
-}
-
-void
-meta_barrier_event_unref (MetaBarrierEvent *event)
-{
- g_return_if_fail (event != NULL);
- g_return_if_fail (event->ref_count > 0);
-
- if (g_atomic_int_dec_and_test ((volatile int *)&event->ref_count))
- g_free (event);
-}
-
-G_DEFINE_BOXED_TYPE (MetaBarrierEvent,
- meta_barrier_event,
- meta_barrier_event_ref,
- meta_barrier_event_unref)
diff --git a/src/backends/meta-crtc-mode.c b/src/backends/meta-crtc-mode.c
deleted file mode 100644
index 6d2de4b74..000000000
--- a/src/backends/meta-crtc-mode.c
+++ /dev/null
@@ -1,200 +0,0 @@
-/*
- * Copyright (C) 2017-2020 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-
-#include "config.h"
-
-#include "backends/meta-crtc-mode.h"
-
-enum
-{
- PROP_0,
-
- PROP_ID,
- PROP_NAME,
- PROP_INFO,
-
- N_PROPS
-};
-
-static GParamSpec *obj_props[N_PROPS];
-
-typedef struct _MetaCrtcModePrivate
-{
- uint64_t id;
- char *name;
- MetaCrtcModeInfo *info;
-} MetaCrtcModePrivate;
-
-G_DEFINE_TYPE_WITH_PRIVATE (MetaCrtcMode, meta_crtc_mode, G_TYPE_OBJECT)
-
-G_DEFINE_BOXED_TYPE (MetaCrtcModeInfo, meta_crtc_mode_info,
- meta_crtc_mode_info_ref,
- meta_crtc_mode_info_unref)
-
-MetaCrtcModeInfo *
-meta_crtc_mode_info_new (void)
-{
- MetaCrtcModeInfo *crtc_mode_info;
-
- crtc_mode_info = g_new0 (MetaCrtcModeInfo, 1);
- g_ref_count_init (&crtc_mode_info->ref_count);
-
- return crtc_mode_info;
-}
-
-MetaCrtcModeInfo *
-meta_crtc_mode_info_ref (MetaCrtcModeInfo *crtc_mode_info)
-{
- g_ref_count_inc (&crtc_mode_info->ref_count);
- return crtc_mode_info;
-}
-
-void
-meta_crtc_mode_info_unref (MetaCrtcModeInfo *crtc_mode_info)
-{
- if (g_ref_count_dec (&crtc_mode_info->ref_count))
- g_free (crtc_mode_info);
-}
-
-uint64_t
-meta_crtc_mode_get_id (MetaCrtcMode *crtc_mode)
-{
- MetaCrtcModePrivate *priv = meta_crtc_mode_get_instance_private (crtc_mode);
-
- return priv->id;
-}
-
-const char *
-meta_crtc_mode_get_name (MetaCrtcMode *crtc_mode)
-{
- MetaCrtcModePrivate *priv = meta_crtc_mode_get_instance_private (crtc_mode);
-
- return priv->name;
-}
-
-const MetaCrtcModeInfo *
-meta_crtc_mode_get_info (MetaCrtcMode *crtc_mode)
-{
- MetaCrtcModePrivate *priv = meta_crtc_mode_get_instance_private (crtc_mode);
-
- return priv->info;
-}
-
-static void
-meta_crtc_mode_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- MetaCrtcMode *crtc_mode = META_CRTC_MODE (object);
- MetaCrtcModePrivate *priv = meta_crtc_mode_get_instance_private (crtc_mode);
-
- switch (prop_id)
- {
- case PROP_ID:
- priv->id = g_value_get_uint64 (value);
- break;
- case PROP_NAME:
- priv->name = g_value_dup_string (value);
- break;
- case PROP_INFO:
- priv->info = meta_crtc_mode_info_ref (g_value_get_boxed (value));
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- }
-}
-
-static void
-meta_crtc_mode_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- MetaCrtcMode *crtc_mode = META_CRTC_MODE (object);
- MetaCrtcModePrivate *priv = meta_crtc_mode_get_instance_private (crtc_mode);
-
- switch (prop_id)
- {
- case PROP_ID:
- g_value_set_uint64 (value, priv->id);
- break;
- case PROP_NAME:
- g_value_set_string (value, priv->name);
- break;
- case PROP_INFO:
- g_value_set_boxed (value, priv->info);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- }
-}
-
-static void
-meta_crtc_mode_finalize (GObject *object)
-{
- MetaCrtcMode *crtc_mode = META_CRTC_MODE (object);
- MetaCrtcModePrivate *priv = meta_crtc_mode_get_instance_private (crtc_mode);
-
- g_clear_pointer (&priv->name, g_free);
- g_clear_pointer (&priv->info, meta_crtc_mode_info_unref);
-
- G_OBJECT_CLASS (meta_crtc_mode_parent_class)->finalize (object);
-}
-
-static void
-meta_crtc_mode_init (MetaCrtcMode *crtc_mode)
-{
-}
-
-static void
-meta_crtc_mode_class_init (MetaCrtcModeClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- object_class->set_property = meta_crtc_mode_set_property;
- object_class->get_property = meta_crtc_mode_get_property;
- object_class->finalize = meta_crtc_mode_finalize;
-
- obj_props[PROP_ID] =
- g_param_spec_uint64 ("id",
- "id",
- "CRTC mode id",
- 0, UINT64_MAX, 0,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT_ONLY |
- G_PARAM_STATIC_STRINGS);
- obj_props[PROP_NAME] =
- g_param_spec_string ("name",
- "name",
- "Name of CRTC mode",
- NULL,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT_ONLY |
- G_PARAM_STATIC_STRINGS);
- obj_props[PROP_INFO] =
- g_param_spec_boxed ("info",
- "info",
- "MetaOutputInfo",
- META_TYPE_CRTC_MODE_INFO,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT_ONLY |
- G_PARAM_STATIC_STRINGS);
- g_object_class_install_properties (object_class, N_PROPS, obj_props);
-}
diff --git a/src/backends/meta-crtc-mode.h b/src/backends/meta-crtc-mode.h
deleted file mode 100644
index 2ac90e408..000000000
--- a/src/backends/meta-crtc-mode.h
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * Copyright (C) 2017-2020 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-
-#ifndef META_CRTC_MODE_H
-#define META_CRTC_MODE_H
-
-#include <glib-object.h>
-#include <stdint.h>
-
-#include "core/util-private.h"
-
-/* Same as KMS mode flags and X11 randr flags */
-typedef enum _MetaCrtcModeFlag
-{
- META_CRTC_MODE_FLAG_NONE = 0,
- META_CRTC_MODE_FLAG_PHSYNC = (1 << 0),
- META_CRTC_MODE_FLAG_NHSYNC = (1 << 1),
- META_CRTC_MODE_FLAG_PVSYNC = (1 << 2),
- META_CRTC_MODE_FLAG_NVSYNC = (1 << 3),
- META_CRTC_MODE_FLAG_INTERLACE = (1 << 4),
- META_CRTC_MODE_FLAG_DBLSCAN = (1 << 5),
- META_CRTC_MODE_FLAG_CSYNC = (1 << 6),
- META_CRTC_MODE_FLAG_PCSYNC = (1 << 7),
- META_CRTC_MODE_FLAG_NCSYNC = (1 << 8),
- META_CRTC_MODE_FLAG_HSKEW = (1 << 9),
- META_CRTC_MODE_FLAG_BCAST = (1 << 10),
- META_CRTC_MODE_FLAG_PIXMUX = (1 << 11),
- META_CRTC_MODE_FLAG_DBLCLK = (1 << 12),
- META_CRTC_MODE_FLAG_CLKDIV2 = (1 << 13),
-
- META_CRTC_MODE_FLAG_MASK = 0x3fff
-} MetaCrtcModeFlag;
-
-typedef struct _MetaCrtcModeInfo
-{
- grefcount ref_count;
-
- int width;
- int height;
- float refresh_rate;
- int64_t vblank_duration_us;
- MetaCrtcModeFlag flags;
-} MetaCrtcModeInfo;
-
-#define META_TYPE_CRTC_MODE (meta_crtc_mode_get_type ())
-META_EXPORT_TEST
-G_DECLARE_DERIVABLE_TYPE (MetaCrtcMode, meta_crtc_mode,
- META, CRTC_MODE,
- GObject)
-
-struct _MetaCrtcModeClass
-{
- GObjectClass parent_class;
-};
-
-#define META_TYPE_CRTC_MODE_INFO (meta_crtc_mode_info_get_type ())
-GType meta_crtc_mode_info_get_type (void);
-
-META_EXPORT_TEST
-MetaCrtcModeInfo * meta_crtc_mode_info_new (void);
-
-META_EXPORT_TEST
-MetaCrtcModeInfo * meta_crtc_mode_info_ref (MetaCrtcModeInfo *crtc_mode_info);
-
-META_EXPORT_TEST
-void meta_crtc_mode_info_unref (MetaCrtcModeInfo *crtc_mode_info);
-
-G_DEFINE_AUTOPTR_CLEANUP_FUNC (MetaCrtcModeInfo, meta_crtc_mode_info_unref)
-
-uint64_t meta_crtc_mode_get_id (MetaCrtcMode *crtc_mode);
-
-const char * meta_crtc_mode_get_name (MetaCrtcMode *crtc_mode);
-
-META_EXPORT_TEST
-const MetaCrtcModeInfo * meta_crtc_mode_get_info (MetaCrtcMode *crtc_mode);
-
-#endif /* META_CRTC_MODE_H */
diff --git a/src/backends/meta-crtc.c b/src/backends/meta-crtc.c
deleted file mode 100644
index 09f9199d5..000000000
--- a/src/backends/meta-crtc.c
+++ /dev/null
@@ -1,246 +0,0 @@
-/*
- * Copyright (C) 2017 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-
-#include "config.h"
-
-#include "backends/meta-crtc.h"
-
-#include "backends/meta-gpu.h"
-
-enum
-{
- PROP_0,
-
- PROP_ID,
- PROP_GPU,
- PROP_ALL_TRANSFORMS,
-
- N_PROPS
-};
-
-static GParamSpec *obj_props[N_PROPS];
-
-typedef struct _MetaCrtcPrivate
-{
- uint64_t id;
-
- MetaGpu *gpu;
-
- MetaMonitorTransform all_transforms;
-
- GList *outputs;
- MetaCrtcConfig *config;
-} MetaCrtcPrivate;
-
-G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (MetaCrtc, meta_crtc, G_TYPE_OBJECT)
-
-uint64_t
-meta_crtc_get_id (MetaCrtc *crtc)
-{
- MetaCrtcPrivate *priv = meta_crtc_get_instance_private (crtc);
-
- return priv->id;
-}
-
-MetaGpu *
-meta_crtc_get_gpu (MetaCrtc *crtc)
-{
- MetaCrtcPrivate *priv = meta_crtc_get_instance_private (crtc);
-
- return priv->gpu;
-}
-
-const GList *
-meta_crtc_get_outputs (MetaCrtc *crtc)
-{
- MetaCrtcPrivate *priv = meta_crtc_get_instance_private (crtc);
-
- return priv->outputs;
-}
-
-void
-meta_crtc_assign_output (MetaCrtc *crtc,
- MetaOutput *output)
-{
- MetaCrtcPrivate *priv = meta_crtc_get_instance_private (crtc);
-
- priv->outputs = g_list_append (priv->outputs, output);
-}
-
-void
-meta_crtc_unassign_output (MetaCrtc *crtc,
- MetaOutput *output)
-{
- MetaCrtcPrivate *priv = meta_crtc_get_instance_private (crtc);
-
- g_return_if_fail (g_list_find (priv->outputs, output));
-
- priv->outputs = g_list_remove (priv->outputs, output);
-}
-
-MetaMonitorTransform
-meta_crtc_get_all_transforms (MetaCrtc *crtc)
-{
- MetaCrtcPrivate *priv = meta_crtc_get_instance_private (crtc);
-
- return priv->all_transforms;
-}
-
-void
-meta_crtc_set_config (MetaCrtc *crtc,
- graphene_rect_t *layout,
- MetaCrtcMode *mode,
- MetaMonitorTransform transform)
-{
- MetaCrtcPrivate *priv = meta_crtc_get_instance_private (crtc);
- MetaCrtcConfig *config;
-
- meta_crtc_unset_config (crtc);
-
- config = g_new0 (MetaCrtcConfig, 1);
- config->layout = *layout;
- config->mode = mode;
- config->transform = transform;
-
- priv->config = config;
-}
-
-void
-meta_crtc_unset_config (MetaCrtc *crtc)
-{
- MetaCrtcPrivate *priv = meta_crtc_get_instance_private (crtc);
-
- g_clear_pointer (&priv->config, g_free);
-}
-
-const MetaCrtcConfig *
-meta_crtc_get_config (MetaCrtc *crtc)
-{
- MetaCrtcPrivate *priv = meta_crtc_get_instance_private (crtc);
-
- return priv->config;
-}
-
-static void
-meta_crtc_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- MetaCrtc *crtc = META_CRTC (object);
- MetaCrtcPrivate *priv = meta_crtc_get_instance_private (crtc);
-
- switch (prop_id)
- {
- case PROP_ID:
- priv->id = g_value_get_uint64 (value);
- break;
- case PROP_GPU:
- priv->gpu = g_value_get_object (value);
- break;
- case PROP_ALL_TRANSFORMS:
- priv->all_transforms = g_value_get_uint (value);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- }
-}
-
-static void
-meta_crtc_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- MetaCrtc *crtc = META_CRTC (object);
- MetaCrtcPrivate *priv = meta_crtc_get_instance_private (crtc);
-
- switch (prop_id)
- {
- case PROP_ID:
- g_value_set_uint64 (value, priv->id);
- break;
- case PROP_GPU:
- g_value_set_object (value, priv->gpu);
- break;
- case PROP_ALL_TRANSFORMS:
- g_value_set_uint (value, priv->all_transforms);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- }
-}
-
-static void
-meta_crtc_finalize (GObject *object)
-{
- MetaCrtc *crtc = META_CRTC (object);
- MetaCrtcPrivate *priv = meta_crtc_get_instance_private (crtc);
-
- g_clear_pointer (&priv->config, g_free);
- g_clear_pointer (&priv->outputs, g_list_free);
-
- G_OBJECT_CLASS (meta_crtc_parent_class)->finalize (object);
-}
-
-static void
-meta_crtc_init (MetaCrtc *crtc)
-{
- MetaCrtcPrivate *priv = meta_crtc_get_instance_private (crtc);
-
- priv->all_transforms = META_MONITOR_ALL_TRANSFORMS;
-}
-
-static void
-meta_crtc_class_init (MetaCrtcClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- object_class->set_property = meta_crtc_set_property;
- object_class->get_property = meta_crtc_get_property;
- object_class->finalize = meta_crtc_finalize;
-
- obj_props[PROP_ID] =
- g_param_spec_uint64 ("id",
- "id",
- "CRTC id",
- 0, UINT64_MAX, 0,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT_ONLY |
- G_PARAM_STATIC_STRINGS);
- obj_props[PROP_GPU] =
- g_param_spec_object ("gpu",
- "gpu",
- "MetaGpu",
- META_TYPE_GPU,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT_ONLY |
- G_PARAM_STATIC_STRINGS);
- obj_props[PROP_ALL_TRANSFORMS] =
- g_param_spec_uint ("all-transforms",
- "all-transforms",
- "All transforms",
- 0,
- META_MONITOR_ALL_TRANSFORMS,
- META_MONITOR_ALL_TRANSFORMS,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT_ONLY |
- G_PARAM_STATIC_STRINGS);
- g_object_class_install_properties (object_class, N_PROPS, obj_props);
-}
diff --git a/src/backends/meta-crtc.h b/src/backends/meta-crtc.h
deleted file mode 100644
index f6a3bc136..000000000
--- a/src/backends/meta-crtc.h
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * Copyright (C) 2017 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-
-#ifndef META_CRTC_H
-#define META_CRTC_H
-
-#include <glib-object.h>
-
-#include "backends/meta-backend-types.h"
-#include "backends/meta-crtc-mode.h"
-#include "backends/meta-monitor-transform.h"
-#include "core/util-private.h"
-#include "meta/boxes.h"
-
-typedef struct _MetaCrtcConfig
-{
- graphene_rect_t layout;
- MetaMonitorTransform transform;
- MetaCrtcMode *mode;
-} MetaCrtcConfig;
-
-#define META_TYPE_CRTC (meta_crtc_get_type ())
-META_EXPORT_TEST
-G_DECLARE_DERIVABLE_TYPE (MetaCrtc, meta_crtc, META, CRTC, GObject)
-
-struct _MetaCrtcClass
-{
- GObjectClass parent_class;
-};
-
-META_EXPORT_TEST
-uint64_t meta_crtc_get_id (MetaCrtc *crtc);
-
-META_EXPORT_TEST
-MetaGpu * meta_crtc_get_gpu (MetaCrtc *crtc);
-
-META_EXPORT_TEST
-const GList * meta_crtc_get_outputs (MetaCrtc *crtc);
-
-void meta_crtc_assign_output (MetaCrtc *crtc,
- MetaOutput *output);
-
-META_EXPORT_TEST
-void meta_crtc_unassign_output (MetaCrtc *crtc,
- MetaOutput *output);
-
-MetaMonitorTransform meta_crtc_get_all_transforms (MetaCrtc *crtc);
-
-META_EXPORT_TEST
-void meta_crtc_set_config (MetaCrtc *crtc,
- graphene_rect_t *layout,
- MetaCrtcMode *mode,
- MetaMonitorTransform transform);
-
-META_EXPORT_TEST
-void meta_crtc_unset_config (MetaCrtc *crtc);
-
-META_EXPORT_TEST
-const MetaCrtcConfig * meta_crtc_get_config (MetaCrtc *crtc);
-
-#endif /* META_CRTC_H */
diff --git a/src/backends/meta-cursor-renderer.c b/src/backends/meta-cursor-renderer.c
deleted file mode 100644
index 3353b17d3..000000000
--- a/src/backends/meta-cursor-renderer.c
+++ /dev/null
@@ -1,492 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2014 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Written by:
- * Jasper St. Pierre <jstpierre@mecheye.net>
- */
-
-#include "config.h"
-
-#include "backends/meta-cursor-renderer.h"
-
-#include <math.h>
-
-#include "backends/meta-backend-private.h"
-#include "backends/meta-logical-monitor.h"
-#include "backends/meta-stage-private.h"
-#include "clutter/clutter.h"
-#include "clutter/clutter-mutter.h"
-#include "cogl/cogl.h"
-#include "core/boxes-private.h"
-#include "meta/meta-backend.h"
-#include "meta/util.h"
-
-G_DEFINE_INTERFACE (MetaHwCursorInhibitor, meta_hw_cursor_inhibitor,
- G_TYPE_OBJECT)
-
-enum
-{
- PROP_0,
-
- PROP_BACKEND,
- PROP_DEVICE,
-
- N_PROPS
-};
-
-static GParamSpec *obj_props[N_PROPS];
-
-struct _MetaCursorRendererPrivate
-{
- MetaBackend *backend;
-
- float current_x;
- float current_y;
-
- ClutterInputDevice *device;
- MetaCursorSprite *displayed_cursor;
- MetaCursorSprite *overlay_cursor;
-
- MetaOverlay *stage_overlay;
- gboolean handled_by_backend;
- gulong after_paint_handler_id;
-
- GList *hw_cursor_inhibitors;
-};
-typedef struct _MetaCursorRendererPrivate MetaCursorRendererPrivate;
-
-enum
-{
- CURSOR_PAINTED,
- LAST_SIGNAL
-};
-static guint signals[LAST_SIGNAL];
-
-G_DEFINE_TYPE_WITH_PRIVATE (MetaCursorRenderer, meta_cursor_renderer, G_TYPE_OBJECT);
-
-gboolean
-meta_hw_cursor_inhibitor_is_cursor_inhibited (MetaHwCursorInhibitor *inhibitor)
-{
- MetaHwCursorInhibitorInterface *iface =
- META_HW_CURSOR_INHIBITOR_GET_IFACE (inhibitor);
-
- return iface->is_cursor_inhibited (inhibitor);
-}
-
-static void
-meta_hw_cursor_inhibitor_default_init (MetaHwCursorInhibitorInterface *iface)
-{
-}
-
-void
-meta_cursor_renderer_emit_painted (MetaCursorRenderer *renderer,
- MetaCursorSprite *cursor_sprite,
- ClutterStageView *stage_view)
-{
- g_signal_emit (renderer, signals[CURSOR_PAINTED], 0, cursor_sprite, stage_view);
-}
-
-static void
-align_cursor_position (MetaCursorRenderer *renderer,
- graphene_rect_t *rect)
-{
- MetaCursorRendererPrivate *priv =
- meta_cursor_renderer_get_instance_private (renderer);
- ClutterActor *stage = meta_backend_get_stage (priv->backend);
- ClutterStageView *view;
- cairo_rectangle_int_t view_layout;
- float view_scale;
-
- view = clutter_stage_get_view_at (CLUTTER_STAGE (stage),
- priv->current_x,
- priv->current_y);
- if (!view)
- return;
-
- clutter_stage_view_get_layout (view, &view_layout);
- view_scale = clutter_stage_view_get_scale (view);
-
- graphene_rect_offset (rect, -view_layout.x, -view_layout.y);
- rect->origin.x = floorf (rect->origin.x * view_scale) / view_scale;
- rect->origin.y = floorf (rect->origin.y * view_scale) / view_scale;
- graphene_rect_offset (rect, view_layout.x, view_layout.y);
-}
-
-void
-meta_cursor_renderer_update_stage_overlay (MetaCursorRenderer *renderer,
- MetaCursorSprite *cursor_sprite)
-{
- MetaCursorRendererPrivate *priv = meta_cursor_renderer_get_instance_private (renderer);
- ClutterActor *stage = meta_backend_get_stage (priv->backend);
- CoglTexture *texture;
- graphene_rect_t rect = GRAPHENE_RECT_INIT_ZERO;
-
- g_set_object (&priv->overlay_cursor, cursor_sprite);
-
- if (cursor_sprite)
- {
- rect = meta_cursor_renderer_calculate_rect (renderer, cursor_sprite);
- align_cursor_position (renderer, &rect);
- }
-
- if (!priv->stage_overlay)
- priv->stage_overlay = meta_stage_create_cursor_overlay (META_STAGE (stage));
-
- if (cursor_sprite)
- texture = meta_cursor_sprite_get_cogl_texture (cursor_sprite);
- else
- texture = NULL;
-
- meta_overlay_set_visible (priv->stage_overlay, !priv->handled_by_backend);
- meta_stage_update_cursor_overlay (META_STAGE (stage), priv->stage_overlay,
- texture, &rect);
-}
-
-static void
-meta_cursor_renderer_after_paint (ClutterStage *stage,
- ClutterStageView *stage_view,
- MetaCursorRenderer *renderer)
-{
- MetaCursorRendererPrivate *priv =
- meta_cursor_renderer_get_instance_private (renderer);
-
- if (priv->displayed_cursor && !priv->handled_by_backend)
- {
- graphene_rect_t rect;
- MetaRectangle view_layout;
- graphene_rect_t view_rect;
-
- rect = meta_cursor_renderer_calculate_rect (renderer,
- priv->displayed_cursor);
- clutter_stage_view_get_layout (stage_view, &view_layout);
- view_rect = meta_rectangle_to_graphene_rect (&view_layout);
- if (graphene_rect_intersection (&rect, &view_rect, NULL))
- {
- meta_cursor_renderer_emit_painted (renderer,
- priv->displayed_cursor,
- stage_view);
- }
- }
-}
-
-static gboolean
-meta_cursor_renderer_real_update_cursor (MetaCursorRenderer *renderer,
- MetaCursorSprite *cursor_sprite)
-{
- if (cursor_sprite)
- meta_cursor_sprite_realize_texture (cursor_sprite);
-
- return FALSE;
-}
-
-static void
-meta_cursor_renderer_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- MetaCursorRenderer *renderer = META_CURSOR_RENDERER (object);
- MetaCursorRendererPrivate *priv =
- meta_cursor_renderer_get_instance_private (renderer);
-
- switch (prop_id)
- {
- case PROP_BACKEND:
- g_value_set_object (value, priv->backend);
- break;
- case PROP_DEVICE:
- g_value_set_object (value, priv->device);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-
-static void
-meta_cursor_renderer_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- MetaCursorRenderer *renderer = META_CURSOR_RENDERER (object);
- MetaCursorRendererPrivate *priv =
- meta_cursor_renderer_get_instance_private (renderer);
-
- switch (prop_id)
- {
- case PROP_BACKEND:
- priv->backend = g_value_get_object (value);
- break;
- case PROP_DEVICE:
- priv->device = g_value_get_object (value);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-
-static void
-meta_cursor_renderer_finalize (GObject *object)
-{
- MetaCursorRenderer *renderer = META_CURSOR_RENDERER (object);
- MetaCursorRendererPrivate *priv = meta_cursor_renderer_get_instance_private (renderer);
- ClutterActor *stage = meta_backend_get_stage (priv->backend);
-
- if (priv->stage_overlay)
- meta_stage_remove_cursor_overlay (META_STAGE (stage), priv->stage_overlay);
-
- g_clear_signal_handler (&priv->after_paint_handler_id, stage);
-
- g_clear_object (&priv->displayed_cursor);
- g_clear_object (&priv->overlay_cursor);
-
- G_OBJECT_CLASS (meta_cursor_renderer_parent_class)->finalize (object);
-}
-
-static void
-meta_cursor_renderer_constructed (GObject *object)
-{
- MetaCursorRenderer *renderer = META_CURSOR_RENDERER (object);
- MetaCursorRendererPrivate *priv =
- meta_cursor_renderer_get_instance_private (renderer);
- ClutterActor *stage;
-
- stage = meta_backend_get_stage (priv->backend);
- priv->after_paint_handler_id =
- g_signal_connect (stage, "after-paint",
- G_CALLBACK (meta_cursor_renderer_after_paint),
- renderer);
-
- G_OBJECT_CLASS (meta_cursor_renderer_parent_class)->constructed (object);
-}
-
-static void
-meta_cursor_renderer_class_init (MetaCursorRendererClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- object_class->get_property = meta_cursor_renderer_get_property;
- object_class->set_property = meta_cursor_renderer_set_property;
- object_class->finalize = meta_cursor_renderer_finalize;
- object_class->constructed = meta_cursor_renderer_constructed;
- klass->update_cursor = meta_cursor_renderer_real_update_cursor;
-
- obj_props[PROP_BACKEND] =
- g_param_spec_object ("backend",
- "backend",
- "MetaBackend",
- META_TYPE_BACKEND,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT_ONLY |
- G_PARAM_STATIC_STRINGS);
- obj_props[PROP_DEVICE] =
- g_param_spec_object ("device",
- "device",
- "Input device",
- CLUTTER_TYPE_INPUT_DEVICE,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT_ONLY |
- G_PARAM_STATIC_STRINGS);
- g_object_class_install_properties (object_class, N_PROPS, obj_props);
-
- signals[CURSOR_PAINTED] = g_signal_new ("cursor-painted",
- G_TYPE_FROM_CLASS (klass),
- G_SIGNAL_RUN_LAST,
- 0,
- NULL, NULL, NULL,
- G_TYPE_NONE, 2,
- G_TYPE_POINTER,
- CLUTTER_TYPE_STAGE_VIEW);
-}
-
-static void
-meta_cursor_renderer_init (MetaCursorRenderer *renderer)
-{
-}
-
-graphene_rect_t
-meta_cursor_renderer_calculate_rect (MetaCursorRenderer *renderer,
- MetaCursorSprite *cursor_sprite)
-{
- MetaCursorRendererPrivate *priv =
- meta_cursor_renderer_get_instance_private (renderer);
- CoglTexture *texture;
- int hot_x, hot_y;
- int width, height;
- float texture_scale;
-
- texture = meta_cursor_sprite_get_cogl_texture (cursor_sprite);
- if (!texture)
- return (graphene_rect_t) GRAPHENE_RECT_INIT_ZERO;
-
- meta_cursor_sprite_get_hotspot (cursor_sprite, &hot_x, &hot_y);
- texture_scale = meta_cursor_sprite_get_texture_scale (cursor_sprite);
- width = cogl_texture_get_width (texture);
- height = cogl_texture_get_height (texture);
-
- return (graphene_rect_t) {
- .origin = {
- .x = priv->current_x - (hot_x * texture_scale),
- .y = priv->current_y - (hot_y * texture_scale)
- },
- .size = {
- .width = width * texture_scale,
- .height = height * texture_scale
- }
- };
-}
-
-static float
-find_highest_logical_monitor_scale (MetaBackend *backend,
- MetaCursorSprite *cursor_sprite)
-{
- MetaMonitorManager *monitor_manager =
- meta_backend_get_monitor_manager (backend);
- MetaCursorRenderer *cursor_renderer =
- meta_backend_get_cursor_renderer (backend);
- graphene_rect_t cursor_rect;
- GList *logical_monitors;
- GList *l;
- float highest_scale = 0.0f;
-
- cursor_rect = meta_cursor_renderer_calculate_rect (cursor_renderer,
- cursor_sprite);
-
- logical_monitors =
- meta_monitor_manager_get_logical_monitors (monitor_manager);
- for (l = logical_monitors; l; l = l->next)
- {
- MetaLogicalMonitor *logical_monitor = l->data;
- graphene_rect_t logical_monitor_rect =
- meta_rectangle_to_graphene_rect (&logical_monitor->rect);
-
- if (!graphene_rect_intersection (&cursor_rect,
- &logical_monitor_rect,
- NULL))
- continue;
-
- highest_scale = MAX (highest_scale, logical_monitor->scale);
- }
-
- return highest_scale;
-}
-
-static void
-meta_cursor_renderer_update_cursor (MetaCursorRenderer *renderer,
- MetaCursorSprite *cursor_sprite)
-{
- MetaCursorRendererPrivate *priv = meta_cursor_renderer_get_instance_private (renderer);
- gboolean handled_by_backend;
-
- if (cursor_sprite)
- {
- float scale = find_highest_logical_monitor_scale (priv->backend,
- cursor_sprite);
- meta_cursor_sprite_prepare_at (cursor_sprite,
- MAX (1, scale),
- (int) priv->current_x,
- (int) priv->current_y);
- }
-
- handled_by_backend =
- META_CURSOR_RENDERER_GET_CLASS (renderer)->update_cursor (renderer,
- cursor_sprite);
- if (handled_by_backend != priv->handled_by_backend)
- priv->handled_by_backend = handled_by_backend;
-
- meta_cursor_renderer_update_stage_overlay (renderer, cursor_sprite);
-}
-
-MetaCursorRenderer *
-meta_cursor_renderer_new (MetaBackend *backend,
- ClutterInputDevice *device)
-{
- return g_object_new (META_TYPE_CURSOR_RENDERER,
- "backend", backend,
- "device", device,
- NULL);
-}
-
-void
-meta_cursor_renderer_set_cursor (MetaCursorRenderer *renderer,
- MetaCursorSprite *cursor_sprite)
-{
- MetaCursorRendererPrivate *priv = meta_cursor_renderer_get_instance_private (renderer);
-
- if (priv->displayed_cursor == cursor_sprite)
- return;
- g_set_object (&priv->displayed_cursor, cursor_sprite);
-
- meta_cursor_renderer_update_cursor (renderer, cursor_sprite);
-}
-
-void
-meta_cursor_renderer_force_update (MetaCursorRenderer *renderer)
-{
- MetaCursorRendererPrivate *priv =
- meta_cursor_renderer_get_instance_private (renderer);
-
- meta_cursor_renderer_update_cursor (renderer, priv->displayed_cursor);
-}
-
-void
-meta_cursor_renderer_update_position (MetaCursorRenderer *renderer)
-{
- MetaCursorRendererPrivate *priv = meta_cursor_renderer_get_instance_private (renderer);
- graphene_point_t pos;
-
- clutter_seat_query_state (clutter_input_device_get_seat (priv->device),
- priv->device, NULL, &pos, NULL);
- priv->current_x = pos.x;
- priv->current_y = pos.y;
-
- meta_cursor_renderer_update_cursor (renderer, priv->displayed_cursor);
-}
-
-MetaCursorSprite *
-meta_cursor_renderer_get_cursor (MetaCursorRenderer *renderer)
-{
- MetaCursorRendererPrivate *priv = meta_cursor_renderer_get_instance_private (renderer);
-
- return priv->overlay_cursor;
-}
-
-gboolean
-meta_cursor_renderer_is_overlay_visible (MetaCursorRenderer *renderer)
-{
- MetaCursorRendererPrivate *priv =
- meta_cursor_renderer_get_instance_private (renderer);
-
- if (!priv->stage_overlay)
- return FALSE;
-
- return meta_overlay_is_visible (priv->stage_overlay);
-}
-
-ClutterInputDevice *
-meta_cursor_renderer_get_input_device (MetaCursorRenderer *renderer)
-{
- MetaCursorRendererPrivate *priv =
- meta_cursor_renderer_get_instance_private (renderer);
-
- return priv->device;
-}
diff --git a/src/backends/meta-cursor-renderer.h b/src/backends/meta-cursor-renderer.h
deleted file mode 100644
index f6de01bfb..000000000
--- a/src/backends/meta-cursor-renderer.h
+++ /dev/null
@@ -1,82 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2014 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Written by:
- * Jasper St. Pierre <jstpierre@mecheye.net>
- */
-
-#ifndef META_CURSOR_RENDERER_H
-#define META_CURSOR_RENDERER_H
-
-#include <glib-object.h>
-
-#include "backends/meta-backend-types.h"
-#include "backends/meta-cursor.h"
-
-#define META_TYPE_HW_CURSOR_INHIBITOR (meta_hw_cursor_inhibitor_get_type ())
-G_DECLARE_INTERFACE (MetaHwCursorInhibitor, meta_hw_cursor_inhibitor,
- META, HW_CURSOR_INHIBITOR, GObject)
-
-struct _MetaHwCursorInhibitorInterface
-{
- GTypeInterface parent_iface;
-
- gboolean (* is_cursor_inhibited) (MetaHwCursorInhibitor *inhibitor);
-};
-
-gboolean meta_hw_cursor_inhibitor_is_cursor_inhibited (MetaHwCursorInhibitor *inhibitor);
-
-#define META_TYPE_CURSOR_RENDERER (meta_cursor_renderer_get_type ())
-G_DECLARE_DERIVABLE_TYPE (MetaCursorRenderer, meta_cursor_renderer,
- META, CURSOR_RENDERER, GObject);
-
-struct _MetaCursorRendererClass
-{
- GObjectClass parent_class;
-
- gboolean (* update_cursor) (MetaCursorRenderer *renderer,
- MetaCursorSprite *cursor_sprite);
-};
-
-MetaCursorRenderer * meta_cursor_renderer_new (MetaBackend *backend,
- ClutterInputDevice *device);
-
-void meta_cursor_renderer_set_cursor (MetaCursorRenderer *renderer,
- MetaCursorSprite *cursor_sprite);
-
-void meta_cursor_renderer_update_position (MetaCursorRenderer *renderer);
-void meta_cursor_renderer_force_update (MetaCursorRenderer *renderer);
-
-MetaCursorSprite * meta_cursor_renderer_get_cursor (MetaCursorRenderer *renderer);
-
-gboolean meta_cursor_renderer_is_overlay_visible (MetaCursorRenderer *renderer);
-
-graphene_rect_t meta_cursor_renderer_calculate_rect (MetaCursorRenderer *renderer,
- MetaCursorSprite *cursor_sprite);
-
-void meta_cursor_renderer_emit_painted (MetaCursorRenderer *renderer,
- MetaCursorSprite *cursor_sprite,
- ClutterStageView *stage_view);
-ClutterInputDevice * meta_cursor_renderer_get_input_device (MetaCursorRenderer *renderer);
-
-void meta_cursor_renderer_update_stage_overlay (MetaCursorRenderer *renderer,
- MetaCursorSprite *cursor_sprite);
-
-#endif /* META_CURSOR_RENDERER_H */
diff --git a/src/backends/meta-cursor-sprite-xcursor.c b/src/backends/meta-cursor-sprite-xcursor.c
deleted file mode 100644
index 5284f28ea..000000000
--- a/src/backends/meta-cursor-sprite-xcursor.c
+++ /dev/null
@@ -1,371 +0,0 @@
-/*
- * Copyright 2013, 2018 Red Hat, Inc.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-#include "config.h"
-
-#include "backends/meta-cursor-sprite-xcursor.h"
-
-#include "backends/meta-cursor.h"
-#include "backends/meta-cursor-renderer.h"
-#include "clutter/clutter.h"
-#include "cogl/cogl.h"
-#include "meta/prefs.h"
-#include "meta/util.h"
-
-struct _MetaCursorSpriteXcursor
-{
- MetaCursorSprite parent;
-
- MetaCursor cursor;
-
- int current_frame;
- XcursorImages *xcursor_images;
-
- int theme_scale;
- gboolean theme_dirty;
-};
-
-G_DEFINE_TYPE (MetaCursorSpriteXcursor, meta_cursor_sprite_xcursor,
- META_TYPE_CURSOR_SPRITE)
-
-static const char *
-translate_meta_cursor (MetaCursor cursor)
-{
- switch (cursor)
- {
- case META_CURSOR_DEFAULT:
- return "left_ptr";
- case META_CURSOR_NORTH_RESIZE:
- return "top_side";
- case META_CURSOR_SOUTH_RESIZE:
- return "bottom_side";
- case META_CURSOR_WEST_RESIZE:
- return "left_side";
- case META_CURSOR_EAST_RESIZE:
- return "right_side";
- case META_CURSOR_SE_RESIZE:
- return "bottom_right_corner";
- case META_CURSOR_SW_RESIZE:
- return "bottom_left_corner";
- case META_CURSOR_NE_RESIZE:
- return "top_right_corner";
- case META_CURSOR_NW_RESIZE:
- return "top_left_corner";
- case META_CURSOR_MOVE_OR_RESIZE_WINDOW:
- return "fleur";
- case META_CURSOR_BUSY:
- return "watch";
- case META_CURSOR_DND_IN_DRAG:
- return "dnd-none";
- case META_CURSOR_DND_MOVE:
- return "dnd-move";
- case META_CURSOR_DND_COPY:
- return "dnd-copy";
- case META_CURSOR_DND_UNSUPPORTED_TARGET:
- return "dnd-none";
- case META_CURSOR_POINTING_HAND:
- return "hand2";
- case META_CURSOR_CROSSHAIR:
- return "crosshair";
- case META_CURSOR_IBEAM:
- return "xterm";
- case META_CURSOR_BLANK:
- case META_CURSOR_NONE:
- case META_CURSOR_LAST:
- break;
- }
-
- g_assert_not_reached ();
- return NULL;
-}
-
-static Cursor
-create_blank_cursor (Display *xdisplay)
-{
- Pixmap pixmap;
- XColor color;
- Cursor cursor;
- XGCValues gc_values;
- GC gc;
-
- pixmap = XCreatePixmap (xdisplay, DefaultRootWindow (xdisplay), 1, 1, 1);
-
- gc_values.foreground = BlackPixel (xdisplay, DefaultScreen (xdisplay));
- gc = XCreateGC (xdisplay, pixmap, GCForeground, &gc_values);
-
- XFillRectangle (xdisplay, pixmap, gc, 0, 0, 1, 1);
-
- color.pixel = 0;
- color.red = color.blue = color.green = 0;
-
- cursor = XCreatePixmapCursor (xdisplay, pixmap, pixmap, &color, &color, 1, 1);
-
- XFreeGC (xdisplay, gc);
- XFreePixmap (xdisplay, pixmap);
-
- return cursor;
-}
-
-static XcursorImages *
-create_blank_cursor_images (void)
-{
- XcursorImages *images;
-
- images = XcursorImagesCreate (1);
- images->images[0] = XcursorImageCreate (1, 1);
-
- images->images[0]->xhot = 0;
- images->images[0]->yhot = 0;
- memset (images->images[0]->pixels, 0, sizeof(int32_t));
-
- return images;
-}
-
-MetaCursor
-meta_cursor_sprite_xcursor_get_cursor (MetaCursorSpriteXcursor *sprite_xcursor)
-{
- return sprite_xcursor->cursor;
-}
-
-Cursor
-meta_create_x_cursor (Display *xdisplay,
- MetaCursor cursor)
-{
- if (cursor == META_CURSOR_BLANK)
- return create_blank_cursor (xdisplay);
-
- return XcursorLibraryLoadCursor (xdisplay, translate_meta_cursor (cursor));
-}
-
-static XcursorImages *
-load_cursor_on_client (MetaCursor cursor, int scale)
-{
- XcursorImages *xcursor_images;
- int fallback_size;
-
- if (cursor == META_CURSOR_BLANK)
- return create_blank_cursor_images ();
-
- xcursor_images =
- XcursorLibraryLoadImages (translate_meta_cursor (cursor),
- meta_prefs_get_cursor_theme (),
- meta_prefs_get_cursor_size () * scale);
- if (xcursor_images)
- return xcursor_images;
-
- g_warning_once ("No cursor theme available, please install a cursor theme");
-
- fallback_size = 24 * scale;
- xcursor_images = XcursorImagesCreate (1);
- xcursor_images->images[0] = XcursorImageCreate (fallback_size, fallback_size);
- xcursor_images->images[0]->xhot = 0;
- xcursor_images->images[0]->yhot = 0;
- memset (xcursor_images->images[0]->pixels, 0xc0,
- fallback_size * fallback_size * sizeof (int32_t));
- return xcursor_images;
-}
-
-static void
-load_from_current_xcursor_image (MetaCursorSpriteXcursor *sprite_xcursor)
-{
- MetaCursorSprite *sprite = META_CURSOR_SPRITE (sprite_xcursor);
- XcursorImage *xc_image;
- int width, height, rowstride;
- CoglPixelFormat cogl_format;
- ClutterBackend *clutter_backend;
- CoglContext *cogl_context;
- CoglTexture2D *texture;
- GError *error = NULL;
- int hotspot_x, hotspot_y;
-
- g_assert (!meta_cursor_sprite_get_cogl_texture (sprite));
-
- xc_image = meta_cursor_sprite_xcursor_get_current_image (sprite_xcursor);
- width = (int) xc_image->width;
- height = (int) xc_image->height;
- rowstride = width * 4;
-
-#if G_BYTE_ORDER == G_LITTLE_ENDIAN
- cogl_format = COGL_PIXEL_FORMAT_BGRA_8888;
-#else
- cogl_format = COGL_PIXEL_FORMAT_ARGB_8888;
-#endif
-
- clutter_backend = clutter_get_default_backend ();
- cogl_context = clutter_backend_get_cogl_context (clutter_backend);
- texture = cogl_texture_2d_new_from_data (cogl_context,
- width, height,
- cogl_format,
- rowstride,
- (uint8_t *) xc_image->pixels,
- &error);
- if (!texture)
- {
- g_warning ("Failed to allocate cursor texture: %s", error->message);
- g_error_free (error);
- }
-
- if (meta_is_wayland_compositor ())
- {
- hotspot_x = ((int) (xc_image->xhot / sprite_xcursor->theme_scale) *
- sprite_xcursor->theme_scale);
- hotspot_y = ((int) (xc_image->yhot / sprite_xcursor->theme_scale) *
- sprite_xcursor->theme_scale);
- }
- else
- {
- hotspot_x = xc_image->xhot;
- hotspot_y = xc_image->yhot;
- }
- meta_cursor_sprite_set_texture (sprite,
- COGL_TEXTURE (texture),
- hotspot_x, hotspot_y);
-
- g_clear_pointer (&texture, cogl_object_unref);
-}
-
-void
-meta_cursor_sprite_xcursor_set_theme_scale (MetaCursorSpriteXcursor *sprite_xcursor,
- int theme_scale)
-{
- if (sprite_xcursor->theme_scale != theme_scale)
- sprite_xcursor->theme_dirty = TRUE;
- sprite_xcursor->theme_scale = theme_scale;
-}
-
-static gboolean
-meta_cursor_sprite_xcursor_is_animated (MetaCursorSprite *sprite)
-{
- MetaCursorSpriteXcursor *sprite_xcursor = META_CURSOR_SPRITE_XCURSOR (sprite);
-
- return (sprite_xcursor->xcursor_images &&
- sprite_xcursor->xcursor_images->nimage > 1);
-}
-
-XcursorImage *
-meta_cursor_sprite_xcursor_get_current_image (MetaCursorSpriteXcursor *sprite_xcursor)
-{
- return sprite_xcursor->xcursor_images->images[sprite_xcursor->current_frame];
-}
-
-static void
-meta_cursor_sprite_xcursor_tick_frame (MetaCursorSprite *sprite)
-{
- MetaCursorSpriteXcursor *sprite_xcursor = META_CURSOR_SPRITE_XCURSOR (sprite);
-
- if (!meta_cursor_sprite_is_animated (sprite))
- return;
-
- sprite_xcursor->current_frame++;
-
- if (sprite_xcursor->current_frame >= sprite_xcursor->xcursor_images->nimage)
- sprite_xcursor->current_frame = 0;
-
- meta_cursor_sprite_clear_texture (sprite);
- load_from_current_xcursor_image (sprite_xcursor);
-}
-
-static unsigned int
-meta_cursor_sprite_xcursor_get_current_frame_time (MetaCursorSprite *sprite)
-{
- MetaCursorSpriteXcursor *sprite_xcursor = META_CURSOR_SPRITE_XCURSOR (sprite);
- XcursorImages *xcursor_images;
-
- g_return_val_if_fail (meta_cursor_sprite_is_animated (sprite), 0);
-
- xcursor_images = sprite_xcursor->xcursor_images;
- return xcursor_images->images[sprite_xcursor->current_frame]->delay;
-}
-
-static void
-load_cursor_from_theme (MetaCursorSprite *sprite)
-{
- MetaCursorSpriteXcursor *sprite_xcursor = META_CURSOR_SPRITE_XCURSOR (sprite);
-
- g_assert (sprite_xcursor->cursor != META_CURSOR_NONE);
-
- sprite_xcursor->theme_dirty = FALSE;
-
- /* We might be reloading with a different scale. If so clear the old data. */
- if (sprite_xcursor->xcursor_images)
- {
- meta_cursor_sprite_clear_texture (sprite);
- XcursorImagesDestroy (sprite_xcursor->xcursor_images);
- }
-
- sprite_xcursor->current_frame = 0;
- sprite_xcursor->xcursor_images =
- load_cursor_on_client (sprite_xcursor->cursor,
- sprite_xcursor->theme_scale);
-
- load_from_current_xcursor_image (sprite_xcursor);
-}
-
-static void
-meta_cursor_sprite_xcursor_realize_texture (MetaCursorSprite *sprite)
-{
- MetaCursorSpriteXcursor *sprite_xcursor = META_CURSOR_SPRITE_XCURSOR (sprite);
-
- if (sprite_xcursor->theme_dirty)
- load_cursor_from_theme (sprite);
-}
-
-MetaCursorSpriteXcursor *
-meta_cursor_sprite_xcursor_new (MetaCursor cursor)
-{
- MetaCursorSpriteXcursor *sprite_xcursor;
-
- sprite_xcursor = g_object_new (META_TYPE_CURSOR_SPRITE_XCURSOR, NULL);
- sprite_xcursor->cursor = cursor;
-
- return sprite_xcursor;
-}
-
-static void
-meta_cursor_sprite_xcursor_finalize (GObject *object)
-{
- MetaCursorSpriteXcursor *sprite_xcursor = META_CURSOR_SPRITE_XCURSOR (object);
-
- g_clear_pointer (&sprite_xcursor->xcursor_images,
- XcursorImagesDestroy);
-
- G_OBJECT_CLASS (meta_cursor_sprite_xcursor_parent_class)->finalize (object);
-}
-
-static void
-meta_cursor_sprite_xcursor_init (MetaCursorSpriteXcursor *sprite_xcursor)
-{
- sprite_xcursor->theme_scale = 1;
- sprite_xcursor->theme_dirty = TRUE;
-}
-
-static void
-meta_cursor_sprite_xcursor_class_init (MetaCursorSpriteXcursorClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
- MetaCursorSpriteClass *cursor_sprite_class = META_CURSOR_SPRITE_CLASS (klass);
-
- object_class->finalize = meta_cursor_sprite_xcursor_finalize;
-
- cursor_sprite_class->realize_texture =
- meta_cursor_sprite_xcursor_realize_texture;
- cursor_sprite_class->is_animated = meta_cursor_sprite_xcursor_is_animated;
- cursor_sprite_class->tick_frame = meta_cursor_sprite_xcursor_tick_frame;
- cursor_sprite_class->get_current_frame_time =
- meta_cursor_sprite_xcursor_get_current_frame_time;
-}
diff --git a/src/backends/meta-cursor-sprite-xcursor.h b/src/backends/meta-cursor-sprite-xcursor.h
deleted file mode 100644
index dbc927484..000000000
--- a/src/backends/meta-cursor-sprite-xcursor.h
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright 2013, 2018 Red Hat, Inc.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-#ifndef META_CURSOR_SPRITE_XCURSOR_H
-#define META_CURSOR_SPRITE_XCURSOR_H
-
-#include <glib-object.h>
-#include <X11/Xcursor/Xcursor.h>
-
-#include "backends/meta-cursor.h"
-
-#define META_TYPE_CURSOR_SPRITE_XCURSOR meta_cursor_sprite_xcursor_get_type ()
-G_DECLARE_FINAL_TYPE (MetaCursorSpriteXcursor, meta_cursor_sprite_xcursor,
- META, CURSOR_SPRITE_XCURSOR, MetaCursorSprite)
-
-MetaCursorSpriteXcursor * meta_cursor_sprite_xcursor_new (MetaCursor cursor);
-
-void meta_cursor_sprite_xcursor_set_theme_scale (MetaCursorSpriteXcursor *sprite_xcursor,
- int scale);
-
-MetaCursor meta_cursor_sprite_xcursor_get_cursor (MetaCursorSpriteXcursor *sprite_xcusror);
-
-XcursorImage * meta_cursor_sprite_xcursor_get_current_image (MetaCursorSpriteXcursor *sprite_xcursor);
-
-Cursor meta_create_x_cursor (Display *xdisplay,
- MetaCursor cursor);
-
-#endif /* META_CURSOR_SPRITE_XCURSOR_H */
diff --git a/src/backends/meta-cursor-tracker-private.h b/src/backends/meta-cursor-tracker-private.h
deleted file mode 100644
index 2d8d38042..000000000
--- a/src/backends/meta-cursor-tracker-private.h
+++ /dev/null
@@ -1,56 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright 2013 Red Hat, Inc.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, see <http://www.gnu.org/licenses/>.
- *
- * Author: Giovanni Campagna <gcampagn@redhat.com>
- */
-
-#ifndef META_CURSOR_TRACKER_PRIVATE_H
-#define META_CURSOR_TRACKER_PRIVATE_H
-
-#include "backends/meta-cursor.h"
-#include "backends/meta-cursor-renderer.h"
-#include "meta/meta-cursor-tracker.h"
-
-struct _MetaCursorTrackerClass
-{
- GObjectClass parent_class;
-
- void (* set_force_track_position) (MetaCursorTracker *tracker,
- gboolean is_enabled);
- MetaCursorSprite * (* get_sprite) (MetaCursorTracker *tracker);
-};
-
-void meta_cursor_tracker_set_window_cursor (MetaCursorTracker *tracker,
- MetaCursorSprite *cursor_sprite);
-void meta_cursor_tracker_unset_window_cursor (MetaCursorTracker *tracker);
-void meta_cursor_tracker_set_root_cursor (MetaCursorTracker *tracker,
- MetaCursorSprite *cursor_sprite);
-
-void meta_cursor_tracker_invalidate_position (MetaCursorTracker *tracker);
-
-void meta_cursor_tracker_track_position (MetaCursorTracker *tracker);
-
-void meta_cursor_tracker_untrack_position (MetaCursorTracker *tracker);
-
-MetaBackend * meta_cursor_tracker_get_backend (MetaCursorTracker *tracker);
-
-void meta_cursor_tracker_notify_cursor_changed (MetaCursorTracker *tracker);
-
-void meta_cursor_tracker_destroy (MetaCursorTracker *tracker);
-
-#endif
diff --git a/src/backends/meta-cursor-tracker.c b/src/backends/meta-cursor-tracker.c
deleted file mode 100644
index 24776e266..000000000
--- a/src/backends/meta-cursor-tracker.c
+++ /dev/null
@@ -1,514 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright 2013 Red Hat, Inc.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, see <http://www.gnu.org/licenses/>.
- *
- * Author: Giovanni Campagna <gcampagn@redhat.com>
- */
-
-/**
- * SECTION:cursor-tracker
- * @title: MetaCursorTracker
- * @short_description: Mutter cursor tracking helper. Originally only
- * tracking the cursor image, now more of a "core
- * pointer abstraction"
- */
-
-#include "config.h"
-
-#include "backends/meta-cursor-tracker-private.h"
-
-#include <string.h>
-
-#include "backends/meta-backend-private.h"
-#include "cogl/cogl.h"
-#include "core/display-private.h"
-#include "clutter/clutter.h"
-#include "meta/main.h"
-#include "meta/util.h"
-
-enum
-{
- PROP_0,
-
- PROP_BACKEND,
-
- N_PROPS
-};
-
-static GParamSpec *obj_props[N_PROPS];
-
-typedef struct _MetaCursorTrackerPrivate
-{
- MetaBackend *backend;
-
- gboolean is_showing;
-
- int track_position_count;
-
- float x;
- float y;
-
- MetaCursorSprite *effective_cursor; /* May be NULL when hidden */
- MetaCursorSprite *displayed_cursor;
-
- /* Wayland clients can set a NULL buffer as their cursor
- * explicitly, which means that we shouldn't display anything.
- * So, we can't simply store a NULL in window_cursor to
- * determine an unset window cursor; we need an extra boolean.
- */
- gboolean has_window_cursor;
- MetaCursorSprite *window_cursor;
-
- MetaCursorSprite *root_cursor;
-} MetaCursorTrackerPrivate;
-
-G_DEFINE_TYPE_WITH_PRIVATE (MetaCursorTracker, meta_cursor_tracker,
- G_TYPE_OBJECT)
-
-enum
-{
- CURSOR_CHANGED,
- POSITION_INVALIDATED,
- VISIBILITY_CHANGED,
- LAST_SIGNAL
-};
-
-static guint signals[LAST_SIGNAL];
-
-void
-meta_cursor_tracker_notify_cursor_changed (MetaCursorTracker *tracker)
-{
- g_signal_emit (tracker, signals[CURSOR_CHANGED], 0);
-}
-
-static void
-cursor_texture_updated (MetaCursorSprite *cursor,
- MetaCursorTracker *tracker)
-{
- g_signal_emit (tracker, signals[CURSOR_CHANGED], 0);
-}
-
-static gboolean
-update_displayed_cursor (MetaCursorTracker *tracker)
-{
- MetaCursorTrackerPrivate *priv =
- meta_cursor_tracker_get_instance_private (tracker);
- MetaDisplay *display = meta_get_display ();
- MetaCursorSprite *cursor = NULL;
-
- if (display && meta_display_windows_are_interactable (display) &&
- priv->has_window_cursor)
- cursor = priv->window_cursor;
- else
- cursor = priv->root_cursor;
-
- if (priv->displayed_cursor == cursor)
- return FALSE;
-
- if (priv->displayed_cursor)
- {
- g_signal_handlers_disconnect_by_func (priv->displayed_cursor,
- cursor_texture_updated,
- tracker);
- }
-
- g_set_object (&priv->displayed_cursor, cursor);
-
- if (cursor)
- {
- g_signal_connect (cursor, "texture-changed",
- G_CALLBACK (cursor_texture_updated), tracker);
- }
-
- return TRUE;
-}
-
-static gboolean
-update_effective_cursor (MetaCursorTracker *tracker)
-{
- MetaCursorTrackerPrivate *priv =
- meta_cursor_tracker_get_instance_private (tracker);
- MetaCursorSprite *cursor = NULL;
-
- if (priv->is_showing)
- cursor = priv->displayed_cursor;
-
- return g_set_object (&priv->effective_cursor, cursor);
-}
-
-static void
-change_cursor_renderer (MetaCursorTracker *tracker)
-{
- MetaCursorTrackerPrivate *priv =
- meta_cursor_tracker_get_instance_private (tracker);
- MetaCursorRenderer *cursor_renderer =
- meta_backend_get_cursor_renderer (priv->backend);
-
- meta_cursor_renderer_set_cursor (cursor_renderer, priv->effective_cursor);
-}
-
-static void
-sync_cursor (MetaCursorTracker *tracker)
-{
- gboolean cursor_changed = FALSE;
-
- cursor_changed = update_displayed_cursor (tracker);
-
- if (update_effective_cursor (tracker))
- change_cursor_renderer (tracker);
-
- if (cursor_changed)
- g_signal_emit (tracker, signals[CURSOR_CHANGED], 0);
-}
-
-static void
-meta_cursor_tracker_real_set_force_track_position (MetaCursorTracker *tracker,
- gboolean is_enabled)
-{
-}
-
-static MetaCursorSprite *
-meta_cursor_tracker_real_get_sprite (MetaCursorTracker *tracker)
-{
- MetaCursorTrackerPrivate *priv =
- meta_cursor_tracker_get_instance_private (tracker);
-
- return priv->displayed_cursor;
-}
-
-void
-meta_cursor_tracker_destroy (MetaCursorTracker *tracker)
-{
- g_object_run_dispose (G_OBJECT (tracker));
- g_object_unref (tracker);
-}
-
-static void
-meta_cursor_tracker_init (MetaCursorTracker *tracker)
-{
- MetaCursorTrackerPrivate *priv =
- meta_cursor_tracker_get_instance_private (tracker);
-
- priv->is_showing = FALSE;
- priv->x = -1.0;
- priv->y = -1.0;
-}
-
-static void
-meta_cursor_tracker_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- MetaCursorTracker *tracker = META_CURSOR_TRACKER (object);
- MetaCursorTrackerPrivate *priv =
- meta_cursor_tracker_get_instance_private (tracker);
-
- switch (prop_id)
- {
- case PROP_BACKEND:
- g_value_set_object (value, priv->backend);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-
-static void
-meta_cursor_tracker_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- MetaCursorTracker *tracker = META_CURSOR_TRACKER (object);
- MetaCursorTrackerPrivate *priv =
- meta_cursor_tracker_get_instance_private (tracker);
-
- switch (prop_id)
- {
- case PROP_BACKEND:
- priv->backend = g_value_get_object (value);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-
-static void
-meta_cursor_tracker_dispose (GObject *object)
-{
- MetaCursorTracker *tracker = META_CURSOR_TRACKER (object);
- MetaCursorTrackerPrivate *priv =
- meta_cursor_tracker_get_instance_private (tracker);
-
- g_clear_object (&priv->effective_cursor);
- g_clear_object (&priv->displayed_cursor);
- g_clear_object (&priv->root_cursor);
-
- G_OBJECT_CLASS (meta_cursor_tracker_parent_class)->dispose (object);
-}
-
-static void
-meta_cursor_tracker_class_init (MetaCursorTrackerClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- object_class->get_property = meta_cursor_tracker_get_property;
- object_class->set_property = meta_cursor_tracker_set_property;
- object_class->dispose = meta_cursor_tracker_dispose;
-
- klass->set_force_track_position =
- meta_cursor_tracker_real_set_force_track_position;
- klass->get_sprite =
- meta_cursor_tracker_real_get_sprite;
-
- obj_props[PROP_BACKEND] =
- g_param_spec_object ("backend",
- "backend",
- "MetaBackend",
- META_TYPE_BACKEND,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT_ONLY |
- G_PARAM_STATIC_STRINGS);
- g_object_class_install_properties (object_class, N_PROPS, obj_props);
-
- signals[CURSOR_CHANGED] = g_signal_new ("cursor-changed",
- G_TYPE_FROM_CLASS (klass),
- G_SIGNAL_RUN_LAST,
- 0,
- NULL, NULL, NULL,
- G_TYPE_NONE, 0);
-
- signals[POSITION_INVALIDATED] = g_signal_new ("position-invalidated",
- G_TYPE_FROM_CLASS (klass),
- G_SIGNAL_RUN_LAST,
- 0,
- NULL, NULL, NULL,
- G_TYPE_NONE, 0);
-
- signals[VISIBILITY_CHANGED] = g_signal_new ("visibility-changed",
- G_TYPE_FROM_CLASS (klass),
- G_SIGNAL_RUN_LAST,
- 0, NULL, NULL, NULL,
- G_TYPE_NONE, 0);
-}
-
-/**
- * meta_cursor_tracker_get_for_display:
- * @display: the #MetaDisplay
- *
- * Retrieves the cursor tracker object for @display.
- *
- * Returns: (transfer none):
- */
-MetaCursorTracker *
-meta_cursor_tracker_get_for_display (MetaDisplay *display)
-{
- MetaBackend *backend = meta_get_backend ();
- MetaCursorTracker *tracker = meta_backend_get_cursor_tracker (backend);
-
- g_assert (tracker);
-
- return tracker;
-}
-
-static void
-set_window_cursor (MetaCursorTracker *tracker,
- gboolean has_cursor,
- MetaCursorSprite *cursor_sprite)
-{
- MetaCursorTrackerPrivate *priv =
- meta_cursor_tracker_get_instance_private (tracker);
-
- g_clear_object (&priv->window_cursor);
- if (cursor_sprite)
- priv->window_cursor = g_object_ref (cursor_sprite);
- priv->has_window_cursor = has_cursor;
- sync_cursor (tracker);
-}
-
-/**
- * meta_cursor_tracker_get_sprite:
- *
- * Returns: (transfer none):
- */
-CoglTexture *
-meta_cursor_tracker_get_sprite (MetaCursorTracker *tracker)
-{
- MetaCursorSprite *cursor_sprite;
-
- cursor_sprite = META_CURSOR_TRACKER_GET_CLASS (tracker)->get_sprite (tracker);
-
- if (!cursor_sprite)
- return NULL;
-
- meta_cursor_sprite_realize_texture (cursor_sprite);
- return meta_cursor_sprite_get_cogl_texture (cursor_sprite);
-}
-
-/**
- * meta_cursor_tracker_get_hot:
- * @tracker:
- * @x: (out):
- * @y: (out):
- *
- */
-void
-meta_cursor_tracker_get_hot (MetaCursorTracker *tracker,
- int *x,
- int *y)
-{
- MetaCursorSprite *cursor_sprite;
-
- g_return_if_fail (META_IS_CURSOR_TRACKER (tracker));
-
- cursor_sprite = META_CURSOR_TRACKER_GET_CLASS (tracker)->get_sprite (tracker);
-
- if (cursor_sprite)
- meta_cursor_sprite_get_hotspot (cursor_sprite, x, y);
- else
- {
- if (x)
- *x = 0;
- if (y)
- *y = 0;
- }
-}
-
-void
-meta_cursor_tracker_set_window_cursor (MetaCursorTracker *tracker,
- MetaCursorSprite *cursor_sprite)
-{
- set_window_cursor (tracker, TRUE, cursor_sprite);
-}
-
-void
-meta_cursor_tracker_unset_window_cursor (MetaCursorTracker *tracker)
-{
- set_window_cursor (tracker, FALSE, NULL);
-}
-
-/**
- * meta_cursor_tracker_set_root_cursor:
- * @tracker: a #MetaCursorTracker object.
- * @cursor_sprite: (transfer none): the new root cursor
- *
- * Sets the root cursor (the cursor that is shown if not modified by a window).
- * The #MetaCursorTracker will take a strong reference to the sprite.
- */
-void
-meta_cursor_tracker_set_root_cursor (MetaCursorTracker *tracker,
- MetaCursorSprite *cursor_sprite)
-{
- MetaCursorTrackerPrivate *priv =
- meta_cursor_tracker_get_instance_private (tracker);
-
- g_clear_object (&priv->root_cursor);
- if (cursor_sprite)
- priv->root_cursor = g_object_ref (cursor_sprite);
-
- sync_cursor (tracker);
-}
-
-void
-meta_cursor_tracker_invalidate_position (MetaCursorTracker *tracker)
-{
- g_signal_emit (tracker, signals[POSITION_INVALIDATED], 0);
-}
-
-void
-meta_cursor_tracker_get_pointer (MetaCursorTracker *tracker,
- graphene_point_t *coords,
- ClutterModifierType *mods)
-{
- ClutterSeat *seat;
- ClutterInputDevice *cdevice;
-
- seat = clutter_backend_get_default_seat (clutter_get_default_backend ());
- cdevice = clutter_seat_get_pointer (seat);
-
- clutter_seat_query_state (seat, cdevice, NULL, coords, mods);
-}
-
-void
-meta_cursor_tracker_track_position (MetaCursorTracker *tracker)
-{
- MetaCursorTrackerPrivate *priv =
- meta_cursor_tracker_get_instance_private (tracker);
-
- priv->track_position_count++;
- if (priv->track_position_count == 1)
- {
- MetaCursorTrackerClass *klass =
- META_CURSOR_TRACKER_GET_CLASS (tracker);
-
- klass->set_force_track_position (tracker, TRUE);
- }
-}
-
-void
-meta_cursor_tracker_untrack_position (MetaCursorTracker *tracker)
-{
- MetaCursorTrackerPrivate *priv =
- meta_cursor_tracker_get_instance_private (tracker);
-
- g_return_if_fail (priv->track_position_count > 0);
-
- priv->track_position_count--;
- if (priv->track_position_count == 0)
- {
- MetaCursorTrackerClass *klass =
- META_CURSOR_TRACKER_GET_CLASS (tracker);
-
- klass->set_force_track_position (tracker, FALSE);
- }
-}
-
-gboolean
-meta_cursor_tracker_get_pointer_visible (MetaCursorTracker *tracker)
-{
- MetaCursorTrackerPrivate *priv =
- meta_cursor_tracker_get_instance_private (tracker);
-
- return priv->is_showing;
-}
-
-void
-meta_cursor_tracker_set_pointer_visible (MetaCursorTracker *tracker,
- gboolean visible)
-{
- MetaCursorTrackerPrivate *priv =
- meta_cursor_tracker_get_instance_private (tracker);
-
- if (visible == priv->is_showing)
- return;
- priv->is_showing = visible;
-
- sync_cursor (tracker);
-
- g_signal_emit (tracker, signals[VISIBILITY_CHANGED], 0);
-}
-MetaBackend *
-meta_cursor_tracker_get_backend (MetaCursorTracker *tracker)
-{
- MetaCursorTrackerPrivate *priv =
- meta_cursor_tracker_get_instance_private (tracker);
-
- return priv->backend;
-}
diff --git a/src/backends/meta-cursor.c b/src/backends/meta-cursor.c
deleted file mode 100644
index d0fb2ba68..000000000
--- a/src/backends/meta-cursor.c
+++ /dev/null
@@ -1,240 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright 2013 Red Hat, Inc.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, see <http://www.gnu.org/licenses/>.
- *
- * Author: Giovanni Campagna <gcampagn@redhat.com>
- */
-
-#include "config.h"
-
-#include "backends/meta-cursor.h"
-
-#include "backends/meta-backend-private.h"
-#include "cogl/cogl.h"
-#include "meta/common.h"
-
-enum
-{
- PREPARE_AT,
- TEXTURE_CHANGED,
-
- LAST_SIGNAL
-};
-
-static guint signals[LAST_SIGNAL];
-
-typedef struct _MetaCursorSpritePrivate
-{
- GObject parent;
-
- CoglTexture2D *texture;
- float texture_scale;
- MetaMonitorTransform texture_transform;
- int hot_x, hot_y;
-} MetaCursorSpritePrivate;
-
-G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (MetaCursorSprite,
- meta_cursor_sprite,
- G_TYPE_OBJECT)
-
-gboolean
-meta_cursor_sprite_is_animated (MetaCursorSprite *sprite)
-{
- MetaCursorSpriteClass *klass = META_CURSOR_SPRITE_GET_CLASS (sprite);
-
- if (klass->is_animated)
- return klass->is_animated (sprite);
- else
- return FALSE;
-}
-
-void
-meta_cursor_sprite_tick_frame (MetaCursorSprite *sprite)
-{
- return META_CURSOR_SPRITE_GET_CLASS (sprite)->tick_frame (sprite);
-}
-
-unsigned int
-meta_cursor_sprite_get_current_frame_time (MetaCursorSprite *sprite)
-{
- return META_CURSOR_SPRITE_GET_CLASS (sprite)->get_current_frame_time (sprite);
-}
-
-void
-meta_cursor_sprite_clear_texture (MetaCursorSprite *sprite)
-{
- MetaCursorSpritePrivate *priv =
- meta_cursor_sprite_get_instance_private (sprite);
-
- g_clear_pointer (&priv->texture, cogl_object_unref);
-}
-
-void
-meta_cursor_sprite_set_texture (MetaCursorSprite *sprite,
- CoglTexture *texture,
- int hot_x,
- int hot_y)
-{
- MetaCursorSpritePrivate *priv =
- meta_cursor_sprite_get_instance_private (sprite);
-
- g_clear_pointer (&priv->texture, cogl_object_unref);
- if (texture)
- priv->texture = cogl_object_ref (texture);
- priv->hot_x = hot_x;
- priv->hot_y = hot_y;
-
- g_signal_emit (sprite, signals[TEXTURE_CHANGED], 0);
-}
-
-void
-meta_cursor_sprite_set_texture_scale (MetaCursorSprite *sprite,
- float scale)
-{
- MetaCursorSpritePrivate *priv =
- meta_cursor_sprite_get_instance_private (sprite);
-
- priv->texture_scale = scale;
-}
-
-void
-meta_cursor_sprite_set_texture_transform (MetaCursorSprite *sprite,
- MetaMonitorTransform transform)
-{
- MetaCursorSpritePrivate *priv =
- meta_cursor_sprite_get_instance_private (sprite);
-
- priv->texture_transform = transform;
-}
-
-CoglTexture *
-meta_cursor_sprite_get_cogl_texture (MetaCursorSprite *sprite)
-{
- MetaCursorSpritePrivate *priv =
- meta_cursor_sprite_get_instance_private (sprite);
-
- return COGL_TEXTURE (priv->texture);
-}
-
-void
-meta_cursor_sprite_get_hotspot (MetaCursorSprite *sprite,
- int *hot_x,
- int *hot_y)
-{
- MetaCursorSpritePrivate *priv =
- meta_cursor_sprite_get_instance_private (sprite);
-
- *hot_x = priv->hot_x;
- *hot_y = priv->hot_y;
-}
-
-int
-meta_cursor_sprite_get_width (MetaCursorSprite *sprite)
-{
- CoglTexture *texture;
-
- texture = meta_cursor_sprite_get_cogl_texture (sprite);
- return cogl_texture_get_width (texture);
-}
-
-int
-meta_cursor_sprite_get_height (MetaCursorSprite *sprite)
-{
- CoglTexture *texture;
-
- texture = meta_cursor_sprite_get_cogl_texture (sprite);
- return cogl_texture_get_height (texture);
-}
-
-float
-meta_cursor_sprite_get_texture_scale (MetaCursorSprite *sprite)
-{
- MetaCursorSpritePrivate *priv =
- meta_cursor_sprite_get_instance_private (sprite);
-
- return priv->texture_scale;
-}
-
-MetaMonitorTransform
-meta_cursor_sprite_get_texture_transform (MetaCursorSprite *sprite)
-{
- MetaCursorSpritePrivate *priv =
- meta_cursor_sprite_get_instance_private (sprite);
-
- return priv->texture_transform;
-}
-
-void
-meta_cursor_sprite_prepare_at (MetaCursorSprite *sprite,
- float best_scale,
- int x,
- int y)
-{
- g_signal_emit (sprite, signals[PREPARE_AT], 0, best_scale, x, y);
-}
-
-void
-meta_cursor_sprite_realize_texture (MetaCursorSprite *sprite)
-{
- META_CURSOR_SPRITE_GET_CLASS (sprite)->realize_texture (sprite);
-}
-
-static void
-meta_cursor_sprite_init (MetaCursorSprite *sprite)
-{
- MetaCursorSpritePrivate *priv =
- meta_cursor_sprite_get_instance_private (sprite);
-
- priv->texture_scale = 1.0f;
- priv->texture_transform = META_MONITOR_TRANSFORM_NORMAL;
-}
-
-static void
-meta_cursor_sprite_finalize (GObject *object)
-{
- MetaCursorSprite *sprite = META_CURSOR_SPRITE (object);
- MetaCursorSpritePrivate *priv =
- meta_cursor_sprite_get_instance_private (sprite);
-
- g_clear_pointer (&priv->texture, cogl_object_unref);
-
- G_OBJECT_CLASS (meta_cursor_sprite_parent_class)->finalize (object);
-}
-
-static void
-meta_cursor_sprite_class_init (MetaCursorSpriteClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- object_class->finalize = meta_cursor_sprite_finalize;
-
- signals[PREPARE_AT] = g_signal_new ("prepare-at",
- G_TYPE_FROM_CLASS (object_class),
- G_SIGNAL_RUN_LAST,
- 0,
- NULL, NULL, NULL,
- G_TYPE_NONE, 3,
- G_TYPE_FLOAT,
- G_TYPE_INT,
- G_TYPE_INT);
- signals[TEXTURE_CHANGED] = g_signal_new ("texture-changed",
- G_TYPE_FROM_CLASS (object_class),
- G_SIGNAL_RUN_LAST,
- 0,
- NULL, NULL, NULL,
- G_TYPE_NONE, 0);
-}
diff --git a/src/backends/meta-cursor.h b/src/backends/meta-cursor.h
deleted file mode 100644
index a65e128c4..000000000
--- a/src/backends/meta-cursor.h
+++ /dev/null
@@ -1,85 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright 2013 Red Hat, Inc.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, see <http://www.gnu.org/licenses/>.
- *
- * Author: Giovanni Campagna <gcampagn@redhat.com>
- */
-
-#ifndef META_CURSOR_H
-#define META_CURSOR_H
-
-#include "backends/meta-backend-types.h"
-#include "meta/common.h"
-#include "meta/boxes.h"
-
-#define META_TYPE_CURSOR_SPRITE (meta_cursor_sprite_get_type ())
-G_DECLARE_DERIVABLE_TYPE (MetaCursorSprite,
- meta_cursor_sprite,
- META, CURSOR_SPRITE,
- GObject)
-
-struct _MetaCursorSpriteClass
-{
- GObjectClass parent_class;
-
- void (* realize_texture) (MetaCursorSprite *sprite);
- gboolean (* is_animated) (MetaCursorSprite *sprite);
- void (* tick_frame) (MetaCursorSprite *sprite);
- unsigned int (* get_current_frame_time) (MetaCursorSprite *sprite);
-};
-
-void meta_cursor_sprite_prepare_at (MetaCursorSprite *sprite,
- float best_scale,
- int x,
- int y);
-
-void meta_cursor_sprite_realize_texture (MetaCursorSprite *sprite);
-
-void meta_cursor_sprite_clear_texture (MetaCursorSprite *sprite);
-
-void meta_cursor_sprite_set_texture (MetaCursorSprite *sprite,
- CoglTexture *texture,
- int hot_x,
- int hot_y);
-
-void meta_cursor_sprite_set_texture_scale (MetaCursorSprite *sprite,
- float scale);
-
-void meta_cursor_sprite_set_texture_transform (MetaCursorSprite *sprite,
- MetaMonitorTransform transform);
-
-CoglTexture *meta_cursor_sprite_get_cogl_texture (MetaCursorSprite *sprite);
-
-void meta_cursor_sprite_get_hotspot (MetaCursorSprite *sprite,
- int *hot_x,
- int *hot_y);
-
-int meta_cursor_sprite_get_width (MetaCursorSprite *sprite);
-
-int meta_cursor_sprite_get_height (MetaCursorSprite *sprite);
-
-float meta_cursor_sprite_get_texture_scale (MetaCursorSprite *sprite);
-
-MetaMonitorTransform meta_cursor_sprite_get_texture_transform (MetaCursorSprite *sprite);
-
-gboolean meta_cursor_sprite_is_animated (MetaCursorSprite *sprite);
-
-void meta_cursor_sprite_tick_frame (MetaCursorSprite *sprite);
-
-unsigned int meta_cursor_sprite_get_current_frame_time (MetaCursorSprite *sprite);
-
-#endif /* META_CURSOR_H */
diff --git a/src/backends/meta-dbus-session-watcher.c b/src/backends/meta-dbus-session-watcher.c
deleted file mode 100644
index a885b423b..000000000
--- a/src/backends/meta-dbus-session-watcher.c
+++ /dev/null
@@ -1,237 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2015-2017 Red Hat Inc.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- */
-
-#include "config.h"
-
-#include "backends/meta-dbus-session-watcher.h"
-
-#include <gio/gio.h>
-
-enum
-{
- SESSION_SIGNAL_SESSION_CLOSED,
-
- N_SESSION_SIGNALS
-};
-
-static guint session_signals[N_SESSION_SIGNALS];
-
-G_DEFINE_INTERFACE (MetaDbusSession, meta_dbus_session, G_TYPE_OBJECT)
-
-struct _MetaDbusSessionWatcher
-{
- GObject parent;
-
- GHashTable *clients;
-};
-
-G_DEFINE_TYPE (MetaDbusSessionWatcher,
- meta_dbus_session_watcher,
- G_TYPE_OBJECT)
-
-typedef struct _MetaDbusSessionClient
-{
- MetaDbusSessionWatcher *session_watcher;
- MetaDbusSession *session;
- char *dbus_name;
- guint name_watcher_id;
- GList *sessions;
-} MetaDbusSessionClient;
-
-static void
-meta_dbus_session_client_vanished (MetaDbusSession *session)
-{
- META_DBUS_SESSION_GET_IFACE (session)->client_vanished (session);
-}
-
-static void
-meta_dbus_session_client_destroy (MetaDbusSessionClient *client)
-{
- while (TRUE)
- {
- GList *l;
- MetaDbusSession *session;
-
- l = client->sessions;
- if (!l)
- break;
-
- session = l->data;
-
- /*
- * This will invoke on_session_closed which removes the session from the
- * list.
- */
- meta_dbus_session_client_vanished (session);
- }
-
- if (client->name_watcher_id)
- g_bus_unwatch_name (client->name_watcher_id);
-
- g_free (client->dbus_name);
- g_free (client);
-}
-
-static void
-meta_dbus_session_watcher_destroy_client (MetaDbusSessionWatcher *session_watcher,
- MetaDbusSessionClient *client)
-{
- g_hash_table_remove (session_watcher->clients, client->dbus_name);
-}
-
-static void
-name_vanished_callback (GDBusConnection *connection,
- const char *name,
- gpointer user_data)
-{
- MetaDbusSessionClient *client = user_data;
-
- g_warning ("D-Bus client with active sessions vanished");
-
- client->name_watcher_id = 0;
-
- meta_dbus_session_watcher_destroy_client (client->session_watcher, client);
-}
-
-static MetaDbusSessionClient *
-meta_dbus_session_client_new (MetaDbusSessionWatcher *session_watcher,
- MetaDbusSession *session,
- const char *dbus_name)
-{
- GDBusInterfaceSkeleton *interface_skeleton =
- G_DBUS_INTERFACE_SKELETON (session);
- GDBusConnection *connection =
- g_dbus_interface_skeleton_get_connection (interface_skeleton);
- MetaDbusSessionClient *client;
-
- client = g_new0 (MetaDbusSessionClient, 1);
- client->session_watcher = session_watcher;
- client->session = session;
- client->dbus_name = g_strdup (dbus_name);
-
- client->name_watcher_id =
- g_bus_watch_name_on_connection (connection,
- dbus_name,
- G_BUS_NAME_WATCHER_FLAGS_NONE,
- NULL,
- name_vanished_callback,
- client,
- NULL);
-
- return client;
-}
-
-static void
-on_session_closed (MetaDbusSession *session,
- MetaDbusSessionClient *client)
-{
- client->sessions = g_list_remove (client->sessions, session);
-
- if (!client->sessions)
- meta_dbus_session_watcher_destroy_client (client->session_watcher, client);
-}
-
-static void
-meta_dbus_session_client_add_session (MetaDbusSessionClient *client,
- MetaDbusSession *session)
-{
- client->sessions = g_list_append (client->sessions, session);
-
- g_signal_connect (session, "session-closed",
- G_CALLBACK (on_session_closed),
- client);
-}
-
-static MetaDbusSessionClient *
-meta_dbus_session_watcher_get_client (MetaDbusSessionWatcher *session_watcher,
- const char *dbus_name)
-{
- return g_hash_table_lookup (session_watcher->clients, dbus_name);
-}
-
-void
-meta_dbus_session_watcher_watch_session (MetaDbusSessionWatcher *session_watcher,
- const char *client_dbus_name,
- MetaDbusSession *session)
-{
- MetaDbusSessionClient *client;
-
- client = meta_dbus_session_watcher_get_client (session_watcher,
- client_dbus_name);
- if (!client)
- {
- client = meta_dbus_session_client_new (session_watcher,
- session,
- client_dbus_name);
- g_hash_table_insert (session_watcher->clients,
- g_strdup (client_dbus_name),
- client);
- }
-
- meta_dbus_session_client_add_session (client, session);
-}
-
-void
-meta_dbus_session_notify_closed (MetaDbusSession *session)
-{
- g_signal_emit (session, session_signals[SESSION_SIGNAL_SESSION_CLOSED], 0);
-}
-
-static void
-meta_dbus_session_default_init (MetaDbusSessionInterface *iface)
-{
- session_signals[SESSION_SIGNAL_SESSION_CLOSED] =
- g_signal_new ("session-closed",
- G_TYPE_FROM_INTERFACE (iface),
- G_SIGNAL_RUN_LAST,
- 0,
- NULL, NULL, NULL,
- G_TYPE_NONE, 0);
-}
-
-static void
-meta_dbus_session_watcher_finalize (GObject *object)
-{
- MetaDbusSessionWatcher *session_watcher = META_DBUS_SESSION_WATCHER (object);
-
- g_hash_table_destroy (session_watcher->clients);
-
- G_OBJECT_CLASS (meta_dbus_session_watcher_parent_class)->finalize (object);
-}
-
-static void
-meta_dbus_session_watcher_init (MetaDbusSessionWatcher *session_watcher)
-{
- session_watcher->clients =
- g_hash_table_new_full (g_str_hash,
- g_str_equal,
- g_free,
- (GDestroyNotify) meta_dbus_session_client_destroy);
-}
-
-static void
-meta_dbus_session_watcher_class_init (MetaDbusSessionWatcherClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- object_class->finalize = meta_dbus_session_watcher_finalize;
-}
diff --git a/src/backends/meta-dbus-session-watcher.h b/src/backends/meta-dbus-session-watcher.h
deleted file mode 100644
index 06d3e1ff9..000000000
--- a/src/backends/meta-dbus-session-watcher.h
+++ /dev/null
@@ -1,52 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2017 Red Hat Inc.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- */
-
-#ifndef META_DBUS_SESSION_WATCHER_H
-#define META_DBUS_SESSION_WATCHER_H
-
-#include <glib-object.h>
-
-#define META_TYPE_DBUS_SESSION (meta_dbus_session_get_type ())
-G_DECLARE_INTERFACE (MetaDbusSession, meta_dbus_session,
- META, DBUS_SESSION,
- GObject)
-
-struct _MetaDbusSessionInterface
-{
- GTypeInterface parent_iface;
-
- void (* client_vanished) (MetaDbusSession *session);
-};
-
-#define META_TYPE_DBUS_SESSION_WATCHER (meta_dbus_session_watcher_get_type ())
-G_DECLARE_FINAL_TYPE (MetaDbusSessionWatcher,
- meta_dbus_session_watcher,
- META, DBUS_SESSION_WATCHER,
- GObject)
-
-void meta_dbus_session_watcher_watch_session (MetaDbusSessionWatcher *session_watcher,
- const char *client_dbus_name,
- MetaDbusSession *session);
-
-void meta_dbus_session_notify_closed (MetaDbusSession *session);
-
-#endif /* META_DBUS_SESSION_WATCHER_H */
diff --git a/src/backends/meta-display-config-shared.h b/src/backends/meta-display-config-shared.h
deleted file mode 100644
index f037dac83..000000000
--- a/src/backends/meta-display-config-shared.h
+++ /dev/null
@@ -1,39 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-/*
- * Copyright (C) 2013 Red Hat Inc.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, see <http://www.gnu.org/licenses/>.
- */
-
-/* This file is shared between mutter (src/core/meta-display-config-shared.h)
- and gnome-desktop (libgnome-desktop/meta-xrandr-shared.h).
-
- The canonical place for all changes is mutter.
-
- There should be no includes in this file.
-*/
-
-#ifndef META_DISPLAY_CONFIG_SHARED_H
-#define META_DISPLAY_CONFIG_SHARED_H
-
-typedef enum
-{
- META_POWER_SAVE_UNSUPPORTED = -1,
- META_POWER_SAVE_ON = 0,
- META_POWER_SAVE_STANDBY,
- META_POWER_SAVE_SUSPEND,
- META_POWER_SAVE_OFF,
-} MetaPowerSave;
-
-#endif /* META_DISPLAY_CONFIG_SHARED_H */
diff --git a/src/backends/meta-dnd-private.h b/src/backends/meta-dnd-private.h
deleted file mode 100644
index 0cfb3d788..000000000
--- a/src/backends/meta-dnd-private.h
+++ /dev/null
@@ -1,41 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2016 Hyungwon Hwang
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef META_DND_PRIVATE__H
-#define META_DND_PRIVATE__H
-
-#include <glib.h>
-#include <X11/Xlib.h>
-
-#include "backends/meta-backend-private.h"
-#include "compositor/meta-compositor-x11.h"
-
-gboolean meta_dnd_handle_xdnd_event (MetaBackend *backend,
- MetaCompositorX11 *compositor_x11,
- Display *xdisplay,
- XEvent *xev);
-
-void meta_dnd_init_xdnd (MetaX11Display *x11_display);
-
-#ifdef HAVE_WAYLAND
-void meta_dnd_wayland_handle_begin_modal (MetaCompositor *compositor);
-void meta_dnd_wayland_handle_end_modal (MetaCompositor *compositor);
-#endif
-
-#endif /* META_DND_PRIVATE_H */
diff --git a/src/backends/meta-egl-ext.h b/src/backends/meta-egl-ext.h
deleted file mode 100644
index db0b74f76..000000000
--- a/src/backends/meta-egl-ext.h
+++ /dev/null
@@ -1,103 +0,0 @@
-/*
- * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining
- * a copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sublicense, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial
- * portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
- * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
- * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-#ifndef META_EGL_EXT_H
-#define META_EGL_EXT_H
-
-#include <EGL/egl.h>
-#include <EGL/eglext.h>
-#include <EGL/eglmesaext.h>
-
-/*
- * This is a little different to the tests shipped with EGL implementations,
- * which wrap the entire thing in #ifndef EGL_WL_bind_wayland_display, then go
- * on to define both BindWaylandDisplay and QueryWaylandBuffer.
- *
- * Unfortunately, some implementations (particularly the version of Mesa shipped
- * in Ubuntu 12.04) define EGL_WL_bind_wayland_display, but then only provide
- * prototypes for (Un)BindWaylandDisplay, completely omitting
- * QueryWaylandBuffer.
- *
- * Detect this, and provide our own definitions if necessary.
- */
-#ifndef EGL_WAYLAND_BUFFER_WL
-#define EGL_WAYLAND_BUFFER_WL 0x31D5 /* eglCreateImageKHR target */
-#define EGL_WAYLAND_PLANE_WL 0x31D6 /* eglCreateImageKHR target */
-
-#define EGL_TEXTURE_Y_U_V_WL 0x31D7
-#define EGL_TEXTURE_Y_UV_WL 0x31D8
-#define EGL_TEXTURE_Y_XUXV_WL 0x31D9
-#define EGL_TEXTURE_EXTERNAL_WL 0x31DA
-
-struct wl_resource;
-#ifdef EGL_EGLEXT_PROTOTYPES
-EGLAPI EGLBoolean EGLAPIENTRY eglQueryWaylandBufferWL(EGLDisplay dpy, struct wl_resource *buffer, EGLint attribute, EGLint *value);
-#endif
-typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYWAYLANDBUFFERWL) (EGLDisplay dpy, struct wl_resource *buffer, EGLint attribute, EGLint *value);
-#endif
-
-/*
- * FIXME: Remove both EGL_EXT_stream_acquire_mode and
- * EGL_NV_output_drm_flip_event definitions below once both extensions
- * get published by Khronos and incorportated into Khronos' header files
- */
-#ifndef EGL_EXT_stream_acquire_mode
-#define EGL_EXT_stream_acquire_mode 1
-#define EGL_CONSUMER_AUTO_ACQUIRE_EXT 0x332B
-#define EGL_RESOURCE_BUSY_EXT 0x3353
-typedef EGLBoolean (EGLAPIENTRYP PFNEGLSTREAMCONSUMERACQUIREATTRIBEXTPROC) (EGLDisplay dpy, EGLStreamKHR stream, const EGLAttrib *attrib_list);
-#ifdef EGL_EGLEXT_PROTOTYPES
-EGLAPI EGLBoolean EGLAPIENTRY eglStreamConsumerAcquireAttribEXT (EGLDisplay dpy, EGLStreamKHR stream, const EGLAttrib *attrib_list);
-#endif
-#endif /* EGL_EXT_stream_acquire_mode */
-
-#ifndef EGL_NV_output_drm_flip_event
-#define EGL_NV_output_drm_flip_event 1
-#define EGL_DRM_FLIP_EVENT_DATA_NV 0x333E
-#endif /* EGL_NV_output_drm_flip_event */
-
-#ifndef EGL_NV_stream_attrib
-#define EGL_NV_stream_attrib 1
-#ifdef EGL_EGLEXT_PROTOTYPES
-EGLAPI EGLStreamKHR EGLAPIENTRY eglCreateStreamAttribNV(EGLDisplay dpy, const EGLAttrib *attrib_list);
-EGLAPI EGLBoolean EGLAPIENTRY eglSetStreamAttribNV(EGLDisplay dpy, EGLStreamKHR stream, EGLenum attribute, EGLAttrib value);
-EGLAPI EGLBoolean EGLAPIENTRY eglQueryStreamAttribNV(EGLDisplay dpy, EGLStreamKHR stream, EGLenum attribute, EGLAttrib *value);
-EGLAPI EGLBoolean EGLAPIENTRY eglStreamConsumerAcquireAttribNV(EGLDisplay dpy, EGLStreamKHR stream, const EGLAttrib *attrib_list);
-EGLAPI EGLBoolean EGLAPIENTRY eglStreamConsumerReleaseAttribNV(EGLDisplay dpy, EGLStreamKHR stream, const EGLAttrib *attrib_list);
-#endif
-typedef EGLStreamKHR (EGLAPIENTRYP PFNEGLCREATESTREAMATTRIBNVPROC) (EGLDisplay dpy, const EGLAttrib *attrib_list);
-typedef EGLBoolean (EGLAPIENTRYP PFNEGLSETSTREAMATTRIBNVPROC) (EGLDisplay dpy, EGLStreamKHR stream, EGLenum attribute, EGLAttrib value);
-typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYSTREAMATTRIBNVPROC) (EGLDisplay dpy, EGLStreamKHR stream, EGLenum attribute, EGLAttrib *value);
-typedef EGLBoolean (EGLAPIENTRYP PFNEGLSTREAMCONSUMERACQUIREATTRIBNVPROC) (EGLDisplay dpy, EGLStreamKHR stream, const EGLAttrib *attrib_list);
-typedef EGLBoolean (EGLAPIENTRYP PFNEGLSTREAMCONSUMERRELEASEATTRIBNVPROC) (EGLDisplay dpy, EGLStreamKHR stream, const EGLAttrib *attrib_list);
-#endif /* EGL_NV_stream_attrib */
-
-#ifndef EGL_WL_wayland_eglstream
-#define EGL_WL_wayland_eglstream 1
-#define EGL_WAYLAND_EGLSTREAM_WL 0x334B
-#endif /* EGL_WL_wayland_eglstream */
-
-#endif /* META_EGL_EXT_H */
diff --git a/src/backends/meta-egl.c b/src/backends/meta-egl.c
deleted file mode 100644
index 0d3f8c95d..000000000
--- a/src/backends/meta-egl.c
+++ /dev/null
@@ -1,1154 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2016, 2017 Red Hat Inc.
- * Copyright (C) 2018, 2019 DisplayLink (UK) Ltd.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Written by:
- * Jonas Ådahl <jadahl@gmail.com>
- */
-
-#include "config.h"
-
-#include <EGL/egl.h>
-#include <EGL/eglext.h>
-#include <EGL/eglmesaext.h>
-#include <gio/gio.h>
-#include <glib.h>
-#include <glib-object.h>
-
-#include "backends/meta-backend-private.h"
-#include "backends/meta-egl.h"
-#include "backends/meta-egl-ext.h"
-#include "meta/util.h"
-
-struct _MetaEgl
-{
- GObject parent;
-
- PFNEGLGETPLATFORMDISPLAYEXTPROC eglGetPlatformDisplayEXT;
-
- PFNEGLCREATEIMAGEKHRPROC eglCreateImageKHR;
- PFNEGLDESTROYIMAGEKHRPROC eglDestroyImageKHR;
-
- PFNEGLBINDWAYLANDDISPLAYWL eglBindWaylandDisplayWL;
- PFNEGLQUERYWAYLANDBUFFERWL eglQueryWaylandBufferWL;
-
- PFNEGLQUERYDEVICESEXTPROC eglQueryDevicesEXT;
- PFNEGLQUERYDEVICESTRINGEXTPROC eglQueryDeviceStringEXT;
-
- PFNEGLGETOUTPUTLAYERSEXTPROC eglGetOutputLayersEXT;
- PFNEGLQUERYOUTPUTLAYERATTRIBEXTPROC eglQueryOutputLayerAttribEXT;
-
- PFNEGLCREATESTREAMKHRPROC eglCreateStreamKHR;
- PFNEGLDESTROYSTREAMKHRPROC eglDestroyStreamKHR;
- PFNEGLQUERYSTREAMKHRPROC eglQueryStreamKHR;
-
- PFNEGLCREATESTREAMATTRIBNVPROC eglCreateStreamAttribNV;
-
- PFNEGLCREATESTREAMPRODUCERSURFACEKHRPROC eglCreateStreamProducerSurfaceKHR;
-
- PFNEGLSTREAMCONSUMEROUTPUTEXTPROC eglStreamConsumerOutputEXT;
-
- PFNEGLSTREAMCONSUMERGLTEXTUREEXTERNALKHRPROC eglStreamConsumerGLTextureExternalKHR;
-
- PFNEGLSTREAMCONSUMERACQUIREKHRPROC eglStreamConsumerAcquireKHR;
- PFNEGLSTREAMCONSUMERACQUIREATTRIBNVPROC eglStreamConsumerAcquireAttribNV;
-
- PFNEGLQUERYDMABUFFORMATSEXTPROC eglQueryDmaBufFormatsEXT;
- PFNEGLQUERYDMABUFMODIFIERSEXTPROC eglQueryDmaBufModifiersEXT;
-};
-
-G_DEFINE_TYPE (MetaEgl, meta_egl, G_TYPE_OBJECT)
-
-G_DEFINE_QUARK (-meta-egl-error-quark, meta_egl_error)
-
-static const char *
-get_egl_error_str (EGLint error_number)
-{
- switch (error_number)
- {
- case EGL_SUCCESS:
- return "The last function succeeded without error.";
- break;
- case EGL_NOT_INITIALIZED:
- return "EGL is not initialized, or could not be initialized, for the specified EGL display connection.";
- break;
- case EGL_BAD_ACCESS:
- return "EGL cannot access a requested resource (for example a context is bound in another thread).";
- break;
- case EGL_BAD_ALLOC:
- return "EGL failed to allocate resources for the requested operation.";
- break;
- case EGL_BAD_ATTRIBUTE:
- return "An unrecognized attribute or attribute value was passed in the attribute list.";
- break;
- case EGL_BAD_CONTEXT:
- return "An EGLContext argument does not name a valid EGL rendering context.";
- break;
- case EGL_BAD_CONFIG:
- return "An EGLConfig argument does not name a valid EGL frame buffer configuration.";
- break;
- case EGL_BAD_CURRENT_SURFACE:
- return "The current surface of the calling thread is a window, pixel buffer or pixmap that is no longer valid.";
- break;
- case EGL_BAD_DISPLAY:
- return "An EGLDisplay argument does not name a valid EGL display connection.";
- break;
- case EGL_BAD_SURFACE:
- return "An EGLSurface argument does not name a valid surface (window, pixel buffer or pixmap) configured for GL rendering.";
- break;
- case EGL_BAD_MATCH:
- return "Arguments are inconsistent (for example, a valid context requires buffers not supplied by a valid surface).";
- break;
- case EGL_BAD_PARAMETER:
- return "One or more argument values are invalid.";
- break;
- case EGL_BAD_NATIVE_PIXMAP:
- return "A NativePixmapType argument does not refer to a valid native pixmap.";
- break;
- case EGL_BAD_NATIVE_WINDOW:
- return "A NativeWindowType argument does not refer to a valid native window.";
- break;
- case EGL_CONTEXT_LOST:
- return "A power management event has occurred. The application must destroy all contexts and reinitialise OpenGL ES state and objects to continue rendering. ";
- break;
- case EGL_BAD_STREAM_KHR:
- return "An EGLStreamKHR argument does not name a valid EGL stream.";
- break;
- case EGL_BAD_STATE_KHR:
- return "An EGLStreamKHR argument is not in a valid state";
- break;
- case EGL_BAD_DEVICE_EXT:
- return "An EGLDeviceEXT argument does not name a valid EGL device.";
- break;
- case EGL_BAD_OUTPUT_LAYER_EXT:
- return "An EGLOutputLayerEXT argument does not name a valid EGL output layer.";
- case EGL_RESOURCE_BUSY_EXT:
- return "The operation could not be completed on the requested resource because it is temporary unavailable.";
- default:
- return "Unknown error";
- break;
- }
-}
-
-static void
-set_egl_error (GError **error)
-{
- EGLint error_number;
- const char *error_str;
-
- if (!error)
- return;
-
- error_number = eglGetError ();
- error_str = get_egl_error_str (error_number);
- g_set_error_literal (error, META_EGL_ERROR,
- error_number,
- error_str);
-}
-
-gboolean
-meta_extensions_string_has_extensions_valist (const char *extensions_str,
- const char ***missing_extensions,
- const char *first_extension,
- va_list var_args)
-{
- char **extensions;
- const char *extension;
- size_t num_missing_extensions = 0;
-
- if (missing_extensions)
- *missing_extensions = NULL;
-
- extensions = g_strsplit (extensions_str, " ", -1);
-
- extension = first_extension;
- while (extension)
- {
- if (!g_strv_contains ((const char * const *) extensions, extension))
- {
- num_missing_extensions++;
- if (missing_extensions)
- {
- *missing_extensions = g_realloc_n (*missing_extensions,
- num_missing_extensions + 1,
- sizeof (const char *));
- (*missing_extensions)[num_missing_extensions - 1] = extension;
- (*missing_extensions)[num_missing_extensions] = NULL;
- }
- else
- {
- break;
- }
- }
- extension = va_arg (var_args, char *);
- }
-
- g_strfreev (extensions);
-
- return num_missing_extensions == 0;
-}
-
-gboolean
-meta_egl_has_extensions (MetaEgl *egl,
- EGLDisplay display,
- const char ***missing_extensions,
- const char *first_extension,
- ...)
-{
- va_list var_args;
- const char *extensions_str;
- gboolean has_extensions;
-
- extensions_str = (const char *) eglQueryString (display, EGL_EXTENSIONS);
- if (!extensions_str)
- {
- g_warning ("Failed to query string: %s",
- get_egl_error_str (eglGetError ()));
- return FALSE;
- }
-
- va_start (var_args, first_extension);
- has_extensions =
- meta_extensions_string_has_extensions_valist (extensions_str,
- missing_extensions,
- first_extension,
- var_args);
- va_end (var_args);
-
- return has_extensions;
-}
-
-gboolean
-meta_egl_initialize (MetaEgl *egl,
- EGLDisplay display,
- GError **error)
-{
- if (!eglInitialize (display, NULL, NULL))
- {
- set_egl_error (error);
- return FALSE;
- }
-
- return TRUE;
-}
-
-gboolean
-meta_egl_bind_api (MetaEgl *egl,
- EGLenum api,
- GError **error)
-{
- if (!eglBindAPI (api))
- {
- set_egl_error (error);
- return FALSE;
- }
-
- return TRUE;
-}
-
-gpointer
-meta_egl_get_proc_address (MetaEgl *egl,
- const char *procname,
- GError **error)
-{
- gpointer func;
-
- func = (gpointer) eglGetProcAddress (procname);
- if (!func)
- {
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- "Could not load symbol '%s': Not found",
- procname);
- return NULL;
- }
-
- return func;
-}
-
-gboolean
-meta_egl_get_config_attrib (MetaEgl *egl,
- EGLDisplay display,
- EGLConfig config,
- EGLint attribute,
- EGLint *value,
- GError **error)
-{
- if (!eglGetConfigAttrib (display,
- config,
- attribute,
- value))
- {
- set_egl_error (error);
- return FALSE;
- }
-
- return TRUE;
-}
-
-EGLConfig *
-meta_egl_choose_all_configs (MetaEgl *egl,
- EGLDisplay display,
- const EGLint *attrib_list,
- EGLint *out_num_configs,
- GError **error)
-{
- EGLint num_configs;
- EGLConfig *configs;
- EGLint num_matches;
-
- if (!eglGetConfigs (display, NULL, 0, &num_configs))
- {
- set_egl_error (error);
- return FALSE;
- }
-
- if (num_configs < 1)
- {
- g_set_error (error, G_IO_ERROR,
- G_IO_ERROR_FAILED,
- "No EGL configurations available");
- return FALSE;
- }
-
- configs = g_new0 (EGLConfig, num_configs);
-
- if (!eglChooseConfig (display, attrib_list, configs, num_configs, &num_matches))
- {
- g_free (configs);
- set_egl_error (error);
- return FALSE;
- }
-
- if (num_matches == 0)
- {
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- "No matching EGL configs");
- g_free (configs);
- return NULL;
- }
-
- *out_num_configs = num_configs;
- return configs;
-}
-
-gboolean
-meta_egl_choose_first_config (MetaEgl *egl,
- EGLDisplay display,
- const EGLint *attrib_list,
- EGLConfig *chosen_config,
- GError **error)
-{
- EGLint num_configs;
- EGLConfig *configs;
- EGLint num_matches;
-
- if (!eglGetConfigs (display, NULL, 0, &num_configs))
- {
- set_egl_error (error);
- return FALSE;
- }
-
- if (num_configs < 1)
- {
- g_set_error (error, G_IO_ERROR,
- G_IO_ERROR_FAILED,
- "No EGL configurations available");
- return FALSE;
- }
-
- configs = g_new0 (EGLConfig, num_configs);
-
- if (!eglChooseConfig (display, attrib_list, configs, num_configs, &num_matches))
- {
- g_free (configs);
- set_egl_error (error);
- return FALSE;
- }
-
- if (num_matches == 0)
- {
- g_free (configs);
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- "No matching EGLConfig found");
- return FALSE;
- }
-
- /*
- * We don't have any preference specified yet, so lets choose the first one.
- */
- *chosen_config = configs[0];
-
- g_free (configs);
-
- return TRUE;
-}
-
-EGLSurface
-meta_egl_create_window_surface (MetaEgl *egl,
- EGLDisplay display,
- EGLConfig config,
- EGLNativeWindowType native_window_type,
- const EGLint *attrib_list,
- GError **error)
-{
- EGLSurface surface;
-
- surface = eglCreateWindowSurface (display, config,
- native_window_type, attrib_list);
- if (surface == EGL_NO_SURFACE)
- {
- set_egl_error (error);
- return EGL_NO_SURFACE;
- }
-
- return surface;
-}
-
-EGLSurface
-meta_egl_create_pbuffer_surface (MetaEgl *egl,
- EGLDisplay display,
- EGLConfig config,
- const EGLint *attrib_list,
- GError **error)
-{
- EGLSurface surface;
-
- surface = eglCreatePbufferSurface (display, config, attrib_list);
- if (surface == EGL_NO_SURFACE)
- {
- set_egl_error (error);
- return EGL_NO_SURFACE;
- }
-
- return surface;
-}
-
-gboolean
-meta_egl_destroy_surface (MetaEgl *egl,
- EGLDisplay display,
- EGLSurface surface,
- GError **error)
-{
- if (!eglDestroySurface (display, surface))
- {
- set_egl_error (error);
- return FALSE;
- }
-
- return TRUE;
-}
-
-static gboolean
-is_egl_proc_valid_real (void *proc,
- const char *proc_name,
- GError **error)
-{
- if (!proc)
- {
- g_set_error (error, G_IO_ERROR,
- G_IO_ERROR_FAILED,
- "EGL proc '%s' not resolved",
- proc_name);
- return FALSE;
- }
-
- return TRUE;
-}
-
-#define is_egl_proc_valid(proc, error) \
- is_egl_proc_valid_real (proc, #proc, error)
-
-EGLDisplay
-meta_egl_get_platform_display (MetaEgl *egl,
- EGLenum platform,
- void *native_display,
- const EGLint *attrib_list,
- GError **error)
-{
- EGLDisplay display;
-
- if (!is_egl_proc_valid (egl->eglGetPlatformDisplayEXT, error))
- return EGL_NO_DISPLAY;
-
- display = egl->eglGetPlatformDisplayEXT (platform,
- native_display,
- attrib_list);
- if (display == EGL_NO_DISPLAY)
- {
- set_egl_error (error);
- return EGL_NO_DISPLAY;
- }
-
- return display;
-}
-
-gboolean
-meta_egl_terminate (MetaEgl *egl,
- EGLDisplay display,
- GError **error)
-{
- if (!eglTerminate (display))
- {
- set_egl_error (error);
- return FALSE;
- }
-
- return TRUE;
-}
-
-EGLContext
-meta_egl_create_context (MetaEgl *egl,
- EGLDisplay display,
- EGLConfig config,
- EGLContext share_context,
- const EGLint *attrib_list,
- GError **error)
-{
- EGLContext context;
-
- context = eglCreateContext (display, config, share_context, attrib_list);
- if (context == EGL_NO_CONTEXT)
- {
- set_egl_error (error);
- return EGL_NO_CONTEXT;
- }
-
- return context;
-}
-
-gboolean
-meta_egl_destroy_context (MetaEgl *egl,
- EGLDisplay display,
- EGLContext context,
- GError **error)
-{
- if (!eglDestroyContext (display, context))
- {
- set_egl_error (error);
- return FALSE;
- }
-
- return TRUE;
-}
-
-EGLImageKHR
-meta_egl_create_image (MetaEgl *egl,
- EGLDisplay display,
- EGLContext context,
- EGLenum target,
- EGLClientBuffer buffer,
- const EGLint *attrib_list,
- GError **error)
-{
- EGLImageKHR image;
-
- if (!is_egl_proc_valid (egl->eglCreateImageKHR, error))
- return EGL_NO_IMAGE_KHR;
-
- image = egl->eglCreateImageKHR (display, context,
- target, buffer, attrib_list);
- if (image == EGL_NO_IMAGE_KHR)
- {
- set_egl_error (error);
- return EGL_NO_IMAGE_KHR;
- }
-
- return image;
-}
-
-gboolean
-meta_egl_destroy_image (MetaEgl *egl,
- EGLDisplay display,
- EGLImageKHR image,
- GError **error)
-{
- if (!is_egl_proc_valid (egl->eglDestroyImageKHR, error))
- return FALSE;
-
- if (!egl->eglDestroyImageKHR (display, image))
- {
- set_egl_error (error);
- return FALSE;
- }
-
- return TRUE;
-}
-
-EGLImageKHR
-meta_egl_create_dmabuf_image (MetaEgl *egl,
- EGLDisplay egl_display,
- unsigned int width,
- unsigned int height,
- uint32_t drm_format,
- uint32_t n_planes,
- const int *fds,
- const uint32_t *strides,
- const uint32_t *offsets,
- const uint64_t *modifiers,
- GError **error)
-{
- EGLint attribs[37];
- int atti = 0;
-
- /* This requires the Mesa commit in
- * Mesa 10.3 (08264e5dad4df448e7718e782ad9077902089a07) or
- * Mesa 10.2.7 (55d28925e6109a4afd61f109e845a8a51bd17652).
- * Otherwise Mesa closes the fd behind our back and re-importing
- * will fail.
- * https://bugs.freedesktop.org/show_bug.cgi?id=76188
- */
-
- attribs[atti++] = EGL_WIDTH;
- attribs[atti++] = width;
- attribs[atti++] = EGL_HEIGHT;
- attribs[atti++] = height;
- attribs[atti++] = EGL_LINUX_DRM_FOURCC_EXT;
- attribs[atti++] = drm_format;
-
- if (n_planes > 0)
- {
- attribs[atti++] = EGL_DMA_BUF_PLANE0_FD_EXT;
- attribs[atti++] = fds[0];
- attribs[atti++] = EGL_DMA_BUF_PLANE0_OFFSET_EXT;
- attribs[atti++] = offsets[0];
- attribs[atti++] = EGL_DMA_BUF_PLANE0_PITCH_EXT;
- attribs[atti++] = strides[0];
- if (modifiers)
- {
- attribs[atti++] = EGL_DMA_BUF_PLANE0_MODIFIER_LO_EXT;
- attribs[atti++] = modifiers[0] & 0xFFFFFFFF;
- attribs[atti++] = EGL_DMA_BUF_PLANE0_MODIFIER_HI_EXT;
- attribs[atti++] = modifiers[0] >> 32;
- }
- }
-
- if (n_planes > 1)
- {
- attribs[atti++] = EGL_DMA_BUF_PLANE1_FD_EXT;
- attribs[atti++] = fds[1];
- attribs[atti++] = EGL_DMA_BUF_PLANE1_OFFSET_EXT;
- attribs[atti++] = offsets[1];
- attribs[atti++] = EGL_DMA_BUF_PLANE1_PITCH_EXT;
- attribs[atti++] = strides[1];
- if (modifiers)
- {
- attribs[atti++] = EGL_DMA_BUF_PLANE1_MODIFIER_LO_EXT;
- attribs[atti++] = modifiers[1] & 0xFFFFFFFF;
- attribs[atti++] = EGL_DMA_BUF_PLANE1_MODIFIER_HI_EXT;
- attribs[atti++] = modifiers[1] >> 32;
- }
- }
-
- if (n_planes > 2)
- {
- attribs[atti++] = EGL_DMA_BUF_PLANE2_FD_EXT;
- attribs[atti++] = fds[2];
- attribs[atti++] = EGL_DMA_BUF_PLANE2_OFFSET_EXT;
- attribs[atti++] = offsets[2];
- attribs[atti++] = EGL_DMA_BUF_PLANE2_PITCH_EXT;
- attribs[atti++] = strides[2];
- if (modifiers)
- {
- attribs[atti++] = EGL_DMA_BUF_PLANE2_MODIFIER_LO_EXT;
- attribs[atti++] = modifiers[2] & 0xFFFFFFFF;
- attribs[atti++] = EGL_DMA_BUF_PLANE2_MODIFIER_HI_EXT;
- attribs[atti++] = modifiers[2] >> 32;
- }
- }
-
- attribs[atti++] = EGL_NONE;
- g_assert (atti <= G_N_ELEMENTS (attribs));
-
- return meta_egl_create_image (egl, egl_display, EGL_NO_CONTEXT,
- EGL_LINUX_DMA_BUF_EXT, NULL,
- attribs,
- error);
-}
-
-gboolean
-meta_egl_make_current (MetaEgl *egl,
- EGLDisplay display,
- EGLSurface draw,
- EGLSurface read,
- EGLContext context,
- GError **error)
-{
- if (!eglMakeCurrent (display, draw, read, context))
- {
- set_egl_error (error);
- return FALSE;
- }
-
- return TRUE;
-}
-
-gboolean
-meta_egl_swap_buffers (MetaEgl *egl,
- EGLDisplay display,
- EGLSurface surface,
- GError **error)
-{
- if (!eglSwapBuffers (display, surface))
- {
- set_egl_error (error);
- return FALSE;
- }
-
- return TRUE;
-}
-
-gboolean
-meta_egl_bind_wayland_display (MetaEgl *egl,
- EGLDisplay display,
- struct wl_display *wayland_display,
- GError **error)
-{
- if (!is_egl_proc_valid (egl->eglBindWaylandDisplayWL, error))
- return FALSE;
-
- if (!egl->eglBindWaylandDisplayWL (display, wayland_display))
- {
- set_egl_error (error);
- return FALSE;
- }
-
- return TRUE;
-}
-
-gboolean
-meta_egl_query_wayland_buffer (MetaEgl *egl,
- EGLDisplay display,
- struct wl_resource *buffer,
- EGLint attribute,
- EGLint *value,
- GError **error)
-{
- if (!is_egl_proc_valid (egl->eglQueryWaylandBufferWL, error))
- return FALSE;
-
- if (!egl->eglQueryWaylandBufferWL (display, buffer, attribute, value))
- {
- set_egl_error (error);
- return FALSE;
- }
-
- return TRUE;
-}
-
-gboolean
-meta_egl_query_devices (MetaEgl *egl,
- EGLint max_devices,
- EGLDeviceEXT *devices,
- EGLint *num_devices,
- GError **error)
-{
- if (!is_egl_proc_valid (egl->eglQueryDevicesEXT, error))
- return FALSE;
-
- if (!egl->eglQueryDevicesEXT (max_devices,
- devices,
- num_devices))
- {
- set_egl_error (error);
- return FALSE;
- }
-
- return TRUE;
-}
-
-const char *
-meta_egl_query_device_string (MetaEgl *egl,
- EGLDeviceEXT device,
- EGLint name,
- GError **error)
-{
- const char *device_string;
-
- if (!is_egl_proc_valid (egl->eglQueryDeviceStringEXT, error))
- return NULL;
-
- device_string = egl->eglQueryDeviceStringEXT (device, name);
- if (!device_string)
- {
- set_egl_error (error);
- return NULL;
- }
-
- return device_string;
-}
-
-gboolean
-meta_egl_egl_device_has_extensions (MetaEgl *egl,
- EGLDeviceEXT device,
- const char ***missing_extensions,
- const char *first_extension,
- ...)
-{
- va_list var_args;
- const char *extensions_str;
- gboolean has_extensions;
- GError *error = NULL;
-
- extensions_str = meta_egl_query_device_string (egl, device, EGL_EXTENSIONS,
- &error);
- if (!extensions_str)
- {
- g_warning ("Failed to query device string: %s", error->message);
- g_error_free (error);
- return FALSE;
- }
-
- va_start (var_args, first_extension);
- has_extensions =
- meta_extensions_string_has_extensions_valist (extensions_str,
- missing_extensions,
- first_extension,
- var_args);
- va_end (var_args);
-
- return has_extensions;
-}
-
-gboolean
-meta_egl_get_output_layers (MetaEgl *egl,
- EGLDisplay display,
- const EGLAttrib *attrib_list,
- EGLOutputLayerEXT *layers,
- EGLint max_layers,
- EGLint *num_layers,
- GError **error)
-{
- if (!is_egl_proc_valid (egl->eglGetOutputLayersEXT, error))
- return FALSE;
-
- if (!egl->eglGetOutputLayersEXT (display,
- attrib_list,
- layers,
- max_layers,
- num_layers))
- {
- set_egl_error (error);
- return FALSE;
- }
-
- return TRUE;
-}
-
-gboolean
-meta_egl_query_output_layer_attrib (MetaEgl *egl,
- EGLDisplay display,
- EGLOutputLayerEXT layer,
- EGLint attribute,
- EGLAttrib *value,
- GError **error)
-{
- if (!is_egl_proc_valid (egl->eglQueryOutputLayerAttribEXT, error))
- return FALSE;
-
- if (!egl->eglQueryOutputLayerAttribEXT (display, layer,
- attribute, value))
- {
- set_egl_error (error);
- return FALSE;
- }
-
- return TRUE;
-}
-
-EGLStreamKHR
-meta_egl_create_stream (MetaEgl *egl,
- EGLDisplay display,
- const EGLint *attrib_list,
- GError **error)
-{
- EGLStreamKHR stream;
-
- if (!is_egl_proc_valid (egl->eglCreateStreamKHR, error))
- return EGL_NO_STREAM_KHR;
-
- stream = egl->eglCreateStreamKHR (display, attrib_list);
- if (stream == EGL_NO_STREAM_KHR)
- {
- set_egl_error (error);
- return EGL_NO_STREAM_KHR;
- }
-
- return stream;
-}
-
-gboolean
-meta_egl_destroy_stream (MetaEgl *egl,
- EGLDisplay display,
- EGLStreamKHR stream,
- GError **error)
-{
- if (!is_egl_proc_valid (egl->eglDestroyStreamKHR, error))
- return FALSE;
-
- if (!egl->eglDestroyStreamKHR (display, stream))
- {
- set_egl_error (error);
- return FALSE;
- }
-
- return TRUE;
-}
-
-gboolean
-meta_egl_query_stream (MetaEgl *egl,
- EGLDisplay display,
- EGLStreamKHR stream,
- EGLenum attribute,
- EGLint *value,
- GError **error)
-{
- if (!is_egl_proc_valid (egl->eglQueryStreamKHR, error))
- return FALSE;
-
- if (!egl->eglQueryStreamKHR (display, stream, attribute, value))
- {
- set_egl_error (error);
- return FALSE;
- }
-
- return TRUE;
-}
-
-EGLStreamKHR
-meta_egl_create_stream_attrib (MetaEgl *egl,
- EGLDisplay display,
- const EGLAttrib *attrib_list,
- GError **error)
-{
- EGLStreamKHR stream;
-
- if (!is_egl_proc_valid (egl->eglCreateStreamAttribNV, error))
- return FALSE;
-
- stream = egl->eglCreateStreamAttribNV (display, attrib_list);
- if (stream == EGL_NO_STREAM_KHR)
- {
- set_egl_error (error);
- return EGL_NO_STREAM_KHR;
- }
-
- return stream;
-}
-
-EGLSurface
-meta_egl_create_stream_producer_surface (MetaEgl *egl,
- EGLDisplay display,
- EGLConfig config,
- EGLStreamKHR stream,
- const EGLint *attrib_list,
- GError **error)
-{
- EGLSurface surface;
-
- if (!is_egl_proc_valid (egl->eglCreateStreamProducerSurfaceKHR, error))
- return EGL_NO_SURFACE;
-
- surface = egl->eglCreateStreamProducerSurfaceKHR (display,
- config,
- stream,
- attrib_list);
- if (surface == EGL_NO_SURFACE)
- {
- set_egl_error (error);
- return EGL_NO_SURFACE;
- }
-
- return surface;
-}
-
-gboolean
-meta_egl_stream_consumer_output (MetaEgl *egl,
- EGLDisplay display,
- EGLStreamKHR stream,
- EGLOutputLayerEXT layer,
- GError **error)
-{
- if (!is_egl_proc_valid (egl->eglStreamConsumerOutputEXT, error))
- return FALSE;
-
- if (!egl->eglStreamConsumerOutputEXT (display, stream, layer))
- {
- set_egl_error (error);
- return FALSE;
- }
-
- return TRUE;
-}
-
-gboolean
-meta_egl_stream_consumer_acquire_attrib (MetaEgl *egl,
- EGLDisplay display,
- EGLStreamKHR stream,
- EGLAttrib *attrib_list,
- GError **error)
-{
- if (!is_egl_proc_valid (egl->eglStreamConsumerAcquireAttribNV, error))
- return FALSE;
-
- if (!egl->eglStreamConsumerAcquireAttribNV (display, stream, attrib_list))
- {
- set_egl_error (error);
- return FALSE;
- }
-
- return TRUE;
-}
-
-gboolean
-meta_egl_stream_consumer_gl_texture_external (MetaEgl *egl,
- EGLDisplay display,
- EGLStreamKHR stream,
- GError **error)
-{
- if (!is_egl_proc_valid (egl->eglStreamConsumerGLTextureExternalKHR, error))
- return FALSE;
-
- if (!egl->eglStreamConsumerGLTextureExternalKHR (display, stream))
- {
- set_egl_error (error);
- return FALSE;
- }
-
- return TRUE;
-}
-
-gboolean
-meta_egl_stream_consumer_acquire (MetaEgl *egl,
- EGLDisplay display,
- EGLStreamKHR stream,
- GError **error)
-{
- if (!is_egl_proc_valid (egl->eglStreamConsumerAcquireKHR, error))
- return FALSE;
-
- if (!egl->eglStreamConsumerAcquireKHR (display, stream))
- {
- set_egl_error (error);
- return FALSE;
- }
-
- return TRUE;
-}
-
-gboolean
-meta_egl_query_dma_buf_formats (MetaEgl *egl,
- EGLDisplay display,
- EGLint max_formats,
- EGLint *formats,
- EGLint *num_formats,
- GError **error)
-{
- if (!is_egl_proc_valid (egl->eglQueryDmaBufFormatsEXT, error))
- return FALSE;
-
- if (!egl->eglQueryDmaBufFormatsEXT (display, max_formats, formats,
- num_formats))
- {
- set_egl_error (error);
- return FALSE;
- }
-
- return TRUE;
-}
-
-gboolean
-meta_egl_query_dma_buf_modifiers (MetaEgl *egl,
- EGLDisplay display,
- EGLint format,
- EGLint max_modifiers,
- EGLuint64KHR *modifiers,
- EGLBoolean *external_only,
- EGLint *num_modifiers,
- GError **error)
-{
- if (!is_egl_proc_valid (egl->eglQueryDmaBufModifiersEXT, error))
- return FALSE;
-
- if (!egl->eglQueryDmaBufModifiersEXT (display, format, max_modifiers,
- modifiers, external_only,
- num_modifiers))
- {
- set_egl_error (error);
- return FALSE;
- }
-
- return TRUE;
-}
-
-#define GET_EGL_PROC_ADDR(proc) \
- egl->proc = (void *) eglGetProcAddress (#proc);
-
-static void
-meta_egl_constructed (GObject *object)
-{
- MetaEgl *egl = META_EGL (object);
-
- GET_EGL_PROC_ADDR (eglGetPlatformDisplayEXT);
-
- GET_EGL_PROC_ADDR (eglCreateImageKHR);
- GET_EGL_PROC_ADDR (eglDestroyImageKHR);
-
- GET_EGL_PROC_ADDR (eglBindWaylandDisplayWL);
- GET_EGL_PROC_ADDR (eglQueryWaylandBufferWL);
-
- GET_EGL_PROC_ADDR (eglQueryDevicesEXT);
- GET_EGL_PROC_ADDR (eglQueryDeviceStringEXT);
-
- GET_EGL_PROC_ADDR (eglGetOutputLayersEXT);
- GET_EGL_PROC_ADDR (eglQueryOutputLayerAttribEXT);
-
- GET_EGL_PROC_ADDR (eglCreateStreamKHR);
- GET_EGL_PROC_ADDR (eglDestroyStreamKHR);
- GET_EGL_PROC_ADDR (eglQueryStreamKHR);
-
- GET_EGL_PROC_ADDR (eglCreateStreamAttribNV);
-
- GET_EGL_PROC_ADDR (eglCreateStreamProducerSurfaceKHR);
-
- GET_EGL_PROC_ADDR (eglStreamConsumerOutputEXT);
-
- GET_EGL_PROC_ADDR (eglStreamConsumerGLTextureExternalKHR);
-
- GET_EGL_PROC_ADDR (eglStreamConsumerAcquireKHR);
- GET_EGL_PROC_ADDR (eglStreamConsumerAcquireAttribNV);
-
- GET_EGL_PROC_ADDR (eglQueryDmaBufFormatsEXT);
- GET_EGL_PROC_ADDR (eglQueryDmaBufModifiersEXT);
-}
-
-#undef GET_EGL_PROC_ADDR
-
-static void
-meta_egl_init (MetaEgl *egl)
-{
-}
-
-static void
-meta_egl_class_init (MetaEglClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- object_class->constructed = meta_egl_constructed;
-}
diff --git a/src/backends/meta-egl.h b/src/backends/meta-egl.h
deleted file mode 100644
index e108e714a..000000000
--- a/src/backends/meta-egl.h
+++ /dev/null
@@ -1,272 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2016 Red Hat Inc.
- * Copyright (C) 2019 DisplayLink (UK) Ltd.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Written by:
- * Jonas Ådahl <jadahl@gmail.com>
- */
-
-#ifndef META_EGL_H
-#define META_EGL_H
-
-#include <EGL/egl.h>
-#include <EGL/eglext.h>
-#include <EGL/eglmesaext.h>
-#include <glib-object.h>
-
-#define META_EGL_ERROR meta_egl_error_quark ()
-
-#define META_TYPE_EGL (meta_egl_get_type ())
-G_DECLARE_FINAL_TYPE (MetaEgl, meta_egl, META, EGL, GObject)
-
-GQuark meta_egl_error_quark (void);
-
-gboolean
-meta_extensions_string_has_extensions_valist (const char *extensions_str,
- const char ***missing_extensions,
- const char *first_extension,
- va_list var_args);
-
-gboolean meta_egl_has_extensions (MetaEgl *egl,
- EGLDisplay display,
- const char ***missing_extensions,
- const char *first_extension,
- ...);
-
-gboolean meta_egl_initialize (MetaEgl *egl,
- EGLDisplay display,
- GError **error);
-
-gboolean meta_egl_bind_api (MetaEgl *egl,
- EGLenum api,
- GError **error);
-
-gpointer meta_egl_get_proc_address (MetaEgl *egl,
- const char *procname,
- GError **error);
-
-gboolean meta_egl_choose_first_config (MetaEgl *egl,
- EGLDisplay display,
- const EGLint *attrib_list,
- EGLConfig *chosen_config,
- GError **error);
-
-gboolean meta_egl_get_config_attrib (MetaEgl *egl,
- EGLDisplay display,
- EGLConfig config,
- EGLint attribute,
- EGLint *value,
- GError **error);
-
-EGLConfig * meta_egl_choose_all_configs (MetaEgl *egl,
- EGLDisplay display,
- const EGLint *attrib_list,
- EGLint *out_num_configs,
- GError **error);
-
-EGLContext meta_egl_create_context (MetaEgl *egl,
- EGLDisplay display,
- EGLConfig config,
- EGLContext share_context,
- const EGLint *attrib_list,
- GError **error);
-
-gboolean meta_egl_destroy_context (MetaEgl *egl,
- EGLDisplay display,
- EGLContext context,
- GError **error);
-
-EGLImageKHR meta_egl_create_image (MetaEgl *egl,
- EGLDisplay display,
- EGLContext context,
- EGLenum target,
- EGLClientBuffer buffer,
- const EGLint *attrib_list,
- GError **error);
-
-gboolean meta_egl_destroy_image (MetaEgl *egl,
- EGLDisplay display,
- EGLImageKHR image,
- GError **error);
-
-EGLImageKHR meta_egl_create_dmabuf_image (MetaEgl *egl,
- EGLDisplay egl_display,
- unsigned int width,
- unsigned int height,
- uint32_t drm_format,
- uint32_t n_planes,
- const int *fds,
- const uint32_t *strides,
- const uint32_t *offsets,
- const uint64_t *modifiers,
- GError **error);
-
-EGLSurface meta_egl_create_window_surface (MetaEgl *egl,
- EGLDisplay display,
- EGLConfig config,
- EGLNativeWindowType native_window_type,
- const EGLint *attrib_list,
- GError **error);
-
-EGLSurface meta_egl_create_pbuffer_surface (MetaEgl *egl,
- EGLDisplay display,
- EGLConfig config,
- const EGLint *attrib_list,
- GError **error);
-
-gboolean meta_egl_destroy_surface (MetaEgl *egl,
- EGLDisplay display,
- EGLSurface surface,
- GError **error);
-
-EGLDisplay meta_egl_get_platform_display (MetaEgl *egl,
- EGLenum platform,
- void *native_display,
- const EGLint *attrib_list,
- GError **error);
-
-gboolean meta_egl_terminate (MetaEgl *egl,
- EGLDisplay display,
- GError **error);
-
-gboolean meta_egl_make_current (MetaEgl *egl,
- EGLDisplay display,
- EGLSurface draw,
- EGLSurface read,
- EGLContext context,
- GError **error);
-
-gboolean meta_egl_swap_buffers (MetaEgl *egl,
- EGLDisplay display,
- EGLSurface surface,
- GError **error);
-
-gboolean meta_egl_bind_wayland_display (MetaEgl *egl,
- EGLDisplay display,
- struct wl_display *wayland_display,
- GError **error);
-
-gboolean meta_egl_query_wayland_buffer (MetaEgl *egl,
- EGLDisplay display,
- struct wl_resource *buffer,
- EGLint attribute,
- EGLint *value,
- GError **error);
-
-gboolean meta_egl_query_devices (MetaEgl *egl,
- EGLint max_devices,
- EGLDeviceEXT *devices,
- EGLint *num_devices,
- GError **error);
-
-const char * meta_egl_query_device_string (MetaEgl *egl,
- EGLDeviceEXT device,
- EGLint name,
- GError **error);
-
-gboolean meta_egl_egl_device_has_extensions (MetaEgl *egl,
- EGLDeviceEXT device,
- const char ***missing_extensions,
- const char *first_extension,
- ...);
-
-gboolean meta_egl_get_output_layers (MetaEgl *egl,
- EGLDisplay display,
- const EGLAttrib *attrib_list,
- EGLOutputLayerEXT *layers,
- EGLint max_layers,
- EGLint *num_layers,
- GError **error);
-
-gboolean meta_egl_query_output_layer_attrib (MetaEgl *egl,
- EGLDisplay display,
- EGLOutputLayerEXT layer,
- EGLint attribute,
- EGLAttrib *value,
- GError **error);
-
-EGLStreamKHR meta_egl_create_stream (MetaEgl *egl,
- EGLDisplay display,
- const EGLint *attrib_list,
- GError **error);
-
-gboolean meta_egl_destroy_stream (MetaEgl *egl,
- EGLDisplay display,
- EGLStreamKHR stream,
- GError **error);
-
-gboolean meta_egl_query_stream (MetaEgl *egl,
- EGLDisplay display,
- EGLStreamKHR stream,
- EGLenum attribute,
- EGLint *value,
- GError **error);
-
-EGLStreamKHR meta_egl_create_stream_attrib (MetaEgl *egl,
- EGLDisplay display,
- const EGLAttrib *attrib_list,
- GError **error);
-
-EGLSurface meta_egl_create_stream_producer_surface (MetaEgl *egl,
- EGLDisplay display,
- EGLConfig config,
- EGLStreamKHR stream,
- const EGLint *attrib_list,
- GError **error);
-
-gboolean meta_egl_stream_consumer_output (MetaEgl *egl,
- EGLDisplay display,
- EGLStreamKHR stream,
- EGLOutputLayerEXT layer,
- GError **error);
-
-gboolean meta_egl_stream_consumer_acquire_attrib (MetaEgl *egl,
- EGLDisplay display,
- EGLStreamKHR stream,
- EGLAttrib *attrib_list,
- GError **error);
-
-gboolean meta_egl_stream_consumer_acquire (MetaEgl *egl,
- EGLDisplay display,
- EGLStreamKHR stream,
- GError **error);
-
-gboolean meta_egl_stream_consumer_gl_texture_external (MetaEgl *egl,
- EGLDisplay display,
- EGLStreamKHR stream,
- GError **error);
-
-gboolean meta_egl_query_dma_buf_formats (MetaEgl *egl,
- EGLDisplay display,
- EGLint max_formats,
- EGLint *formats,
- EGLint *num_formats,
- GError **error);
-
-gboolean meta_egl_query_dma_buf_modifiers (MetaEgl *egl,
- EGLDisplay display,
- EGLint format,
- EGLint max_modifiers,
- EGLuint64KHR *modifiers,
- EGLBoolean *external_only,
- EGLint *num_formats,
- GError **error);
-
-#endif /* META_EGL_H */
diff --git a/src/backends/meta-gles3-table.h b/src/backends/meta-gles3-table.h
deleted file mode 100644
index 4cc866060..000000000
--- a/src/backends/meta-gles3-table.h
+++ /dev/null
@@ -1,36 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2017 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- */
-
-#ifndef META_GLES3_TABLE_H
-#define META_GLES3_TABLE_H
-
-#include <GLES2/gl2.h>
-#include <GLES2/gl2ext.h>
-#include <GLES3/gl3.h>
-
-typedef struct _MetaGles3Table
-{
- void (* glEGLImageTargetTexture2DOES) (GLenum target,
- GLeglImageOES image);
-} MetaGles3Table;
-
-#endif /* META_GLES3_TABLE */
diff --git a/src/backends/meta-gles3.c b/src/backends/meta-gles3.c
deleted file mode 100644
index 727b3c125..000000000
--- a/src/backends/meta-gles3.c
+++ /dev/null
@@ -1,163 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2017 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- */
-#include <stdio.h>
-
-#include "config.h"
-
-#include "backends/meta-gles3.h"
-
-#include <dlfcn.h>
-#include <gio/gio.h>
-
-#include "backends/meta-gles3-table.h"
-
-struct _MetaGles3
-{
- GObject parent;
-
- MetaEgl *egl;
-
- MetaGles3Table table;
-};
-
-G_DEFINE_TYPE (MetaGles3, meta_gles3, G_TYPE_OBJECT)
-
-MetaGles3Table *
-meta_gles3_get_table (MetaGles3 *gles3)
-{
- return &gles3->table;
-}
-
-void
-meta_gles3_ensure_loaded (MetaGles3 *gles3,
- gpointer *func,
- const char *name)
-{
- GError *error = NULL;
-
- if (*func)
- return;
-
- *func = meta_egl_get_proc_address (gles3->egl, name, &error);
- if (!*func)
- g_error ("Failed to load GLES3 symbol: %s", error->message);
-}
-
-static const char *
-get_gl_error_str (GLenum gl_error)
-{
- switch (gl_error)
- {
- case GL_NO_ERROR:
- return "No error has been recorded.";
- case GL_INVALID_ENUM:
- return "An unacceptable value is specified for an enumerated argument.";
- case GL_INVALID_VALUE:
- return "A numeric argument is out of range.";
- case GL_INVALID_OPERATION:
- return "The specified operation is not allowed in the current state.";
- case GL_INVALID_FRAMEBUFFER_OPERATION:
- return "The framebuffer object is not complete.";
- case GL_OUT_OF_MEMORY:
- return "There is not enough memory left to execute the command.";
- default:
- return "Unknown error";
- }
-}
-
-void
-meta_gles3_clear_error (MetaGles3 *gles3)
-{
- while (TRUE)
- {
- GLenum gl_error = glGetError ();
-
- if (gl_error == GL_NO_ERROR)
- break;
- }
-}
-
-gboolean
-meta_gles3_validate (MetaGles3 *gles3,
- GError **error)
-{
- GLenum gl_error;
-
- gl_error = glGetError ();
- if (gl_error != GL_NO_ERROR)
- {
- g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- get_gl_error_str (gl_error));
- return FALSE;
- }
-
- return TRUE;
-}
-
-gboolean
-meta_gles3_has_extensions (MetaGles3 *gles3,
- const char ***missing_extensions,
- const char *first_extension,
- ...)
-{
- va_list var_args;
- const char *extensions_str;
- gboolean has_extensions;
-
- extensions_str = (const char *) glGetString (GL_EXTENSIONS);
- if (!extensions_str)
- {
- g_warning ("Failed to get string: %s", get_gl_error_str (glGetError ()));
- return FALSE;
- }
-
- va_start (var_args, first_extension);
- has_extensions =
- meta_extensions_string_has_extensions_valist (extensions_str,
- missing_extensions,
- first_extension,
- var_args);
- va_end (var_args);
-
- return has_extensions;
-}
-
-MetaGles3 *
-meta_gles3_new (MetaEgl *egl)
-{
- MetaGles3 *gles3;
-
- gles3 = g_object_new (META_TYPE_GLES3, NULL);
- gles3->egl = egl;
-
- return gles3;
-}
-
-static void
-meta_gles3_init (MetaGles3 *gles3)
-{
-}
-
-static void
-meta_gles3_class_init (MetaGles3Class *klass)
-{
-}
diff --git a/src/backends/meta-gles3.h b/src/backends/meta-gles3.h
deleted file mode 100644
index 89206cc8f..000000000
--- a/src/backends/meta-gles3.h
+++ /dev/null
@@ -1,83 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2017 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- */
-
-#ifndef META_GLES3_H
-#define META_GLES3_H
-
-#include <glib-object.h>
-
-#include "backends/meta-egl.h"
-
-typedef struct _MetaGles3Table MetaGles3Table;
-
-#define META_TYPE_GLES3 (meta_gles3_get_type ())
-G_DECLARE_FINAL_TYPE (MetaGles3, meta_gles3, META, GLES3, GObject)
-
-MetaGles3Table * meta_gles3_get_table (MetaGles3 *gles3);
-
-void meta_gles3_clear_error (MetaGles3 *gles3);
-
-gboolean meta_gles3_validate (MetaGles3 *gles3,
- GError **error);
-
-void meta_gles3_ensure_loaded (MetaGles3 *gles,
- gpointer *func,
- const char *name);
-
-gboolean meta_gles3_has_extensions (MetaGles3 *gles3,
- const char ***missing_extensions,
- const char *first_extension,
- ...);
-
-MetaGles3 * meta_gles3_new (MetaEgl *egl);
-
-#define GLBAS(gles3, func, args) \
-{ \
- GError *_error = NULL; \
- \
- func args; \
- \
- if (!meta_gles3_validate (gles3, &_error)) \
- { \
- g_warning ("%s %s failed: %s", #func, #args, _error->message); \
- g_error_free (_error); \
- } \
-}
-
-#define GLEXT(gles3, func, args) \
-{ \
- GError *_error = NULL; \
- MetaGles3Table *table; \
- \
- table = meta_gles3_get_table (gles3); \
- meta_gles3_ensure_loaded (gles3, (gpointer *) &table->func, #func); \
- \
- table->func args; \
- \
- if (!meta_gles3_validate (gles3, &_error)) \
- { \
- g_warning ("%s %s failed: %s", #func, #args, _error->message); \
- g_error_free (_error); \
- } \
-}
-
-#endif /* META_GLES3_H */
diff --git a/src/backends/meta-gpu.c b/src/backends/meta-gpu.c
deleted file mode 100644
index ce4353bf0..000000000
--- a/src/backends/meta-gpu.c
+++ /dev/null
@@ -1,226 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2017 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-
-#include "config.h"
-
-#include "backends/meta-gpu.h"
-
-#include "backends/meta-backend-private.h"
-#include "backends/meta-output.h"
-
-enum
-{
- PROP_0,
-
- PROP_BACKEND,
-
- PROP_LAST
-};
-
-static GParamSpec *obj_props[PROP_LAST];
-
-typedef struct _MetaGpuPrivate
-{
- MetaBackend *backend;
-
- GList *outputs;
- GList *crtcs;
- GList *modes;
-} MetaGpuPrivate;
-
-G_DEFINE_TYPE_WITH_PRIVATE (MetaGpu, meta_gpu, G_TYPE_OBJECT)
-
-gboolean
-meta_gpu_has_hotplug_mode_update (MetaGpu *gpu)
-{
- MetaGpuPrivate *priv = meta_gpu_get_instance_private (gpu);
- GList *l;
-
- for (l = priv->outputs; l; l = l->next)
- {
- MetaOutput *output = l->data;
- const MetaOutputInfo *output_info = meta_output_get_info (output);
-
- if (output_info->hotplug_mode_update)
- return TRUE;
- }
-
- return FALSE;
-}
-
-gboolean
-meta_gpu_read_current (MetaGpu *gpu,
- GError **error)
-{
- MetaGpuPrivate *priv = meta_gpu_get_instance_private (gpu);
- gboolean ret;
- GList *old_outputs;
- GList *old_crtcs;
- GList *old_modes;
-
- /* TODO: Get rid of this when objects incref:s what they need instead */
- old_outputs = priv->outputs;
- old_crtcs = priv->crtcs;
- old_modes = priv->modes;
-
- ret = META_GPU_GET_CLASS (gpu)->read_current (gpu, error);
-
- g_list_free_full (old_outputs, g_object_unref);
- g_list_free_full (old_modes, g_object_unref);
- g_list_free_full (old_crtcs, g_object_unref);
-
- return ret;
-}
-
-MetaBackend *
-meta_gpu_get_backend (MetaGpu *gpu)
-{
- MetaGpuPrivate *priv = meta_gpu_get_instance_private (gpu);
-
- return priv->backend;
-}
-
-GList *
-meta_gpu_get_outputs (MetaGpu *gpu)
-{
- MetaGpuPrivate *priv = meta_gpu_get_instance_private (gpu);
-
- return priv->outputs;
-}
-
-GList *
-meta_gpu_get_crtcs (MetaGpu *gpu)
-{
- MetaGpuPrivate *priv = meta_gpu_get_instance_private (gpu);
-
- return priv->crtcs;
-}
-
-GList *
-meta_gpu_get_modes (MetaGpu *gpu)
-{
- MetaGpuPrivate *priv = meta_gpu_get_instance_private (gpu);
-
- return priv->modes;
-}
-
-void
-meta_gpu_take_outputs (MetaGpu *gpu,
- GList *outputs)
-{
- MetaGpuPrivate *priv = meta_gpu_get_instance_private (gpu);
-
- priv->outputs = outputs;
-}
-
-void
-meta_gpu_take_crtcs (MetaGpu *gpu,
- GList *crtcs)
-{
- MetaGpuPrivate *priv = meta_gpu_get_instance_private (gpu);
-
- priv->crtcs = crtcs;
-}
-
-void
-meta_gpu_take_modes (MetaGpu *gpu,
- GList *modes)
-{
- MetaGpuPrivate *priv = meta_gpu_get_instance_private (gpu);
-
- priv->modes = modes;
-}
-
-static void
-meta_gpu_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- MetaGpu *gpu = META_GPU (object);
- MetaGpuPrivate *priv = meta_gpu_get_instance_private (gpu);
-
- switch (prop_id)
- {
- case PROP_BACKEND:
- priv->backend = g_value_get_object (value);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- }
-}
-
-static void
-meta_gpu_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- MetaGpu *gpu = META_GPU (object);
- MetaGpuPrivate *priv = meta_gpu_get_instance_private (gpu);
-
- switch (prop_id)
- {
- case PROP_BACKEND:
- g_value_set_object (value, priv->backend);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- }
-}
-
-static void
-meta_gpu_finalize (GObject *object)
-{
- MetaGpu *gpu = META_GPU (object);
- MetaGpuPrivate *priv = meta_gpu_get_instance_private (gpu);
-
- g_list_free_full (priv->outputs, g_object_unref);
- g_list_free_full (priv->modes, g_object_unref);
- g_list_free_full (priv->crtcs, g_object_unref);
-
- G_OBJECT_CLASS (meta_gpu_parent_class)->finalize (object);
-}
-
-static void
-meta_gpu_init (MetaGpu *gpu)
-{
-}
-
-static void
-meta_gpu_class_init (MetaGpuClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- object_class->set_property = meta_gpu_set_property;
- object_class->get_property = meta_gpu_get_property;
- object_class->finalize = meta_gpu_finalize;
-
- obj_props[PROP_BACKEND] =
- g_param_spec_object ("backend",
- "backend",
- "MetaBackend",
- META_TYPE_BACKEND,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT_ONLY |
- G_PARAM_STATIC_STRINGS);
- g_object_class_install_properties (object_class, PROP_LAST, obj_props);
-}
diff --git a/src/backends/meta-gpu.h b/src/backends/meta-gpu.h
deleted file mode 100644
index 9d12f95a7..000000000
--- a/src/backends/meta-gpu.h
+++ /dev/null
@@ -1,72 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2017 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-
-#ifndef META_GPU_H
-#define META_GPU_H
-
-#include <glib-object.h>
-
-#include "backends/meta-monitor-manager-private.h"
-
-#define META_TYPE_GPU (meta_gpu_get_type ())
-META_EXPORT_TEST
-G_DECLARE_DERIVABLE_TYPE (MetaGpu, meta_gpu, META, GPU, GObject)
-
-struct _MetaGpuClass
-{
- GObjectClass parent_class;
-
- gboolean (* read_current) (MetaGpu *gpu,
- GError **error);
-};
-
-META_EXPORT_TEST
-gboolean meta_gpu_read_current (MetaGpu *gpu,
- GError **error);
-
-META_EXPORT_TEST
-gboolean meta_gpu_has_hotplug_mode_update (MetaGpu *gpu);
-
-META_EXPORT_TEST
-MetaBackend * meta_gpu_get_backend (MetaGpu *gpu);
-
-META_EXPORT_TEST
-GList * meta_gpu_get_outputs (MetaGpu *gpu);
-
-META_EXPORT_TEST
-GList * meta_gpu_get_crtcs (MetaGpu *gpu);
-
-META_EXPORT_TEST
-GList * meta_gpu_get_modes (MetaGpu *gpu);
-
-META_EXPORT_TEST
-void meta_gpu_take_outputs (MetaGpu *gpu,
- GList *outputs);
-
-META_EXPORT_TEST
-void meta_gpu_take_crtcs (MetaGpu *gpu,
- GList *crtcs);
-
-META_EXPORT_TEST
-void meta_gpu_take_modes (MetaGpu *gpu,
- GList *modes);
-
-#endif /* META_GPU_H */
diff --git a/src/backends/meta-idle-manager.c b/src/backends/meta-idle-manager.c
deleted file mode 100644
index 92ba0a237..000000000
--- a/src/backends/meta-idle-manager.c
+++ /dev/null
@@ -1,379 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright 2013-2021 Red Hat, Inc.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, see <http://www.gnu.org/licenses/>.
- *
- * Adapted from gnome-session/gnome-session/gs-idle-monitor.c and
- * from gnome-desktop/libgnome-desktop/gnome-idle-monitor.c
- */
-
-#include "config.h"
-
-#include "backends/meta-idle-manager.h"
-
-#include "backends/meta-idle-monitor-private.h"
-#include "clutter/clutter.h"
-#include "meta/main.h"
-#include "meta/meta-context.h"
-#include "meta/meta-idle-monitor.h"
-#include "meta/util.h"
-
-#include "meta-dbus-idle-monitor.h"
-
-typedef struct _MetaIdleManager
-{
- MetaBackend *backend;
- guint dbus_name_id;
-
- GHashTable *device_monitors;
-} MetaIdleManager;
-
-static gboolean
-handle_get_idletime (MetaDBusIdleMonitor *skeleton,
- GDBusMethodInvocation *invocation,
- MetaIdleMonitor *monitor)
-{
- guint64 idletime;
-
- idletime = meta_idle_monitor_get_idletime (monitor);
- meta_dbus_idle_monitor_complete_get_idletime (skeleton, invocation, idletime);
-
- return TRUE;
-}
-
-static gboolean
-handle_reset_idletime (MetaDBusIdleMonitor *skeleton,
- GDBusMethodInvocation *invocation,
- MetaIdleMonitor *monitor)
-{
- if (!g_getenv ("MUTTER_DEBUG_RESET_IDLETIME"))
- {
- g_dbus_method_invocation_return_error_literal (invocation,
- G_DBUS_ERROR,
- G_DBUS_ERROR_UNKNOWN_METHOD,
- "This method is for testing purposes only. MUTTER_DEBUG_RESET_IDLETIME must be set to use it");
- return TRUE;
- }
-
- meta_idle_manager_reset_idle_time (meta_idle_monitor_get_manager (monitor));
- meta_dbus_idle_monitor_complete_reset_idletime (skeleton, invocation);
-
- return TRUE;
-}
-
-typedef struct {
- MetaDBusIdleMonitor *dbus_monitor;
- MetaIdleMonitor *monitor;
- char *dbus_name;
- guint watch_id;
- guint name_watcher_id;
-} DBusWatch;
-
-static void
-destroy_dbus_watch (gpointer data)
-{
- DBusWatch *watch = data;
-
- g_object_unref (watch->dbus_monitor);
- g_object_unref (watch->monitor);
- g_free (watch->dbus_name);
- g_bus_unwatch_name (watch->name_watcher_id);
-
- g_free (watch);
-}
-
-static void
-dbus_idle_callback (MetaIdleMonitor *monitor,
- guint watch_id,
- gpointer user_data)
-{
- DBusWatch *watch = user_data;
- GDBusInterfaceSkeleton *skeleton = G_DBUS_INTERFACE_SKELETON (watch->dbus_monitor);
-
- g_dbus_connection_emit_signal (g_dbus_interface_skeleton_get_connection (skeleton),
- watch->dbus_name,
- g_dbus_interface_skeleton_get_object_path (skeleton),
- "org.gnome.Mutter.IdleMonitor",
- "WatchFired",
- g_variant_new ("(u)", watch_id),
- NULL);
-}
-
-static void
-name_vanished_callback (GDBusConnection *connection,
- const char *name,
- gpointer user_data)
-{
- DBusWatch *watch = user_data;
-
- meta_idle_monitor_remove_watch (watch->monitor, watch->watch_id);
-}
-
-static DBusWatch *
-make_dbus_watch (MetaDBusIdleMonitor *skeleton,
- GDBusMethodInvocation *invocation,
- MetaIdleMonitor *monitor)
-{
- DBusWatch *watch;
-
- watch = g_new0 (DBusWatch, 1);
- watch->dbus_monitor = g_object_ref (skeleton);
- watch->monitor = g_object_ref (monitor);
- watch->dbus_name = g_strdup (g_dbus_method_invocation_get_sender (invocation));
- watch->name_watcher_id = g_bus_watch_name_on_connection (g_dbus_method_invocation_get_connection (invocation),
- watch->dbus_name,
- G_BUS_NAME_WATCHER_FLAGS_NONE,
- NULL, /* appeared */
- name_vanished_callback,
- watch, NULL);
-
- return watch;
-}
-
-static gboolean
-handle_add_idle_watch (MetaDBusIdleMonitor *skeleton,
- GDBusMethodInvocation *invocation,
- guint64 interval,
- MetaIdleMonitor *monitor)
-{
- DBusWatch *watch;
-
- watch = make_dbus_watch (skeleton, invocation, monitor);
- watch->watch_id = meta_idle_monitor_add_idle_watch (monitor, interval,
- dbus_idle_callback, watch, destroy_dbus_watch);
-
- meta_dbus_idle_monitor_complete_add_idle_watch (skeleton, invocation, watch->watch_id);
-
- return TRUE;
-}
-
-static gboolean
-handle_add_user_active_watch (MetaDBusIdleMonitor *skeleton,
- GDBusMethodInvocation *invocation,
- MetaIdleMonitor *monitor)
-{
- DBusWatch *watch;
-
- watch = make_dbus_watch (skeleton, invocation, monitor);
- watch->watch_id = meta_idle_monitor_add_user_active_watch (monitor,
- dbus_idle_callback, watch,
- destroy_dbus_watch);
-
- meta_dbus_idle_monitor_complete_add_user_active_watch (skeleton, invocation, watch->watch_id);
-
- return TRUE;
-}
-
-static gboolean
-handle_remove_watch (MetaDBusIdleMonitor *skeleton,
- GDBusMethodInvocation *invocation,
- guint id,
- MetaIdleMonitor *monitor)
-{
- meta_idle_monitor_remove_watch (monitor, id);
- meta_dbus_idle_monitor_complete_remove_watch (skeleton, invocation);
-
- return TRUE;
-}
-
-static void
-create_monitor_skeleton (GDBusObjectManagerServer *manager,
- MetaIdleMonitor *monitor,
- const char *path)
-{
- MetaDBusIdleMonitor *skeleton;
- MetaDBusObjectSkeleton *object;
-
- skeleton = meta_dbus_idle_monitor_skeleton_new ();
- g_signal_connect (skeleton, "handle-add-idle-watch",
- G_CALLBACK (handle_add_idle_watch), monitor);
- g_signal_connect (skeleton, "handle-add-user-active-watch",
- G_CALLBACK (handle_add_user_active_watch), monitor);
- g_signal_connect (skeleton, "handle-remove-watch",
- G_CALLBACK (handle_remove_watch), monitor);
- g_signal_connect (skeleton, "handle-reset-idletime",
- G_CALLBACK (handle_reset_idletime), monitor);
- g_signal_connect (skeleton, "handle-get-idletime",
- G_CALLBACK (handle_get_idletime), monitor);
-
- object = meta_dbus_object_skeleton_new (path);
- meta_dbus_object_skeleton_set_idle_monitor (object, skeleton);
-
- g_dbus_object_manager_server_export (manager, G_DBUS_OBJECT_SKELETON (object));
-
- g_object_unref (skeleton);
- g_object_unref (object);
-}
-
-static void
-on_bus_acquired (GDBusConnection *connection,
- const char *name,
- gpointer user_data)
-{
- MetaIdleManager *manager = user_data;
- GDBusObjectManagerServer *object_manager;
- MetaIdleMonitor *monitor;
- char *path;
-
- object_manager = g_dbus_object_manager_server_new ("/org/gnome/Mutter/IdleMonitor");
-
- /* We never clear the core monitor, as that's supposed to cumulate idle times from
- all devices */
- monitor = meta_idle_manager_get_core_monitor (manager);
- path = g_strdup ("/org/gnome/Mutter/IdleMonitor/Core");
- create_monitor_skeleton (object_manager, monitor, path);
- g_free (path);
-
- g_dbus_object_manager_server_set_connection (object_manager, connection);
-}
-
-static void
-on_name_acquired (GDBusConnection *connection,
- const char *name,
- gpointer user_data)
-{
- meta_verbose ("Acquired name %s", name);
-}
-
-static void
-on_name_lost (GDBusConnection *connection,
- const char *name,
- gpointer user_data)
-{
- meta_verbose ("Lost or failed to acquire name %s", name);
-}
-
-MetaIdleMonitor *
-meta_idle_manager_get_monitor (MetaIdleManager *idle_manager,
- ClutterInputDevice *device)
-{
- return g_hash_table_lookup (idle_manager->device_monitors, device);
-}
-
-MetaIdleMonitor *
-meta_idle_manager_get_core_monitor (MetaIdleManager *idle_manager)
-{
- MetaBackend *backend = meta_get_backend ();
- ClutterBackend *clutter_backend = meta_backend_get_clutter_backend (backend);
- ClutterSeat *seat = clutter_backend_get_default_seat (clutter_backend);
-
- return meta_backend_get_idle_monitor (backend,
- clutter_seat_get_pointer (seat));
-}
-
-void
-meta_idle_manager_reset_idle_time (MetaIdleManager *idle_manager)
-{
- MetaIdleMonitor *core_monitor;
-
- core_monitor = meta_idle_manager_get_core_monitor (idle_manager);
- meta_idle_monitor_reset_idletime (core_monitor);
-}
-
-static void
-create_device_monitor (MetaIdleManager *idle_manager,
- ClutterInputDevice *device)
-{
- MetaIdleMonitor *idle_monitor;
-
- if (g_hash_table_contains (idle_manager->device_monitors, device))
- return;
-
- idle_monitor = meta_idle_monitor_new (idle_manager, device);
- g_hash_table_insert (idle_manager->device_monitors, device, idle_monitor);
-}
-
-static void
-on_device_added (ClutterSeat *seat,
- ClutterInputDevice *device,
- gpointer user_data)
-{
- MetaIdleManager *idle_manager = user_data;
-
- create_device_monitor (idle_manager, device);
-}
-
-static void
-on_device_removed (ClutterSeat *seat,
- ClutterInputDevice *device,
- gpointer user_data)
-{
- MetaIdleManager *idle_manager = user_data;
-
- g_hash_table_remove (idle_manager->device_monitors, device);
-}
-
-static void
-create_device_monitors (MetaIdleManager *idle_manager,
- ClutterSeat *seat)
-{
- GList *l, *devices;
-
- create_device_monitor (idle_manager, clutter_seat_get_pointer (seat));
- create_device_monitor (idle_manager, clutter_seat_get_keyboard (seat));
-
- devices = clutter_seat_list_devices (seat);
- for (l = devices; l; l = l->next)
- {
- ClutterInputDevice *device = l->data;
-
- create_device_monitor (idle_manager, device);
- }
-
- g_list_free (devices);
-}
-
-MetaIdleManager *
-meta_idle_manager_new (MetaBackend *backend)
-{
- MetaContext *context = meta_backend_get_context (backend);
- ClutterSeat *seat = meta_backend_get_default_seat (backend);
- MetaIdleManager *idle_manager;
-
- idle_manager = g_new0 (MetaIdleManager, 1);
- idle_manager->backend = backend;
-
- idle_manager->dbus_name_id =
- g_bus_own_name (G_BUS_TYPE_SESSION,
- "org.gnome.Mutter.IdleMonitor",
- G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT |
- (meta_context_is_replacing (context) ?
- G_BUS_NAME_OWNER_FLAGS_REPLACE :
- G_BUS_NAME_OWNER_FLAGS_NONE),
- on_bus_acquired,
- on_name_acquired,
- on_name_lost,
- idle_manager,
- NULL);
-
- idle_manager->device_monitors =
- g_hash_table_new_full (NULL, NULL, NULL, (GDestroyNotify) g_object_unref);
- g_signal_connect (seat, "device-added",
- G_CALLBACK (on_device_added), idle_manager);
- g_signal_connect_after (seat, "device-removed",
- G_CALLBACK (on_device_removed), idle_manager);
- create_device_monitors (idle_manager, seat);
-
- return idle_manager;
-}
-
-void
-meta_idle_manager_free (MetaIdleManager *idle_manager)
-{
- g_clear_pointer (&idle_manager->device_monitors, g_hash_table_destroy);
- g_bus_unown_name (idle_manager->dbus_name_id);
- g_free (idle_manager);
-}
diff --git a/src/backends/meta-idle-manager.h b/src/backends/meta-idle-manager.h
deleted file mode 100644
index c2a998feb..000000000
--- a/src/backends/meta-idle-manager.h
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Copyright 2021 Red Hat, Inc.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-#ifndef META_IDLE_MANAGER_H
-#define META_IDLE_MANAGER_H
-
-#include "backends/meta-backend-types.h"
-#include "clutter/clutter.h"
-
-typedef struct _MetaIdleMonitor MetaIdleMonitor;
-typedef struct _MetaIdleManager MetaIdleManager;
-
-MetaIdleMonitor * meta_idle_manager_get_monitor (MetaIdleManager *idle_manager,
- ClutterInputDevice *device);
-
-MetaIdleMonitor * meta_idle_manager_get_core_monitor (MetaIdleManager *idle_manager);
-
-void meta_idle_manager_reset_idle_time (MetaIdleManager *idle_manager);
-
-MetaIdleManager * meta_idle_manager_new (MetaBackend *backend);
-
-void meta_idle_manager_free (MetaIdleManager *idle_manager);
-
-#endif /* META_IDLE_MANAGER_H */
diff --git a/src/backends/meta-idle-monitor-private.h b/src/backends/meta-idle-monitor-private.h
deleted file mode 100644
index 6d4387876..000000000
--- a/src/backends/meta-idle-monitor-private.h
+++ /dev/null
@@ -1,53 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright 2013 Red Hat, Inc.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, see <http://www.gnu.org/licenses/>.
- *
- * Adapted from gnome-session/gnome-session/gs-idle-monitor.c and
- * from gnome-desktop/libgnome-desktop/gnome-idle-monitor.c
- */
-
-#ifndef META_IDLE_MONITOR_PRIVATE_H
-#define META_IDLE_MONITOR_PRIVATE_H
-
-#include "core/display-private.h"
-#include "meta/meta-idle-monitor.h"
-
-typedef struct
-{
- MetaIdleMonitor *monitor;
- guint id;
- MetaIdleMonitorWatchFunc callback;
- gpointer user_data;
- GDestroyNotify notify;
- guint64 timeout_msec;
- int idle_source_id;
- GSource *timeout_source;
-} MetaIdleMonitorWatch;
-
-struct _MetaIdleMonitorClass
-{
- GObjectClass parent_class;
-};
-
-void meta_idle_monitor_reset_idletime (MetaIdleMonitor *monitor);
-
-MetaIdleManager * meta_idle_monitor_get_manager (MetaIdleMonitor *monitor);
-
-MetaIdleMonitor * meta_idle_monitor_new (MetaIdleManager *idle_manager,
- ClutterInputDevice *device);
-
-#endif /* META_IDLE_MONITOR_PRIVATE_H */
diff --git a/src/backends/meta-idle-monitor.c b/src/backends/meta-idle-monitor.c
deleted file mode 100644
index df924d4dd..000000000
--- a/src/backends/meta-idle-monitor.c
+++ /dev/null
@@ -1,530 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright 2013 Red Hat, Inc.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, see <http://www.gnu.org/licenses/>.
- *
- * Adapted from gnome-session/gnome-session/gs-idle-monitor.c and
- * from gnome-desktop/libgnome-desktop/gnome-idle-monitor.c
- */
-
-/**
- * SECTION:idle-monitor
- * @title: MetaIdleMonitor
- * @short_description: Mutter idle counter (similar to X's IDLETIME)
- */
-
-#include "config.h"
-
-#include <string.h>
-#include <X11/Xlib.h>
-#include <X11/extensions/sync.h>
-
-#include "backends/gsm-inhibitor-flag.h"
-#include "backends/meta-backend-private.h"
-#include "backends/meta-idle-monitor-private.h"
-#include "clutter/clutter.h"
-#include "meta/main.h"
-#include "meta/meta-idle-monitor.h"
-#include "meta/util.h"
-
-G_STATIC_ASSERT(sizeof(unsigned long) == sizeof(gpointer));
-
-enum
-{
- PROP_0,
- PROP_DEVICE,
- PROP_LAST,
-};
-
-static GParamSpec *obj_props[PROP_LAST];
-
-struct _MetaIdleMonitor
-{
- GObject parent;
-
- MetaIdleManager *idle_manager;
- GDBusProxy *session_proxy;
- gboolean inhibited;
- GHashTable *watches;
- ClutterInputDevice *device;
- int64_t last_event_time;
-};
-
-G_DEFINE_TYPE (MetaIdleMonitor, meta_idle_monitor, G_TYPE_OBJECT)
-
-static void
-meta_idle_monitor_watch_fire (MetaIdleMonitorWatch *watch)
-{
- MetaIdleMonitor *monitor;
- guint id;
- gboolean is_user_active_watch;
-
- monitor = watch->monitor;
- g_object_ref (monitor);
-
- g_clear_handle_id (&watch->idle_source_id, g_source_remove);
-
- id = watch->id;
- is_user_active_watch = (watch->timeout_msec == 0);
-
- if (watch->callback)
- watch->callback (monitor, id, watch->user_data);
-
- if (is_user_active_watch)
- meta_idle_monitor_remove_watch (monitor, id);
-
- g_object_unref (monitor);
-}
-
-static void
-meta_idle_monitor_dispose (GObject *object)
-{
- MetaIdleMonitor *monitor = META_IDLE_MONITOR (object);
-
- g_clear_pointer (&monitor->watches, g_hash_table_destroy);
- g_clear_object (&monitor->session_proxy);
-
- G_OBJECT_CLASS (meta_idle_monitor_parent_class)->dispose (object);
-}
-
-static void
-meta_idle_monitor_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- MetaIdleMonitor *monitor = META_IDLE_MONITOR (object);
-
- switch (prop_id)
- {
- case PROP_DEVICE:
- g_value_set_object (value, monitor->device);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-
-static void
-meta_idle_monitor_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- MetaIdleMonitor *monitor = META_IDLE_MONITOR (object);
- switch (prop_id)
- {
- case PROP_DEVICE:
- monitor->device = g_value_get_object (value);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-
-static void
-meta_idle_monitor_class_init (MetaIdleMonitorClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- object_class->dispose = meta_idle_monitor_dispose;
- object_class->get_property = meta_idle_monitor_get_property;
- object_class->set_property = meta_idle_monitor_set_property;
-
- /**
- * MetaIdleMonitor:device:
- *
- * The device to listen to idletime on.
- */
- obj_props[PROP_DEVICE] =
- g_param_spec_object ("device",
- "Device",
- "The device to listen to idletime on",
- CLUTTER_TYPE_INPUT_DEVICE,
- G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
-
- g_object_class_install_property (object_class, PROP_DEVICE, obj_props[PROP_DEVICE]);
-}
-
-static void
-free_watch (gpointer data)
-{
- MetaIdleMonitorWatch *watch = (MetaIdleMonitorWatch *) data;
- MetaIdleMonitor *monitor = watch->monitor;
-
- g_object_ref (monitor);
-
- g_clear_handle_id (&watch->idle_source_id, g_source_remove);
-
- if (watch->notify != NULL)
- watch->notify (watch->user_data);
-
- if (watch->timeout_source != NULL)
- g_source_destroy (watch->timeout_source);
-
- g_object_unref (monitor);
- g_free (watch);
-}
-
-static void
-update_inhibited_watch (gpointer key,
- gpointer value,
- gpointer user_data)
-{
- MetaIdleMonitor *monitor = user_data;
- MetaIdleMonitorWatch *watch = value;
-
- if (!watch->timeout_source)
- return;
-
- if (monitor->inhibited)
- {
- g_source_set_ready_time (watch->timeout_source, -1);
- }
- else
- {
- g_source_set_ready_time (watch->timeout_source,
- monitor->last_event_time +
- watch->timeout_msec * 1000);
- }
-}
-
-static void
-update_inhibited (MetaIdleMonitor *monitor,
- gboolean inhibited)
-{
- if (inhibited == monitor->inhibited)
- return;
-
- monitor->inhibited = inhibited;
-
- g_hash_table_foreach (monitor->watches,
- update_inhibited_watch,
- monitor);
-}
-
-static void
-meta_idle_monitor_inhibited_actions_changed (GDBusProxy *session,
- GVariant *changed,
- char **invalidated,
- gpointer user_data)
-{
- MetaIdleMonitor *monitor = user_data;
- GVariant *v;
-
- v = g_variant_lookup_value (changed, "InhibitedActions", G_VARIANT_TYPE_UINT32);
- if (v)
- {
- gboolean inhibited;
-
- inhibited = !!(g_variant_get_uint32 (v) & GSM_INHIBITOR_FLAG_IDLE);
- g_variant_unref (v);
-
- if (!inhibited)
- monitor->last_event_time = g_get_monotonic_time ();
- update_inhibited (monitor, inhibited);
- }
-}
-
-static void
-meta_idle_monitor_init (MetaIdleMonitor *monitor)
-{
- GVariant *v;
-
- monitor->watches = g_hash_table_new_full (NULL, NULL, NULL, free_watch);
- monitor->last_event_time = g_get_monotonic_time ();
-
- /* Monitor inhibitors */
- monitor->session_proxy =
- g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
- G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS |
- G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START,
- NULL,
- "org.gnome.SessionManager",
- "/org/gnome/SessionManager",
- "org.gnome.SessionManager",
- NULL,
- NULL);
- if (!monitor->session_proxy)
- return;
-
- g_signal_connect (monitor->session_proxy, "g-properties-changed",
- G_CALLBACK (meta_idle_monitor_inhibited_actions_changed),
- monitor);
-
- v = g_dbus_proxy_get_cached_property (monitor->session_proxy,
- "InhibitedActions");
- if (v)
- {
- monitor->inhibited = !!(g_variant_get_uint32 (v) &
- GSM_INHIBITOR_FLAG_IDLE);
- g_variant_unref (v);
- }
-}
-
-static guint32
-get_next_watch_serial (void)
-{
- static guint32 serial = 0;
-
- g_atomic_int_inc (&serial);
-
- return serial;
-}
-
-static gboolean
-idle_monitor_dispatch_timeout (GSource *source,
- GSourceFunc callback,
- gpointer user_data)
-{
- MetaIdleMonitorWatch *watch = (MetaIdleMonitorWatch *) user_data;
- int64_t now;
- int64_t ready_time;
-
- now = g_source_get_time (source);
- ready_time = g_source_get_ready_time (source);
- if (ready_time > now)
- return G_SOURCE_CONTINUE;
-
- g_source_set_ready_time (watch->timeout_source, -1);
-
- meta_idle_monitor_watch_fire (watch);
-
- return G_SOURCE_CONTINUE;
-}
-
-static GSourceFuncs idle_monitor_source_funcs = {
- .prepare = NULL,
- .check = NULL,
- .dispatch = idle_monitor_dispatch_timeout,
- .finalize = NULL,
-};
-
-static MetaIdleMonitorWatch *
-make_watch (MetaIdleMonitor *monitor,
- guint64 timeout_msec,
- MetaIdleMonitorWatchFunc callback,
- gpointer user_data,
- GDestroyNotify notify)
-{
- MetaIdleMonitorWatch *watch;
-
- watch = g_new0 (MetaIdleMonitorWatch, 1);
-
- watch->monitor = monitor;
- watch->id = get_next_watch_serial ();
- watch->callback = callback;
- watch->user_data = user_data;
- watch->notify = notify;
- watch->timeout_msec = timeout_msec;
-
- if (timeout_msec != 0)
- {
- GSource *source = g_source_new (&idle_monitor_source_funcs,
- sizeof (GSource));
-
- g_source_set_callback (source, NULL, watch, NULL);
- if (!monitor->inhibited)
- {
- g_source_set_ready_time (source,
- monitor->last_event_time +
- timeout_msec * 1000);
- }
- g_source_attach (source, NULL);
- g_source_unref (source);
-
- watch->timeout_source = source;
- }
-
- g_hash_table_insert (monitor->watches,
- GUINT_TO_POINTER (watch->id),
- watch);
- return watch;
-}
-
-/**
- * meta_idle_monitor_add_idle_watch:
- * @monitor: A #MetaIdleMonitor
- * @interval_msec: The idletime interval, in milliseconds
- * @callback: (nullable): The callback to call when the user has
- * accumulated @interval_msec milliseconds of idle time.
- * @user_data: (nullable): The user data to pass to the callback
- * @notify: A #GDestroyNotify
- *
- * Returns: a watch id
- *
- * Adds a watch for a specific idle time. The callback will be called
- * when the user has accumulated @interval_msec milliseconds of idle time.
- * This function will return an ID that can either be passed to
- * meta_idle_monitor_remove_watch(), or can be used to tell idle time
- * watches apart if you have more than one.
- *
- * Also note that this function will only care about positive transitions
- * (user's idle time exceeding a certain time). If you want to know about
- * when the user has become active, use
- * meta_idle_monitor_add_user_active_watch().
- */
-guint
-meta_idle_monitor_add_idle_watch (MetaIdleMonitor *monitor,
- guint64 interval_msec,
- MetaIdleMonitorWatchFunc callback,
- gpointer user_data,
- GDestroyNotify notify)
-{
- MetaIdleMonitorWatch *watch;
-
- g_return_val_if_fail (META_IS_IDLE_MONITOR (monitor), 0);
- g_return_val_if_fail (interval_msec > 0, 0);
-
- watch = make_watch (monitor,
- interval_msec,
- callback,
- user_data,
- notify);
-
- return watch->id;
-}
-
-/**
- * meta_idle_monitor_add_user_active_watch:
- * @monitor: A #MetaIdleMonitor
- * @callback: (nullable): The callback to call when the user is
- * active again.
- * @user_data: (nullable): The user data to pass to the callback
- * @notify: A #GDestroyNotify
- *
- * Returns: a watch id
- *
- * Add a one-time watch to know when the user is active again.
- * Note that this watch is one-time and will de-activate after the
- * function is called, for efficiency purposes. It's most convenient
- * to call this when an idle watch, as added by
- * meta_idle_monitor_add_idle_watch(), has triggered.
- */
-guint
-meta_idle_monitor_add_user_active_watch (MetaIdleMonitor *monitor,
- MetaIdleMonitorWatchFunc callback,
- gpointer user_data,
- GDestroyNotify notify)
-{
- MetaIdleMonitorWatch *watch;
-
- g_return_val_if_fail (META_IS_IDLE_MONITOR (monitor), 0);
-
- watch = make_watch (monitor,
- 0,
- callback,
- user_data,
- notify);
-
- return watch->id;
-}
-
-/**
- * meta_idle_monitor_remove_watch:
- * @monitor: A #MetaIdleMonitor
- * @id: A watch ID
- *
- * Removes an idle time watcher, previously added by
- * meta_idle_monitor_add_idle_watch() or
- * meta_idle_monitor_add_user_active_watch().
- */
-void
-meta_idle_monitor_remove_watch (MetaIdleMonitor *monitor,
- guint id)
-{
- g_return_if_fail (META_IS_IDLE_MONITOR (monitor));
-
- g_object_ref (monitor);
- g_hash_table_remove (monitor->watches,
- GUINT_TO_POINTER (id));
- g_object_unref (monitor);
-}
-
-/**
- * meta_idle_monitor_get_idletime:
- * @monitor: A #MetaIdleMonitor
- *
- * Returns: The current idle time, in milliseconds, or -1 for not supported
- */
-gint64
-meta_idle_monitor_get_idletime (MetaIdleMonitor *monitor)
-{
- return (g_get_monotonic_time () - monitor->last_event_time) / 1000;
-}
-
-void
-meta_idle_monitor_reset_idletime (MetaIdleMonitor *monitor)
-{
- GList *node, *watch_ids;
-
- monitor->last_event_time = g_get_monotonic_time ();
-
- watch_ids = g_hash_table_get_keys (monitor->watches);
-
- for (node = watch_ids; node != NULL; node = node->next)
- {
- guint watch_id = GPOINTER_TO_UINT (node->data);
- MetaIdleMonitorWatch *watch;
-
- watch = g_hash_table_lookup (monitor->watches,
- GUINT_TO_POINTER (watch_id));
- if (!watch)
- continue;
-
- if (watch->timeout_msec == 0)
- {
- meta_idle_monitor_watch_fire (watch);
- }
- else
- {
- if (monitor->inhibited)
- {
- g_source_set_ready_time (watch->timeout_source, -1);
- }
- else
- {
- g_source_set_ready_time (watch->timeout_source,
- monitor->last_event_time +
- watch->timeout_msec * 1000);
- }
- }
- }
-
- g_list_free (watch_ids);
-}
-
-MetaIdleManager *
-meta_idle_monitor_get_manager (MetaIdleMonitor *monitor)
-{
- return monitor->idle_manager;
-}
-
-MetaIdleMonitor *
-meta_idle_monitor_new (MetaIdleManager *idle_manager,
- ClutterInputDevice *device)
-{
- MetaIdleMonitor *monitor;
-
- monitor = g_object_new (META_TYPE_IDLE_MONITOR,
- "device", device,
- NULL);
- monitor->idle_manager = idle_manager;
-
- return monitor;
-}
diff --git a/src/backends/meta-input-device-private.h b/src/backends/meta-input-device-private.h
deleted file mode 100644
index a2cbd4864..000000000
--- a/src/backends/meta-input-device-private.h
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Copyright © 2020 Red Hat Ltd.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
- *
- * Author: Carlos Garnacho <carlosg@gnome.org>
- */
-#ifndef META_INPUT_DEVICE_H
-#define META_INPUT_DEVICE_H
-
-#include <glib-object.h>
-
-#ifdef HAVE_LIBWACOM
-#include <libwacom/libwacom.h>
-#endif
-
-#include "clutter/clutter-mutter.h"
-
-typedef struct _MetaInputDeviceClass MetaInputDeviceClass;
-typedef struct _MetaInputDevice MetaInputDevice;
-
-struct _MetaInputDeviceClass
-{
- ClutterInputDeviceClass parent_class;
-};
-
-#define META_TYPE_INPUT_DEVICE (meta_input_device_get_type ())
-G_DECLARE_DERIVABLE_TYPE (MetaInputDevice,
- meta_input_device,
- META, INPUT_DEVICE,
- ClutterInputDevice)
-
-#ifdef HAVE_LIBWACOM
-WacomDevice * meta_input_device_get_wacom_device (MetaInputDevice *input_device);
-#endif
-
-#endif /* META_INPUT_DEVICE_H */
diff --git a/src/backends/meta-input-device.c b/src/backends/meta-input-device.c
deleted file mode 100644
index 24f6ef9ae..000000000
--- a/src/backends/meta-input-device.c
+++ /dev/null
@@ -1,138 +0,0 @@
-/*
- * Copyright © 2020 Red Hat Ltd.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
- *
- * Author: Carlos Garnacho <carlosg@gnome.org>
- */
-
-#include "config.h"
-
-#include "backends/meta-backend-private.h"
-#include "meta-input-device-private.h"
-
-typedef struct _MetaInputDevicePrivate MetaInputDevicePrivate;
-
-struct _MetaInputDevicePrivate
-{
-#ifdef HAVE_LIBWACOM
- WacomDevice *wacom_device;
-#else
- /* Just something to have non-zero sized struct otherwise */
- gpointer wacom_device;
-#endif
-};
-
-enum
-{
- PROP_WACOM_DEVICE = 1,
- N_PROPS
-};
-
-static GParamSpec *props[N_PROPS] = { 0 };
-
-G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (MetaInputDevice,
- meta_input_device,
- CLUTTER_TYPE_INPUT_DEVICE)
-
-static void
-meta_input_device_init (MetaInputDevice *input_device)
-{
-}
-
-static void
-meta_input_device_constructed (GObject *object)
-{
-#ifdef HAVE_LIBWACOM
- MetaInputDevice *input_device;
- WacomDeviceDatabase *wacom_db;
- MetaInputDevicePrivate *priv;
- const char *node;
-#endif
-
- G_OBJECT_CLASS (meta_input_device_parent_class)->constructed (object);
-
-#ifdef HAVE_LIBWACOM
- input_device = META_INPUT_DEVICE (object);
- priv = meta_input_device_get_instance_private (input_device);
- wacom_db = meta_backend_get_wacom_database (meta_get_backend ());
- node = clutter_input_device_get_device_node (CLUTTER_INPUT_DEVICE (input_device));
- priv->wacom_device = libwacom_new_from_path (wacom_db, node,
- WFALLBACK_NONE, NULL);
-#endif /* HAVE_LIBWACOM */
-}
-
-static void
-meta_input_device_finalize (GObject *object)
-{
-#ifdef HAVE_LIBWACOM
- MetaInputDevicePrivate *priv;
-
- priv = meta_input_device_get_instance_private (META_INPUT_DEVICE (object));
-
- g_clear_pointer (&priv->wacom_device, libwacom_destroy);
-#endif /* HAVE_LIBWACOM */
-
- G_OBJECT_CLASS (meta_input_device_parent_class)->finalize (object);
-}
-
-static void
-meta_input_device_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- MetaInputDevicePrivate *priv;
-
- priv = meta_input_device_get_instance_private (META_INPUT_DEVICE (object));
-
- switch (prop_id)
- {
- case PROP_WACOM_DEVICE:
- g_value_set_pointer (value, priv->wacom_device);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- }
-}
-
-static void
-meta_input_device_class_init (MetaInputDeviceClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- object_class->constructed = meta_input_device_constructed;
- object_class->finalize = meta_input_device_finalize;
- object_class->get_property = meta_input_device_get_property;
-
- props[PROP_WACOM_DEVICE] =
- g_param_spec_pointer ("wacom-device",
- "Wacom device",
- "Wacom device",
- G_PARAM_READABLE);
-
- g_object_class_install_properties (object_class, N_PROPS, props);
-}
-
-#ifdef HAVE_LIBWACOM
-WacomDevice *
-meta_input_device_get_wacom_device (MetaInputDevice *input_device)
-{
- MetaInputDevicePrivate *priv;
-
- priv = meta_input_device_get_instance_private (input_device);
-
- return priv->wacom_device;
-}
-#endif /* HAVE_LIBWACOM */
diff --git a/src/backends/meta-input-mapper-private.h b/src/backends/meta-input-mapper-private.h
deleted file mode 100644
index 63d480dba..000000000
--- a/src/backends/meta-input-mapper-private.h
+++ /dev/null
@@ -1,52 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright 2018 Red Hat, Inc.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, see <http://www.gnu.org/licenses/>.
- *
- * Author: Carlos Garnacho <carlosg@gnome.org>
- */
-
-#ifndef META_INPUT_MAPPER_H
-#define META_INPUT_MAPPER_H
-
-#include <clutter/clutter.h>
-
-#include "backends/meta-backend-types.h"
-
-#define META_TYPE_INPUT_MAPPER (meta_input_mapper_get_type ())
-
-G_DECLARE_FINAL_TYPE (MetaInputMapper, meta_input_mapper,
- META, INPUT_MAPPER, GObject)
-
-MetaInputMapper * meta_input_mapper_new (void);
-
-void meta_input_mapper_add_device (MetaInputMapper *mapper,
- ClutterInputDevice *device);
-void meta_input_mapper_remove_device (MetaInputMapper *mapper,
- ClutterInputDevice *device);
-
-ClutterInputDevice *
-meta_input_mapper_get_logical_monitor_device (MetaInputMapper *mapper,
- MetaLogicalMonitor *logical_monitor,
- ClutterInputDeviceType device_type);
-MetaLogicalMonitor *
-meta_input_mapper_get_device_logical_monitor (MetaInputMapper *mapper,
- ClutterInputDevice *device);
-
-GSettings * meta_input_mapper_get_tablet_settings (MetaInputMapper *mapper,
- ClutterInputDevice *device);
-
-#endif /* META_INPUT_MAPPER_H */
diff --git a/src/backends/meta-input-mapper.c b/src/backends/meta-input-mapper.c
deleted file mode 100644
index ffbe2dd37..000000000
--- a/src/backends/meta-input-mapper.c
+++ /dev/null
@@ -1,986 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-/*
- * Copyright 2018 Red Hat, Inc.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, see <http://www.gnu.org/licenses/>.
- *
- * Author: Carlos Garnacho <carlosg@gnome.org>
- */
-
-#include "config.h"
-
-#ifdef HAVE_LIBGUDEV
-#include <gudev/gudev.h>
-#endif
-
-#include "backends/meta-input-device-private.h"
-#include "meta-input-mapper-private.h"
-#include "meta-monitor-manager-private.h"
-#include "meta-logical-monitor.h"
-#include "meta-backend-private.h"
-
-#define MAX_SIZE_MATCH_DIFF 0.05
-
-typedef struct _MetaMapperInputInfo MetaMapperInputInfo;
-typedef struct _MetaMapperOutputInfo MetaMapperOutputInfo;
-typedef struct _MappingHelper MappingHelper;
-typedef struct _DeviceCandidates DeviceCandidates;
-typedef struct _DeviceMatch DeviceMatch;
-
-struct _MetaInputMapper
-{
- GObject parent_instance;
- MetaMonitorManager *monitor_manager;
- ClutterSeat *seat;
- GHashTable *input_devices; /* ClutterInputDevice -> MetaMapperInputInfo */
- GHashTable *output_devices; /* MetaLogicalMonitor -> MetaMapperOutputInfo */
-#ifdef HAVE_LIBGUDEV
- GUdevClient *udev_client;
-#endif
-};
-
-typedef enum
-{
- META_INPUT_CAP_TOUCH = 1 << 0, /* touch device, either touchscreen or tablet */
- META_INPUT_CAP_STYLUS = 1 << 1, /* tablet pen */
- META_INPUT_CAP_ERASER = 1 << 2, /* tablet eraser */
- META_INPUT_CAP_PAD = 1 << 3, /* pad device, most usually in tablets */
- META_INPUT_CAP_CURSOR = 1 << 4 /* pointer-like device in tablets */
-} MetaInputCapabilityFlags;
-
-typedef enum
-{
- META_MATCH_EDID_VENDOR, /* EDID vendor match, eg. "WAC" for Wacom */
- META_MATCH_EDID_PARTIAL, /* Partial EDID model match, eg. "Cintiq" */
- META_MATCH_EDID_FULL, /* Full EDID model match, eg. "Cintiq 12WX" */
- META_MATCH_SIZE, /* Size from input device and output match */
- META_MATCH_IS_BUILTIN, /* Output is builtin, applies mainly to system-integrated devices */
- META_MATCH_CONFIG, /* Specified by config */
- N_OUTPUT_MATCHES
-} MetaOutputMatchType;
-
-struct _MetaMapperInputInfo
-{
- ClutterInputDevice *device;
- MetaInputMapper *mapper;
- MetaMapperOutputInfo *output;
- GSettings *settings;
- guint builtin : 1;
-};
-
-struct _MetaMapperOutputInfo
-{
- MetaLogicalMonitor *logical_monitor;
- GList *input_devices;
- MetaInputCapabilityFlags attached_caps;
-};
-
-struct _MappingHelper
-{
- GArray *device_maps;
-};
-
-struct _DeviceMatch
-{
- MetaMonitor *monitor;
- uint32_t score;
-};
-
-struct _DeviceCandidates
-{
- MetaMapperInputInfo *input;
-
- GArray *matches; /* Array of DeviceMatch */
-
- int best;
-};
-
-enum
-{
- DEVICE_MAPPED,
- DEVICE_ENABLED,
- DEVICE_ASPECT_RATIO,
- N_SIGNALS
-};
-
-static guint signals[N_SIGNALS] = { 0, };
-
-static void mapper_output_info_remove_input (MetaMapperOutputInfo *output,
- MetaMapperInputInfo *input);
-
-static void mapper_recalculate_input (MetaInputMapper *mapper,
- MetaMapperInputInfo *input);
-
-G_DEFINE_TYPE (MetaInputMapper, meta_input_mapper, G_TYPE_OBJECT)
-
-static GSettings *
-get_device_settings (ClutterInputDevice *device)
-{
- const char *group, *schema, *vendor, *product;
- ClutterInputDeviceType type;
- GSettings *settings;
- char *path;
-
- type = clutter_input_device_get_device_type (device);
-
- if (type == CLUTTER_TOUCHSCREEN_DEVICE)
- {
- group = "touchscreens";
- schema = "org.gnome.desktop.peripherals.touchscreen";
- }
- else if (type == CLUTTER_TABLET_DEVICE ||
- type == CLUTTER_PEN_DEVICE ||
- type == CLUTTER_ERASER_DEVICE ||
- type == CLUTTER_CURSOR_DEVICE ||
- type == CLUTTER_PAD_DEVICE)
- {
- group = "tablets";
- schema = "org.gnome.desktop.peripherals.tablet";
- }
- else
- {
- return NULL;
- }
-
- vendor = clutter_input_device_get_vendor_id (device);
- product = clutter_input_device_get_product_id (device);
- path = g_strdup_printf ("/org/gnome/desktop/peripherals/%s/%s:%s/",
- group, vendor, product);
-
- settings = g_settings_new_with_path (schema, path);
- g_free (path);
-
- return settings;
-}
-
-static void
-settings_output_changed_cb (GSettings *settings,
- const char *key,
- MetaMapperInputInfo *info)
-{
- if (info->output != NULL)
- mapper_output_info_remove_input (info->output, info);
-
- mapper_recalculate_input (info->mapper, info);
-}
-
-static MetaMapperInputInfo *
-mapper_input_info_new (ClutterInputDevice *device,
- MetaInputMapper *mapper)
-{
- MetaMapperInputInfo *info;
-
- info = g_new0 (MetaMapperInputInfo, 1);
- info->mapper = mapper;
- info->device = device;
- info->settings = get_device_settings (device);
-
- g_signal_connect (info->settings, "changed::output",
- G_CALLBACK (settings_output_changed_cb), info);
-
- return info;
-}
-
-static void
-mapper_input_info_free (MetaMapperInputInfo *info)
-{
- g_signal_handlers_disconnect_by_func (info->settings, settings_output_changed_cb, info);
- g_object_unref (info->settings);
- g_free (info);
-}
-
-static MetaMapperOutputInfo *
-mapper_output_info_new (MetaLogicalMonitor *logical_monitor)
-{
- MetaMapperOutputInfo *info;
-
- info = g_new0 (MetaMapperOutputInfo, 1);
- info->logical_monitor = logical_monitor;
-
- return info;
-}
-
-static void
-mapper_output_info_free (MetaMapperOutputInfo *info)
-{
- g_free (info);
-}
-
-static MetaInputCapabilityFlags
-mapper_input_info_get_caps (MetaMapperInputInfo *info)
-{
- ClutterInputDeviceType type;
-
- type = clutter_input_device_get_device_type (info->device);
-
- switch (type)
- {
- case CLUTTER_TOUCHSCREEN_DEVICE:
- return META_INPUT_CAP_TOUCH;
- case CLUTTER_TABLET_DEVICE:
- case CLUTTER_PEN_DEVICE:
- return META_INPUT_CAP_STYLUS;
- case CLUTTER_ERASER_DEVICE:
- return META_INPUT_CAP_ERASER;
- case CLUTTER_CURSOR_DEVICE:
- return META_INPUT_CAP_CURSOR;
- case CLUTTER_PAD_DEVICE:
- return META_INPUT_CAP_PAD;
- default:
- return 0;
- }
-}
-
-static void
-mapper_input_info_set_output (MetaMapperInputInfo *input,
- MetaMapperOutputInfo *output,
- MetaMonitor *monitor)
-{
- MetaInputMapper *mapper = input->mapper;
- float matrix[6] = { 1, 0, 0, 0, 1, 0 };
- double aspect_ratio;
- int width, height;
-
- if (input->output == output)
- return;
-
- input->output = output;
-
- if (output && monitor)
- {
- meta_monitor_manager_get_monitor_matrix (mapper->monitor_manager,
- monitor,
- output->logical_monitor,
- matrix);
- meta_monitor_get_current_resolution (monitor, &width, &height);
- }
- else
- {
- meta_monitor_manager_get_screen_size (mapper->monitor_manager,
- &width, &height);
- }
-
- aspect_ratio = (double) width / height;
-
- g_signal_emit (input->mapper, signals[DEVICE_MAPPED], 0,
- input->device, matrix);
- g_signal_emit (input->mapper, signals[DEVICE_ASPECT_RATIO], 0,
- input->device, aspect_ratio);
-}
-
-static void
-mapper_output_info_add_input (MetaMapperOutputInfo *output,
- MetaMapperInputInfo *input,
- MetaMonitor *monitor)
-{
- g_assert (input->output == NULL);
-
- output->input_devices = g_list_prepend (output->input_devices, input);
- output->attached_caps |= mapper_input_info_get_caps (input);
-
- mapper_input_info_set_output (input, output, monitor);
-}
-
-static void
-mapper_output_info_remove_input (MetaMapperOutputInfo *output,
- MetaMapperInputInfo *input)
-{
- GList *l;
-
- g_assert (input->output == output);
-
- output->input_devices = g_list_remove (output->input_devices, input);
- output->attached_caps = 0;
-
- for (l = output->input_devices; l; l = l->next)
- output->attached_caps |= mapper_input_info_get_caps (l->data);
-
- mapper_input_info_set_output (input, NULL, NULL);
-}
-
-static void
-mapper_output_info_clear_inputs (MetaMapperOutputInfo *output)
-{
- while (output->input_devices)
- {
- MetaMapperInputInfo *input = output->input_devices->data;
-
- mapper_input_info_set_output (input, NULL, NULL);
- output->input_devices = g_list_remove (output->input_devices, input);
- }
-
- output->attached_caps = 0;
-}
-
-static void
-clear_candidates (DeviceCandidates *candidates)
-{
- g_clear_pointer (&candidates->matches, g_array_unref);
-}
-
-static void
-mapping_helper_init (MappingHelper *helper)
-{
- helper->device_maps = g_array_new (FALSE, FALSE, sizeof (DeviceCandidates));
- g_array_set_clear_func (helper->device_maps,
- (GDestroyNotify) clear_candidates);
-}
-
-static void
-mapping_helper_release (MappingHelper *helper)
-{
- g_array_unref (helper->device_maps);
-}
-
-static gboolean
-match_edid (MetaMapperInputInfo *input,
- MetaMonitor *monitor,
- MetaOutputMatchType *match_type)
-{
- const gchar *dev_name;
-
- dev_name = clutter_input_device_get_device_name (input->device);
-
- if (strcasestr (dev_name, meta_monitor_get_vendor (monitor)) == NULL)
- return FALSE;
-
- *match_type = META_MATCH_EDID_VENDOR;
-
- if (strcasestr (dev_name, meta_monitor_get_product (monitor)) != NULL)
- {
- *match_type = META_MATCH_EDID_FULL;
- }
- else
- {
- int i;
- g_auto (GStrv) split = NULL;
-
- split = g_strsplit (meta_monitor_get_product (monitor), " ", -1);
-
- for (i = 0; split[i]; i++)
- {
- if (strcasestr (dev_name, split[i]) != NULL)
- {
- *match_type = META_MATCH_EDID_PARTIAL;
- break;
- }
- }
- }
-
- return TRUE;
-}
-
-static gboolean
-input_device_get_physical_size (MetaInputMapper *mapper,
- ClutterInputDevice *device,
- double *width,
- double *height)
-{
-#ifdef HAVE_LIBGUDEV
- g_autoptr (GUdevDevice) udev_device = NULL;
- const char *node;
-
- node = clutter_input_device_get_device_node (device);
- if (!node)
- return FALSE;
-
- udev_device = g_udev_client_query_by_device_file (mapper->udev_client, node);
-
- if (udev_device &&
- g_udev_device_has_property (udev_device, "ID_INPUT_WIDTH_MM"))
- {
- *width = g_udev_device_get_property_as_double (udev_device,
- "ID_INPUT_WIDTH_MM");
- *height = g_udev_device_get_property_as_double (udev_device,
- "ID_INPUT_HEIGHT_MM");
- return TRUE;
- }
-#endif
-
- return FALSE;
-}
-
-static gboolean
-match_size (MetaMapperInputInfo *input,
- MetaMonitor *monitor)
-{
- double w_diff, h_diff;
- int o_width, o_height;
- double i_width, i_height;
-
- if (!input_device_get_physical_size (input->mapper, input->device,
- &i_width, &i_height))
- return FALSE;
-
- meta_monitor_get_physical_dimensions (monitor, &o_width, &o_height);
- w_diff = ABS (1 - ((double) o_width / i_width));
- h_diff = ABS (1 - ((double) o_height / i_height));
-
- return w_diff < MAX_SIZE_MATCH_DIFF && h_diff < MAX_SIZE_MATCH_DIFF;
-}
-
-static gboolean
-match_builtin (MetaInputMapper *mapper,
- MetaMonitor *monitor)
-{
- return monitor == meta_monitor_manager_get_laptop_panel (mapper->monitor_manager);
-}
-
-static gboolean
-match_config (MetaMapperInputInfo *info,
- MetaMonitor *monitor)
-{
- gboolean match = FALSE;
- char **edid;
- guint n_values;
-
- edid = g_settings_get_strv (info->settings, "output");
- n_values = g_strv_length (edid);
-
- if (n_values != 3)
- {
- g_warning ("EDID configuration for device '%s' "
- "is incorrect, must have 3 values",
- clutter_input_device_get_device_name (info->device));
- goto out;
- }
-
- if (!*edid[0] && !*edid[1] && !*edid[2])
- goto out;
-
- match = (g_strcmp0 (meta_monitor_get_vendor (monitor), edid[0]) == 0 &&
- g_strcmp0 (meta_monitor_get_product (monitor), edid[1]) == 0 &&
- g_strcmp0 (meta_monitor_get_serial (monitor), edid[2]) == 0);
-
- out:
- g_strfreev (edid);
-
- return match;
-}
-
-static int
-sort_by_score (DeviceMatch *match1,
- DeviceMatch *match2)
-{
- return (int) match1->score - match2->score;
-}
-
-static void
-guess_candidates (MetaInputMapper *mapper,
- MetaMapperInputInfo *input,
- DeviceCandidates *info)
-{
- GList *monitors, *l;
- gboolean builtin = FALSE;
- gboolean integrated = TRUE;
-
-#ifdef HAVE_LIBWACOM
- if (clutter_input_device_get_device_type (input->device) != CLUTTER_TOUCHSCREEN_DEVICE)
- {
- WacomDevice *wacom_device;
- WacomIntegrationFlags flags = 0;
-
- wacom_device =
- meta_input_device_get_wacom_device (META_INPUT_DEVICE (input->device));
-
- if (wacom_device)
- {
- flags = libwacom_get_integration_flags (wacom_device);
-
- integrated = (flags & (WACOM_DEVICE_INTEGRATED_SYSTEM |
- WACOM_DEVICE_INTEGRATED_DISPLAY)) != 0;
- builtin = (flags & WACOM_DEVICE_INTEGRATED_SYSTEM) != 0;
- }
- }
-#endif
-
- monitors = meta_monitor_manager_get_monitors (mapper->monitor_manager);
-
- for (l = monitors; l; l = l->next)
- {
- MetaOutputMatchType edid_match;
- DeviceMatch match = { l->data, 0 };
-
- g_assert (META_IS_MONITOR (l->data));
-
- if (match_edid (input, l->data, &edid_match))
- match.score |= 1 << edid_match;
-
- if (integrated && match_size (input, l->data))
- match.score |= 1 << META_MATCH_SIZE;
-
- if (builtin && match_builtin (mapper, l->data))
- match.score |= 1 << META_MATCH_IS_BUILTIN;
-
- if (match_config (input, l->data))
- match.score |= 1 << META_MATCH_CONFIG;
-
- if (match.score > 0)
- g_array_append_val (info->matches, match);
- }
-
- if (info->matches->len == 0)
- {
- DeviceMatch match = { 0 };
-
- match.monitor =
- meta_monitor_manager_get_laptop_panel (mapper->monitor_manager);
-
- if (match.monitor != NULL)
- g_array_append_val (info->matches, match);
-
- info->best = 0;
- }
- else
- {
- DeviceMatch *best;
-
- g_array_sort (info->matches, (GCompareFunc) sort_by_score);
- best = &g_array_index (info->matches, DeviceMatch, 0);
- info->best = best->score;
- }
-}
-
-static void
-mapping_helper_add (MappingHelper *helper,
- MetaMapperInputInfo *input,
- MetaInputMapper *mapper)
-{
- DeviceCandidates info = { 0, };
- guint i, pos = 0;
-
- info.input = input;
- info.matches = g_array_new (FALSE, TRUE, sizeof (DeviceMatch));
-
- guess_candidates (mapper, input, &info);
-
- for (i = 0; i < helper->device_maps->len; i++)
- {
- DeviceCandidates *elem;
-
- elem = &g_array_index (helper->device_maps, DeviceCandidates, i);
-
- if (elem->best > info.best)
- pos = i;
- }
-
- if (pos >= helper->device_maps->len)
- g_array_append_val (helper->device_maps, info);
- else
- g_array_insert_val (helper->device_maps, pos, info);
-}
-
-static void
-mapping_helper_apply (MappingHelper *helper,
- MetaInputMapper *mapper)
-{
- guint i, j;
-
- /* Now, decide which input claims which output */
- for (i = 0; i < helper->device_maps->len; i++)
- {
- DeviceCandidates *info;
-
- info = &g_array_index (helper->device_maps, DeviceCandidates, i);
- g_debug ("Applying mapping %d to input device '%s', capabilities %x", i,
- clutter_input_device_get_device_name (info->input->device),
- mapper_input_info_get_caps (info->input));
-
- for (j = 0; j < info->matches->len; j++)
- {
- MetaLogicalMonitor *logical_monitor;
- MetaMapperOutputInfo *output;
- MetaMonitor *monitor;
- DeviceMatch *match;
-
- match = &g_array_index (info->matches, DeviceMatch, j);
- g_debug ("Output candidate '%s', score %x",
- meta_monitor_get_display_name (match->monitor),
- match->score);
-
- monitor = match->monitor;
- logical_monitor = meta_monitor_get_logical_monitor (monitor);
- output = g_hash_table_lookup (mapper->output_devices,
- logical_monitor);
-
- if (!output)
- continue;
-
- if (output->attached_caps & mapper_input_info_get_caps (info->input))
- continue;
-
- g_debug ("Matched input '%s' with output '%s'",
- clutter_input_device_get_device_name (info->input->device),
- meta_monitor_get_display_name (match->monitor));
- mapper_output_info_add_input (output, info->input, monitor);
- break;
- }
- }
-}
-
-static void
-mapper_recalculate_candidates (MetaInputMapper *mapper)
-{
- MetaMapperInputInfo *input;
- MappingHelper helper;
- GHashTableIter iter;
-
- mapping_helper_init (&helper);
- g_hash_table_iter_init (&iter, mapper->input_devices);
-
- while (g_hash_table_iter_next (&iter, NULL, (gpointer *) &input))
- mapping_helper_add (&helper, input, mapper);
-
- mapping_helper_apply (&helper, mapper);
- mapping_helper_release (&helper);
-}
-
-static void
-mapper_recalculate_input (MetaInputMapper *mapper,
- MetaMapperInputInfo *input)
-{
- MappingHelper helper;
-
- mapping_helper_init (&helper);
- mapping_helper_add (&helper, input, mapper);
- mapping_helper_apply (&helper, mapper);
- mapping_helper_release (&helper);
-}
-
-static void
-mapper_update_outputs (MetaInputMapper *mapper)
-{
- MetaMapperOutputInfo *output;
- GList *logical_monitors, *l;
- GHashTableIter iter;
-
- g_hash_table_iter_init (&iter, mapper->output_devices);
-
- while (g_hash_table_iter_next (&iter, NULL, (gpointer *) &output))
- {
- mapper_output_info_clear_inputs (output);
- g_hash_table_iter_remove (&iter);
- }
-
- logical_monitors =
- meta_monitor_manager_get_logical_monitors (mapper->monitor_manager);
-
- for (l = logical_monitors; l; l = l->next)
- {
- MetaLogicalMonitor *logical_monitor = l->data;
- MetaMapperOutputInfo *info;
-
- info = mapper_output_info_new (logical_monitor);
- g_hash_table_insert (mapper->output_devices, logical_monitor, info);
- }
-
- mapper_recalculate_candidates (mapper);
-}
-
-static void
-input_mapper_monitors_changed_cb (MetaMonitorManager *monitor_manager,
- MetaInputMapper *mapper)
-{
- mapper_update_outputs (mapper);
-}
-
-static void
-input_mapper_power_save_mode_changed_cb (MetaMonitorManager *monitor_manager,
- MetaInputMapper *mapper)
-{
- ClutterInputDevice *device;
- MetaLogicalMonitor *logical_monitor;
- MetaMonitor *builtin;
- MetaPowerSave power_save_mode;
- gboolean on;
-
- power_save_mode =
- meta_monitor_manager_get_power_save_mode (mapper->monitor_manager);
- on = power_save_mode == META_POWER_SAVE_ON;
-
- builtin = meta_monitor_manager_get_laptop_panel (monitor_manager);
- if (!builtin)
- return;
-
- logical_monitor = meta_monitor_get_logical_monitor (builtin);
- if (!logical_monitor)
- return;
-
- device =
- meta_input_mapper_get_logical_monitor_device (mapper,
- logical_monitor,
- CLUTTER_TOUCHSCREEN_DEVICE);
- if (!device)
- return;
-
- g_signal_emit (mapper, signals[DEVICE_ENABLED], 0, device, on);
-}
-
-static void
-input_mapper_device_removed_cb (ClutterSeat *seat,
- ClutterInputDevice *device,
- MetaInputMapper *mapper)
-{
- meta_input_mapper_remove_device (mapper, device);
-}
-
-static void
-meta_input_mapper_finalize (GObject *object)
-{
- MetaInputMapper *mapper = META_INPUT_MAPPER (object);
-
- g_signal_handlers_disconnect_by_func (mapper->monitor_manager,
- input_mapper_monitors_changed_cb,
- mapper);
- g_signal_handlers_disconnect_by_func (mapper->seat,
- input_mapper_device_removed_cb,
- mapper);
-
- g_hash_table_unref (mapper->input_devices);
- g_hash_table_unref (mapper->output_devices);
-#ifdef HAVE_LIBGUDEV
- g_clear_object (&mapper->udev_client);
-#endif
-
- G_OBJECT_CLASS (meta_input_mapper_parent_class)->finalize (object);
-}
-
-static void
-meta_input_mapper_constructed (GObject *object)
-{
-#ifdef HAVE_LIBGUDEV
- const char *udev_subsystems[] = { "input", NULL };
-#endif
- MetaInputMapper *mapper = META_INPUT_MAPPER (object);
- MetaBackend *backend;
-
- G_OBJECT_CLASS (meta_input_mapper_parent_class)->constructed (object);
-
-#ifdef HAVE_LIBGUDEV
- mapper->udev_client = g_udev_client_new (udev_subsystems);
-#endif
-
- mapper->seat = clutter_backend_get_default_seat (clutter_get_default_backend ());
- g_signal_connect (mapper->seat, "device-removed",
- G_CALLBACK (input_mapper_device_removed_cb), mapper);
-
- backend = meta_get_backend ();
- mapper->monitor_manager = meta_backend_get_monitor_manager (backend);
- g_signal_connect (mapper->monitor_manager, "monitors-changed-internal",
- G_CALLBACK (input_mapper_monitors_changed_cb), mapper);
- g_signal_connect (mapper->monitor_manager, "power-save-mode-changed",
- G_CALLBACK (input_mapper_power_save_mode_changed_cb),
- mapper);
-
- mapper_update_outputs (mapper);
-}
-
-static void
-meta_input_mapper_class_init (MetaInputMapperClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- object_class->constructed = meta_input_mapper_constructed;
- object_class->finalize = meta_input_mapper_finalize;
-
- signals[DEVICE_MAPPED] =
- g_signal_new ("device-mapped",
- G_TYPE_FROM_CLASS (object_class),
- G_SIGNAL_RUN_LAST,
- 0,
- NULL, NULL, NULL,
- G_TYPE_NONE, 2,
- CLUTTER_TYPE_INPUT_DEVICE,
- G_TYPE_POINTER);
- signals[DEVICE_ENABLED] =
- g_signal_new ("device-enabled",
- G_TYPE_FROM_CLASS (object_class),
- G_SIGNAL_RUN_LAST,
- 0,
- NULL, NULL, NULL,
- G_TYPE_NONE, 2,
- CLUTTER_TYPE_INPUT_DEVICE,
- G_TYPE_BOOLEAN);
- signals[DEVICE_ASPECT_RATIO] =
- g_signal_new ("device-aspect-ratio",
- G_TYPE_FROM_CLASS (object_class),
- G_SIGNAL_RUN_LAST,
- 0,
- NULL, NULL, NULL,
- G_TYPE_NONE, 2,
- CLUTTER_TYPE_INPUT_DEVICE,
- G_TYPE_DOUBLE);
-}
-
-static void
-meta_input_mapper_init (MetaInputMapper *mapper)
-{
- mapper->input_devices =
- g_hash_table_new_full (NULL, NULL, NULL,
- (GDestroyNotify) mapper_input_info_free);
- mapper->output_devices =
- g_hash_table_new_full (NULL, NULL, NULL,
- (GDestroyNotify) mapper_output_info_free);
-}
-
-MetaInputMapper *
-meta_input_mapper_new (void)
-{
- return g_object_new (META_TYPE_INPUT_MAPPER, NULL);
-}
-
-void
-meta_input_mapper_add_device (MetaInputMapper *mapper,
- ClutterInputDevice *device)
-{
- MetaMapperInputInfo *info;
-
- g_return_if_fail (mapper != NULL);
- g_return_if_fail (device != NULL);
-
- if (g_hash_table_contains (mapper->input_devices, device))
- return;
-
- info = mapper_input_info_new (device, mapper);
- g_hash_table_insert (mapper->input_devices, device, info);
- mapper_recalculate_input (mapper, info);
-}
-
-void
-meta_input_mapper_remove_device (MetaInputMapper *mapper,
- ClutterInputDevice *device)
-{
- MetaMapperInputInfo *input;
-
- g_return_if_fail (mapper != NULL);
- g_return_if_fail (device != NULL);
-
- input = g_hash_table_lookup (mapper->input_devices, device);
-
- if (input)
- {
- if (input->output)
- mapper_output_info_remove_input (input->output, input);
- g_hash_table_remove (mapper->input_devices, device);
- }
-}
-
-ClutterInputDevice *
-meta_input_mapper_get_logical_monitor_device (MetaInputMapper *mapper,
- MetaLogicalMonitor *logical_monitor,
- ClutterInputDeviceType device_type)
-{
- MetaMapperOutputInfo *output;
- GList *l;
-
- output = g_hash_table_lookup (mapper->output_devices, logical_monitor);
- if (!output)
- return NULL;
-
- for (l = output->input_devices; l; l = l->next)
- {
- MetaMapperInputInfo *input = l->data;
-
- if (clutter_input_device_get_device_type (input->device) == device_type)
- return input->device;
- }
-
- return NULL;
-}
-
-static ClutterInputDevice *
-find_grouped_pen (ClutterInputDevice *device)
-{
- GList *l, *devices;
- ClutterInputDeviceType device_type;
- ClutterInputDevice *pen = NULL;
- ClutterSeat *seat;
-
- device_type = clutter_input_device_get_device_type (device);
-
- if (device_type == CLUTTER_TABLET_DEVICE ||
- device_type == CLUTTER_PEN_DEVICE)
- return device;
-
- seat = clutter_input_device_get_seat (device);
- devices = clutter_seat_list_devices (seat);
-
- for (l = devices; l; l = l->next)
- {
- ClutterInputDevice *other_device = l->data;
-
- device_type = clutter_input_device_get_device_type (other_device);
-
- if ((device_type == CLUTTER_TABLET_DEVICE ||
- device_type == CLUTTER_PEN_DEVICE) &&
- clutter_input_device_is_grouped (device, other_device))
- {
- pen = other_device;
- break;
- }
- }
-
- g_list_free (devices);
-
- return pen;
-}
-
-MetaLogicalMonitor *
-meta_input_mapper_get_device_logical_monitor (MetaInputMapper *mapper,
- ClutterInputDevice *device)
-{
- MetaMapperOutputInfo *output;
- MetaLogicalMonitor *logical_monitor;
- GHashTableIter iter;
- GList *l;
-
- if (clutter_input_device_get_device_type (device) == CLUTTER_PAD_DEVICE)
- {
- device = find_grouped_pen (device);
- if (!device)
- return NULL;
- }
-
- g_hash_table_iter_init (&iter, mapper->output_devices);
-
- while (g_hash_table_iter_next (&iter, (gpointer *) &logical_monitor,
- (gpointer *) &output))
- {
- for (l = output->input_devices; l; l = l->next)
- {
- MetaMapperInputInfo *input = l->data;
-
- if (input->device == device)
- return logical_monitor;
- }
- }
-
- return NULL;
-}
-
-GSettings *
-meta_input_mapper_get_tablet_settings (MetaInputMapper *mapper,
- ClutterInputDevice *device)
-{
- MetaMapperInputInfo *input;
-
- g_return_val_if_fail (META_IS_INPUT_MAPPER (mapper), NULL);
- g_return_val_if_fail (CLUTTER_IS_INPUT_DEVICE (device), NULL);
-
- input = g_hash_table_lookup (mapper->input_devices, device);
- if (!input)
- return NULL;
-
- return input->settings;
-}
diff --git a/src/backends/meta-input-settings-dummy.c b/src/backends/meta-input-settings-dummy.c
deleted file mode 100644
index 74e6f429c..000000000
--- a/src/backends/meta-input-settings-dummy.c
+++ /dev/null
@@ -1,295 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright 2021 Canonical, Ltd.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, see <http://www.gnu.org/licenses/>.
- *
- * Author: Marco Trevisan <marco.trevisan@canonical.com>
- */
-
-#include "backends/meta-input-settings-dummy.h"
-
-G_DEFINE_TYPE (MetaInputSettingsDummy,
- meta_input_settings_dummy,
- META_TYPE_INPUT_SETTINGS)
-
-static void
-meta_input_settings_dummy_set_send_events (MetaInputSettings *settings,
- ClutterInputDevice *device,
- GDesktopDeviceSendEvents mode)
-{
-}
-
-static void
-meta_input_settings_dummy_set_matrix (MetaInputSettings *settings,
- ClutterInputDevice *device,
- const float matrix[6])
-{
-}
-
-static void
-meta_input_settings_dummy_set_speed (MetaInputSettings *settings,
- ClutterInputDevice *device,
- gdouble speed)
-{
-}
-
-static void
-meta_input_settings_dummy_set_left_handed (MetaInputSettings *settings,
- ClutterInputDevice *device,
- gboolean enabled)
-{
-}
-
-static void
-meta_input_settings_dummy_set_tap_enabled (MetaInputSettings *settings,
- ClutterInputDevice *device,
- gboolean enabled)
-{
-}
-
-static void
-meta_input_settings_dummy_set_tap_button_map (MetaInputSettings *settings,
- ClutterInputDevice *device,
- GDesktopTouchpadTapButtonMap mode)
-{
-}
-
-static void
-meta_input_settings_dummy_set_tap_and_drag_enabled (MetaInputSettings *settings,
- ClutterInputDevice *device,
- gboolean enabled)
-{
-}
-
-static void
-meta_input_settings_dummy_set_tap_and_drag_lock_enabled (MetaInputSettings *settings,
- ClutterInputDevice *device,
- gboolean enabled)
-{
-}
-
-static void
-meta_input_settings_dummy_set_disable_while_typing (MetaInputSettings *settings,
- ClutterInputDevice *device,
- gboolean enabled)
-{
-}
-
-static void
-meta_input_settings_dummy_set_invert_scroll (MetaInputSettings *settings,
- ClutterInputDevice *device,
- gboolean inverted)
-{
-}
-
-static void
-meta_input_settings_dummy_set_edge_scroll (MetaInputSettings *settings,
- ClutterInputDevice *device,
- gboolean enabled)
-{
-}
-
-static void
-meta_input_settings_dummy_set_two_finger_scroll (MetaInputSettings *settings,
- ClutterInputDevice *device,
- gboolean enabled)
-{
-}
-
-static void
-meta_input_settings_dummy_set_scroll_button (MetaInputSettings *settings,
- ClutterInputDevice *device,
- guint button,
- gboolean button_lock)
-{
-}
-
-
-static void
-meta_input_settings_dummy_set_click_method (MetaInputSettings *settings,
- ClutterInputDevice *device,
- GDesktopTouchpadClickMethod mode)
-{
-}
-
-
-static void
-meta_input_settings_dummy_set_keyboard_repeat (MetaInputSettings *settings,
- gboolean repeat,
- guint delay,
- guint interval)
-{
-}
-
-
-static void
-meta_input_settings_dummy_set_tablet_mapping (MetaInputSettings *settings,
- ClutterInputDevice *device,
- GDesktopTabletMapping mapping)
-{
-}
-
-static void
-meta_input_settings_dummy_set_tablet_aspect_ratio (MetaInputSettings *settings,
- ClutterInputDevice *device,
- double ratio)
-{
-}
-
-static void
-meta_input_settings_dummy_set_tablet_area (MetaInputSettings *settings,
- ClutterInputDevice *device,
- gdouble padding_left,
- gdouble padding_right,
- gdouble padding_top,
- gdouble padding_bottom)
-{
-}
-
-
-static void
-meta_input_settings_dummy_set_mouse_accel_profile (MetaInputSettings *settings,
- ClutterInputDevice *device,
- GDesktopPointerAccelProfile profile)
-{
-}
-
-static void
-meta_input_settings_dummy_set_trackball_accel_profile (MetaInputSettings *settings,
- ClutterInputDevice *device,
- GDesktopPointerAccelProfile profile)
-{
-}
-
-
-static void
-meta_input_settings_dummy_set_stylus_pressure (MetaInputSettings *settings,
- ClutterInputDevice *device,
- ClutterInputDeviceTool *tool,
- const gint32 curve[4])
-{
-}
-
-static void
-meta_input_settings_dummy_set_stylus_button_map (MetaInputSettings *settings,
- ClutterInputDevice *device,
- ClutterInputDeviceTool *tool,
- GDesktopStylusButtonAction primary,
- GDesktopStylusButtonAction secondary,
- GDesktopStylusButtonAction tertiary)
-{
-}
-
-
-static void
-meta_input_settings_dummy_set_mouse_middle_click_emulation (MetaInputSettings *settings,
- ClutterInputDevice *device,
- gboolean enabled)
-{
-}
-
-static void
-meta_input_settings_dummy_set_touchpad_middle_click_emulation (MetaInputSettings *settings,
- ClutterInputDevice *device,
- gboolean enabled)
-{
-}
-
-static void
-meta_input_settings_dummy_set_trackball_middle_click_emulation (MetaInputSettings *settings,
- ClutterInputDevice *device,
- gboolean enabled)
-{
-}
-
-static gboolean
-meta_input_settings_dummy_has_two_finger_scroll (MetaInputSettings *settings,
- ClutterInputDevice *device)
-{
- return FALSE;
-}
-static gboolean
-meta_input_settings_dummy_is_trackball_device (MetaInputSettings *settings,
- ClutterInputDevice *device)
-{
- return FALSE;
-}
-
-static void
-meta_input_settings_dummy_init (MetaInputSettingsDummy *input_settings)
-{
-}
-
-static void
-meta_input_settings_dummy_class_init (MetaInputSettingsDummyClass *klass)
-{
- MetaInputSettingsClass *input_settings_class = META_INPUT_SETTINGS_CLASS (klass);
-
- input_settings_class->set_send_events =
- meta_input_settings_dummy_set_send_events;
- input_settings_class->set_matrix =
- meta_input_settings_dummy_set_matrix;
- input_settings_class->set_speed =
- meta_input_settings_dummy_set_speed;
- input_settings_class->set_left_handed =
- meta_input_settings_dummy_set_left_handed;
- input_settings_class->set_tap_enabled =
- meta_input_settings_dummy_set_tap_enabled;
- input_settings_class->set_tap_button_map =
- meta_input_settings_dummy_set_tap_button_map;
- input_settings_class->set_tap_and_drag_enabled =
- meta_input_settings_dummy_set_tap_and_drag_enabled;
- input_settings_class->set_tap_and_drag_lock_enabled =
- meta_input_settings_dummy_set_tap_and_drag_lock_enabled;
- input_settings_class->set_disable_while_typing =
- meta_input_settings_dummy_set_disable_while_typing;
- input_settings_class->set_invert_scroll =
- meta_input_settings_dummy_set_invert_scroll;
- input_settings_class->set_edge_scroll =
- meta_input_settings_dummy_set_edge_scroll;
- input_settings_class->set_two_finger_scroll =
- meta_input_settings_dummy_set_two_finger_scroll;
- input_settings_class->set_scroll_button =
- meta_input_settings_dummy_set_scroll_button;
- input_settings_class->set_click_method =
- meta_input_settings_dummy_set_click_method;
- input_settings_class->set_keyboard_repeat =
- meta_input_settings_dummy_set_keyboard_repeat;
- input_settings_class->set_tablet_mapping =
- meta_input_settings_dummy_set_tablet_mapping;
- input_settings_class->set_tablet_aspect_ratio =
- meta_input_settings_dummy_set_tablet_aspect_ratio;
- input_settings_class->set_tablet_area =
- meta_input_settings_dummy_set_tablet_area;
- input_settings_class->set_mouse_accel_profile =
- meta_input_settings_dummy_set_mouse_accel_profile;
- input_settings_class->set_trackball_accel_profile =
- meta_input_settings_dummy_set_trackball_accel_profile;
- input_settings_class->set_stylus_pressure =
- meta_input_settings_dummy_set_stylus_pressure;
- input_settings_class->set_stylus_button_map =
- meta_input_settings_dummy_set_stylus_button_map;
- input_settings_class->set_mouse_middle_click_emulation =
- meta_input_settings_dummy_set_mouse_middle_click_emulation;
- input_settings_class->set_touchpad_middle_click_emulation =
- meta_input_settings_dummy_set_touchpad_middle_click_emulation;
- input_settings_class->set_trackball_middle_click_emulation =
- meta_input_settings_dummy_set_trackball_middle_click_emulation;
- input_settings_class->has_two_finger_scroll =
- meta_input_settings_dummy_has_two_finger_scroll;
- input_settings_class->is_trackball_device =
- meta_input_settings_dummy_is_trackball_device;
-}
diff --git a/src/backends/meta-input-settings-dummy.h b/src/backends/meta-input-settings-dummy.h
deleted file mode 100644
index 9d91dc15d..000000000
--- a/src/backends/meta-input-settings-dummy.h
+++ /dev/null
@@ -1,34 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright 2021 Canonical, Ltd.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, see <http://www.gnu.org/licenses/>.
- *
- * Author: Marco Trevisan <marco.trevisan@canonical.com>
- */
-
-#pragma once
-
-#include "backends/meta-input-settings-private.h"
-
-#define META_TYPE_INPUT_SETTINGS_DUMMY (meta_input_settings_dummy_get_type ())
-
-G_DECLARE_DERIVABLE_TYPE (MetaInputSettingsDummy, meta_input_settings_dummy,
- META, INPUT_SETTINGS_DUMMY, MetaInputSettings);
-
-struct _MetaInputSettingsDummyClass
-{
- MetaInputSettingsClass parent_class;
-};
diff --git a/src/backends/meta-input-settings-private.h b/src/backends/meta-input-settings-private.h
deleted file mode 100644
index 42ee0e0e6..000000000
--- a/src/backends/meta-input-settings-private.h
+++ /dev/null
@@ -1,204 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright 2014 Red Hat, Inc.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, see <http://www.gnu.org/licenses/>.
- *
- * Author: Carlos Garnacho <carlosg@gnome.org>
- */
-
-#ifndef META_INPUT_SETTINGS_PRIVATE_H
-#define META_INPUT_SETTINGS_PRIVATE_H
-
-#include <gdesktop-enums.h>
-
-#ifdef HAVE_LIBWACOM
-#include <libwacom/libwacom.h>
-#endif
-
-#include "backends/meta-backend-types.h"
-#include "clutter/clutter.h"
-#include "meta/display.h"
-
-#define META_TYPE_INPUT_SETTINGS (meta_input_settings_get_type ())
-G_DECLARE_DERIVABLE_TYPE (MetaInputSettings, meta_input_settings,
- META, INPUT_SETTINGS, GObject)
-
-typedef enum
-{
- META_A11Y_KEYBOARD_ENABLED = 1 << 0,
- META_A11Y_TIMEOUT_ENABLED = 1 << 1,
- META_A11Y_MOUSE_KEYS_ENABLED = 1 << 2,
- META_A11Y_SLOW_KEYS_ENABLED = 1 << 3,
- META_A11Y_SLOW_KEYS_BEEP_PRESS = 1 << 4,
- META_A11Y_SLOW_KEYS_BEEP_ACCEPT = 1 << 5,
- META_A11Y_SLOW_KEYS_BEEP_REJECT = 1 << 6,
- META_A11Y_BOUNCE_KEYS_ENABLED = 1 << 7,
- META_A11Y_BOUNCE_KEYS_BEEP_REJECT = 1 << 8,
- META_A11Y_TOGGLE_KEYS_ENABLED = 1 << 9,
- META_A11Y_STICKY_KEYS_ENABLED = 1 << 10,
- META_A11Y_STICKY_KEYS_TWO_KEY_OFF = 1 << 11,
- META_A11Y_STICKY_KEYS_BEEP = 1 << 12,
- META_A11Y_FEATURE_STATE_CHANGE_BEEP = 1 << 13,
-} MetaKeyboardA11yFlags;
-
-/**
- * MetaKbdA11ySettings:
- *
- * The #MetaKbdA11ySettings structure contains keyboard accessibility
- * settings
- *
- */
-typedef struct _MetaKbdA11ySettings
-{
- MetaKeyboardA11yFlags controls;
- int slowkeys_delay;
- int debounce_delay;
- int timeout_delay;
- int mousekeys_init_delay;
- int mousekeys_max_speed;
- int mousekeys_accel_time;
-} MetaKbdA11ySettings;
-
-struct _MetaInputSettingsClass
-{
- GObjectClass parent_class;
-
- void (* set_send_events) (MetaInputSettings *settings,
- ClutterInputDevice *device,
- GDesktopDeviceSendEvents mode);
- void (* set_matrix) (MetaInputSettings *settings,
- ClutterInputDevice *device,
- const float matrix[6]);
- void (* set_speed) (MetaInputSettings *settings,
- ClutterInputDevice *device,
- gdouble speed);
- void (* set_left_handed) (MetaInputSettings *settings,
- ClutterInputDevice *device,
- gboolean enabled);
- void (* set_tap_enabled) (MetaInputSettings *settings,
- ClutterInputDevice *device,
- gboolean enabled);
- void (* set_tap_button_map) (MetaInputSettings *settings,
- ClutterInputDevice *device,
- GDesktopTouchpadTapButtonMap mode);
- void (* set_tap_and_drag_enabled) (MetaInputSettings *settings,
- ClutterInputDevice *device,
- gboolean enabled);
- void (* set_tap_and_drag_lock_enabled) (MetaInputSettings *settings,
- ClutterInputDevice *device,
- gboolean enabled);
- void (* set_disable_while_typing) (MetaInputSettings *settings,
- ClutterInputDevice *device,
- gboolean enabled);
- void (* set_invert_scroll) (MetaInputSettings *settings,
- ClutterInputDevice *device,
- gboolean inverted);
- void (* set_edge_scroll) (MetaInputSettings *settings,
- ClutterInputDevice *device,
- gboolean enabled);
- void (* set_two_finger_scroll) (MetaInputSettings *settings,
- ClutterInputDevice *device,
- gboolean enabled);
- void (* set_scroll_button) (MetaInputSettings *settings,
- ClutterInputDevice *device,
- guint button,
- gboolean button_lock);
-
- void (* set_click_method) (MetaInputSettings *settings,
- ClutterInputDevice *device,
- GDesktopTouchpadClickMethod mode);
-
- void (* set_keyboard_repeat) (MetaInputSettings *settings,
- gboolean repeat,
- guint delay,
- guint interval);
-
- void (* set_tablet_mapping) (MetaInputSettings *settings,
- ClutterInputDevice *device,
- GDesktopTabletMapping mapping);
- void (* set_tablet_aspect_ratio) (MetaInputSettings *settings,
- ClutterInputDevice *device,
- double ratio);
- void (* set_tablet_area) (MetaInputSettings *settings,
- ClutterInputDevice *device,
- gdouble padding_left,
- gdouble padding_right,
- gdouble padding_top,
- gdouble padding_bottom);
-
- void (* set_mouse_accel_profile) (MetaInputSettings *settings,
- ClutterInputDevice *device,
- GDesktopPointerAccelProfile profile);
- void (* set_trackball_accel_profile) (MetaInputSettings *settings,
- ClutterInputDevice *device,
- GDesktopPointerAccelProfile profile);
-
- void (* set_stylus_pressure) (MetaInputSettings *settings,
- ClutterInputDevice *device,
- ClutterInputDeviceTool *tool,
- const gint32 curve[4]);
- void (* set_stylus_button_map) (MetaInputSettings *settings,
- ClutterInputDevice *device,
- ClutterInputDeviceTool *tool,
- GDesktopStylusButtonAction primary,
- GDesktopStylusButtonAction secondary,
- GDesktopStylusButtonAction tertiary);
-
- void (* set_mouse_middle_click_emulation) (MetaInputSettings *settings,
- ClutterInputDevice *device,
- gboolean enabled);
- void (* set_touchpad_middle_click_emulation) (MetaInputSettings *settings,
- ClutterInputDevice *device,
- gboolean enabled);
- void (* set_trackball_middle_click_emulation) (MetaInputSettings *settings,
- ClutterInputDevice *device,
- gboolean enabled);
-
- gboolean (* has_two_finger_scroll) (MetaInputSettings *settings,
- ClutterInputDevice *device);
- gboolean (* is_trackball_device) (MetaInputSettings *settings,
- ClutterInputDevice *device);
-};
-
-void meta_input_settings_maybe_save_numlock_state (MetaInputSettings *input_settings,
- gboolean numlock_state);
-gboolean meta_input_settings_maybe_restore_numlock_state (MetaInputSettings *input_settings);
-
-void meta_input_settings_set_device_matrix (MetaInputSettings *input_settings,
- ClutterInputDevice *device,
- float matrix[6]);
-void meta_input_settings_set_device_enabled (MetaInputSettings *input_settings,
- ClutterInputDevice *device,
- gboolean enabled);
-void meta_input_settings_set_device_aspect_ratio (MetaInputSettings *input_settings,
- ClutterInputDevice *device,
- double aspect_ratio);
-
-void meta_input_settings_get_kbd_a11y_settings (MetaInputSettings *input_settings,
- MetaKbdA11ySettings *a11y_settings);
-
-void meta_input_settings_add_device (MetaInputSettings *input_settings,
- ClutterInputDevice *device);
-void meta_input_settings_remove_device (MetaInputSettings *input_settings,
- ClutterInputDevice *device);
-void meta_input_settings_notify_tool_change (MetaInputSettings *input_settings,
- ClutterInputDevice *device,
- ClutterInputDeviceTool *tool);
-void meta_input_settings_notify_kbd_a11y_change (MetaInputSettings *input_settings,
- MetaKeyboardA11yFlags new_flags,
- MetaKeyboardA11yFlags what_changed);
-
-#endif /* META_INPUT_SETTINGS_PRIVATE_H */
diff --git a/src/backends/meta-input-settings.c b/src/backends/meta-input-settings.c
deleted file mode 100644
index 16618608b..000000000
--- a/src/backends/meta-input-settings.c
+++ /dev/null
@@ -1,1762 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright 2014 Red Hat, Inc.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, see <http://www.gnu.org/licenses/>.
- *
- * Author: Carlos Garnacho <carlosg@gnome.org>
- */
-
-/**
- * SECTION:input-settings
- * @title: MetaInputSettings
- * @short_description: Mutter input device configuration
- */
-
-#include "config.h"
-
-#include <glib/gi18n-lib.h>
-#include <string.h>
-
-#include "backends/meta-backend-private.h"
-#include "backends/meta-input-device-private.h"
-#include "backends/meta-input-settings-private.h"
-#include "backends/meta-input-mapper-private.h"
-#include "backends/meta-logical-monitor.h"
-#include "backends/meta-monitor.h"
-#include "core/display-private.h"
-#include "meta/util.h"
-
-static GQuark quark_tool_settings = 0;
-
-typedef struct _MetaInputSettingsPrivate MetaInputSettingsPrivate;
-typedef struct _DeviceMappingInfo DeviceMappingInfo;
-typedef struct _CurrentToolInfo CurrentToolInfo;
-
-struct _CurrentToolInfo
-{
- MetaInputSettings *input_settings;
- ClutterInputDevice *device;
- ClutterInputDeviceTool *tool;
- GSettings *settings;
- gulong changed_id;
-};
-
-struct _DeviceMappingInfo
-{
- MetaInputSettings *input_settings;
- ClutterInputDevice *device;
- GSettings *settings;
- gulong changed_id;
- guint *group_modes;
- double aspect_ratio;
-};
-
-struct _MetaInputSettingsPrivate
-{
- ClutterSeat *seat;
- gulong monitors_changed_id;
-
- GSettings *mouse_settings;
- GSettings *touchpad_settings;
- GSettings *trackball_settings;
- GSettings *keyboard_settings;
- GSettings *keyboard_a11y_settings;
-
- GList *devices;
- GHashTable *mappable_devices;
-
- GHashTable *current_tools;
-
- GHashTable *two_finger_devices;
-
- MetaKbdA11ySettings kbd_a11y_settings;
-};
-
-typedef gboolean (* ConfigBoolMappingFunc) (MetaInputSettings *input_settings,
- ClutterInputDevice *device,
- gboolean value);
-
-typedef void (*ConfigBoolFunc) (MetaInputSettings *input_settings,
- ClutterInputDevice *device,
- gboolean setting);
-typedef void (*ConfigDoubleFunc) (MetaInputSettings *input_settings,
- ClutterInputDevice *device,
- gdouble value);
-typedef void (*ConfigUintFunc) (MetaInputSettings *input_settings,
- ClutterInputDevice *device,
- guint value);
-
-G_DEFINE_TYPE_WITH_PRIVATE (MetaInputSettings, meta_input_settings, G_TYPE_OBJECT)
-
-enum
-{
- KBD_A11Y_CHANGED,
- N_SIGNALS
-};
-
-static guint signals[N_SIGNALS] = { 0 };
-
-static GSList *
-meta_input_settings_get_devices (MetaInputSettings *settings,
- ClutterInputDeviceType type)
-{
- MetaInputSettingsPrivate *priv;
- GList *l;
- GSList *list = NULL;
-
- priv = meta_input_settings_get_instance_private (settings);
-
- for (l = priv->devices; l; l = l->next)
- {
- ClutterInputDevice *device = l->data;
-
- if (clutter_input_device_get_device_type (device) == type &&
- clutter_input_device_get_device_mode (device) != CLUTTER_INPUT_MODE_LOGICAL)
- list = g_slist_prepend (list, device);
- }
-
- return list;
-}
-
-static void
-meta_input_settings_dispose (GObject *object)
-{
- MetaInputSettings *settings = META_INPUT_SETTINGS (object);
- MetaInputSettingsPrivate *priv = meta_input_settings_get_instance_private (settings);
-
- g_clear_object (&priv->mouse_settings);
- g_clear_object (&priv->touchpad_settings);
- g_clear_object (&priv->trackball_settings);
- g_clear_object (&priv->keyboard_settings);
- g_clear_object (&priv->keyboard_a11y_settings);
- g_clear_pointer (&priv->mappable_devices, g_hash_table_unref);
- g_clear_pointer (&priv->current_tools, g_hash_table_unref);
-
- g_clear_pointer (&priv->two_finger_devices, g_hash_table_destroy);
-
- G_OBJECT_CLASS (meta_input_settings_parent_class)->dispose (object);
-}
-
-static void
-settings_device_set_bool_setting (MetaInputSettings *input_settings,
- ClutterInputDevice *device,
- ConfigBoolFunc func,
- gboolean enabled)
-{
- func (input_settings, device, enabled);
-}
-
-static void
-settings_set_bool_setting (MetaInputSettings *input_settings,
- ClutterInputDeviceType type,
- ConfigBoolMappingFunc mapping_func,
- ConfigBoolFunc func,
- gboolean enabled)
-{
- GSList *devices, *l;
-
- devices = meta_input_settings_get_devices (input_settings, type);
-
- for (l = devices; l; l = l->next)
- {
- gboolean value = enabled;
-
- if (mapping_func)
- value = mapping_func (input_settings, l->data, value);
- settings_device_set_bool_setting (input_settings, l->data, func, value);
- }
-
- g_slist_free (devices);
-}
-
-static void
-settings_device_set_double_setting (MetaInputSettings *input_settings,
- ClutterInputDevice *device,
- ConfigDoubleFunc func,
- gdouble value)
-{
- func (input_settings, device, value);
-}
-
-static void
-settings_set_double_setting (MetaInputSettings *input_settings,
- ClutterInputDeviceType type,
- ConfigDoubleFunc func,
- gdouble value)
-{
- GSList *devices, *d;
-
- devices = meta_input_settings_get_devices (input_settings, type);
-
- for (d = devices; d; d = d->next)
- settings_device_set_double_setting (input_settings, d->data, func, value);
-
- g_slist_free (devices);
-}
-
-static void
-settings_device_set_uint_setting (MetaInputSettings *input_settings,
- ClutterInputDevice *device,
- ConfigUintFunc func,
- guint value)
-{
- (func) (input_settings, device, value);
-}
-
-static void
-settings_set_uint_setting (MetaInputSettings *input_settings,
- ClutterInputDeviceType type,
- ConfigUintFunc func,
- guint value)
-{
- GSList *devices, *d;
-
- devices = meta_input_settings_get_devices (input_settings, type);
-
- for (d = devices; d; d = d->next)
- settings_device_set_uint_setting (input_settings, d->data, func, value);
-
- g_slist_free (devices);
-}
-
-static void
-update_touchpad_left_handed (MetaInputSettings *input_settings,
- ClutterInputDevice *device)
-{
- MetaInputSettingsClass *input_settings_class;
- GDesktopTouchpadHandedness handedness;
- MetaInputSettingsPrivate *priv;
- gboolean enabled = FALSE;
-
- if (device &&
- clutter_input_device_get_device_type (device) != CLUTTER_TOUCHPAD_DEVICE)
- return;
-
- priv = meta_input_settings_get_instance_private (input_settings);
- input_settings_class = META_INPUT_SETTINGS_GET_CLASS (input_settings);
- handedness = g_settings_get_enum (priv->touchpad_settings, "left-handed");
-
- switch (handedness)
- {
- case G_DESKTOP_TOUCHPAD_HANDEDNESS_RIGHT:
- enabled = FALSE;
- break;
- case G_DESKTOP_TOUCHPAD_HANDEDNESS_LEFT:
- enabled = TRUE;
- break;
- case G_DESKTOP_TOUCHPAD_HANDEDNESS_MOUSE:
- enabled = g_settings_get_boolean (priv->mouse_settings, "left-handed");
- break;
- default:
- g_assert_not_reached ();
- }
-
- if (device)
- {
- settings_device_set_bool_setting (input_settings, device,
- input_settings_class->set_left_handed,
- enabled);
- }
- else
- {
- settings_set_bool_setting (input_settings, CLUTTER_TOUCHPAD_DEVICE, NULL,
- input_settings_class->set_left_handed,
- enabled);
- }
-}
-
-static void
-update_mouse_left_handed (MetaInputSettings *input_settings,
- ClutterInputDevice *device)
-{
- MetaInputSettingsClass *input_settings_class;
- MetaInputSettingsPrivate *priv;
- gboolean enabled;
-
- if (device &&
- clutter_input_device_get_device_type (device) != CLUTTER_POINTER_DEVICE)
- return;
-
- priv = meta_input_settings_get_instance_private (input_settings);
- input_settings_class = META_INPUT_SETTINGS_GET_CLASS (input_settings);
- enabled = g_settings_get_boolean (priv->mouse_settings, "left-handed");
-
- if (device)
- {
- settings_device_set_bool_setting (input_settings, device,
- input_settings_class->set_left_handed,
- enabled);
- }
- else
- {
- GDesktopTouchpadHandedness touchpad_handedness;
-
- settings_set_bool_setting (input_settings, CLUTTER_POINTER_DEVICE, NULL,
- input_settings_class->set_left_handed,
- enabled);
-
- touchpad_handedness = g_settings_get_enum (priv->touchpad_settings,
- "left-handed");
-
- /* Also update touchpads if they're following mouse settings */
- if (touchpad_handedness == G_DESKTOP_TOUCHPAD_HANDEDNESS_MOUSE)
- update_touchpad_left_handed (input_settings, NULL);
- }
-}
-
-static void
-do_update_pointer_accel_profile (MetaInputSettings *input_settings,
- GSettings *settings,
- ClutterInputDevice *device,
- GDesktopPointerAccelProfile profile)
-{
- MetaInputSettingsPrivate *priv =
- meta_input_settings_get_instance_private (input_settings);
- MetaInputSettingsClass *input_settings_class =
- META_INPUT_SETTINGS_GET_CLASS (input_settings);
-
- if (settings == priv->mouse_settings)
- input_settings_class->set_mouse_accel_profile (input_settings,
- device,
- profile);
- else if (settings == priv->trackball_settings)
- input_settings_class->set_trackball_accel_profile (input_settings,
- device,
- profile);
-}
-
-static void
-update_pointer_accel_profile (MetaInputSettings *input_settings,
- GSettings *settings,
- ClutterInputDevice *device)
-{
- GDesktopPointerAccelProfile profile;
-
- profile = g_settings_get_enum (settings, "accel-profile");
-
- if (device)
- {
- do_update_pointer_accel_profile (input_settings, settings,
- device, profile);
- }
- else
- {
- MetaInputSettingsPrivate *priv =
- meta_input_settings_get_instance_private (input_settings);
- GList *l;
-
- for (l = priv->devices; l; l = l->next)
- {
- device = l->data;
-
- if (clutter_input_device_get_device_mode (device) ==
- CLUTTER_INPUT_MODE_LOGICAL)
- continue;
-
- do_update_pointer_accel_profile (input_settings, settings,
- device, profile);
- }
- }
-}
-
-static GSettings *
-get_settings_for_device_type (MetaInputSettings *input_settings,
- ClutterInputDeviceType type)
-{
- MetaInputSettingsPrivate *priv;
- priv = meta_input_settings_get_instance_private (input_settings);
- switch (type)
- {
- case CLUTTER_POINTER_DEVICE:
- return priv->mouse_settings;
- case CLUTTER_TOUCHPAD_DEVICE:
- return priv->touchpad_settings;
- default:
- return NULL;
- }
-}
-
-static void
-update_middle_click_emulation (MetaInputSettings *input_settings,
- GSettings *settings,
- ClutterInputDevice *device)
-{
- ConfigBoolFunc func;
- const gchar *key = "middle-click-emulation";
- MetaInputSettingsPrivate *priv = meta_input_settings_get_instance_private (input_settings);
-
- if (!settings)
- return;
-
- if (settings == priv->mouse_settings)
- func = META_INPUT_SETTINGS_GET_CLASS (input_settings)->set_mouse_middle_click_emulation;
- else if (settings == priv->touchpad_settings)
- func = META_INPUT_SETTINGS_GET_CLASS (input_settings)->set_touchpad_middle_click_emulation;
- else if (settings == priv->trackball_settings)
- func = META_INPUT_SETTINGS_GET_CLASS (input_settings)->set_trackball_middle_click_emulation;
- else
- return;
-
- if (device)
- {
- settings_device_set_bool_setting (input_settings, device, func,
- g_settings_get_boolean (settings, key));
- }
- else
- {
- settings_set_bool_setting (input_settings, CLUTTER_POINTER_DEVICE,
- NULL, func,
- g_settings_get_boolean (settings, key));
- }
-}
-
-static void
-update_device_speed (MetaInputSettings *input_settings,
- ClutterInputDevice *device)
-{
- GSettings *settings;
- ConfigDoubleFunc func;
- const gchar *key = "speed";
-
- func = META_INPUT_SETTINGS_GET_CLASS (input_settings)->set_speed;
-
- if (device)
- {
- settings = get_settings_for_device_type (input_settings,
- clutter_input_device_get_device_type (device));
- if (!settings)
- return;
-
- settings_device_set_double_setting (input_settings, device, func,
- g_settings_get_double (settings, key));
- }
- else
- {
- settings = get_settings_for_device_type (input_settings, CLUTTER_POINTER_DEVICE);
- settings_set_double_setting (input_settings, CLUTTER_POINTER_DEVICE, func,
- g_settings_get_double (settings, key));
- settings = get_settings_for_device_type (input_settings, CLUTTER_TOUCHPAD_DEVICE);
- settings_set_double_setting (input_settings, CLUTTER_TOUCHPAD_DEVICE, func,
- g_settings_get_double (settings, key));
- }
-}
-
-static void
-update_device_natural_scroll (MetaInputSettings *input_settings,
- ClutterInputDevice *device)
-{
- GSettings *settings;
- ConfigBoolFunc func;
- const gchar *key = "natural-scroll";
-
- func = META_INPUT_SETTINGS_GET_CLASS (input_settings)->set_invert_scroll;
-
- if (device)
- {
- settings = get_settings_for_device_type (input_settings,
- clutter_input_device_get_device_type (device));
- if (!settings)
- return;
-
- settings_device_set_bool_setting (input_settings, device, func,
- g_settings_get_boolean (settings, key));
- }
- else
- {
- settings = get_settings_for_device_type (input_settings, CLUTTER_POINTER_DEVICE);
- settings_set_bool_setting (input_settings, CLUTTER_POINTER_DEVICE,
- NULL, func,
- g_settings_get_boolean (settings, key));
- settings = get_settings_for_device_type (input_settings, CLUTTER_TOUCHPAD_DEVICE);
- settings_set_bool_setting (input_settings, CLUTTER_TOUCHPAD_DEVICE,
- NULL, func,
- g_settings_get_boolean (settings, key));
- }
-}
-
-static void
-update_touchpad_disable_while_typing (MetaInputSettings *input_settings,
- ClutterInputDevice *device)
-{
- GSettings *settings;
- MetaInputSettingsClass *input_settings_class;
- MetaInputSettingsPrivate *priv;
- gboolean enabled;
- const gchar *key = "disable-while-typing";
-
- if (device &&
- clutter_input_device_get_device_type (device) != CLUTTER_TOUCHPAD_DEVICE)
- return;
-
- priv = meta_input_settings_get_instance_private (input_settings);
- input_settings_class = META_INPUT_SETTINGS_GET_CLASS (input_settings);
- enabled = g_settings_get_boolean (priv->touchpad_settings, key);
-
- if (device)
- {
- settings = get_settings_for_device_type (input_settings,
- clutter_input_device_get_device_type (device));
-
- if (!settings)
- return;
-
- settings_device_set_bool_setting (input_settings, device,
- input_settings_class->set_disable_while_typing,
- enabled);
- }
- else
- {
- settings_set_bool_setting (input_settings, CLUTTER_TOUCHPAD_DEVICE, NULL,
- input_settings_class->set_disable_while_typing,
- enabled);
- }
-}
-
-static gboolean
-device_is_tablet_touchpad (MetaInputSettings *input_settings,
- ClutterInputDevice *device)
-{
-#ifdef HAVE_LIBWACOM
- WacomIntegrationFlags flags = 0;
- WacomDevice *wacom_device;
-
- if (clutter_input_device_get_device_type (device) != CLUTTER_TOUCHPAD_DEVICE)
- return FALSE;
-
- wacom_device = meta_input_device_get_wacom_device (META_INPUT_DEVICE (device));
-
- if (wacom_device)
- {
- flags = libwacom_get_integration_flags (wacom_device);
-
- if ((flags & (WACOM_DEVICE_INTEGRATED_SYSTEM |
- WACOM_DEVICE_INTEGRATED_DISPLAY)) == 0)
- return TRUE;
- }
-#endif
-
- return FALSE;
-}
-
-static gboolean
-force_enable_on_tablet (MetaInputSettings *input_settings,
- ClutterInputDevice *device,
- gboolean value)
-{
- return device_is_tablet_touchpad (input_settings, device) || value;
-}
-
-static void
-update_touchpad_tap_enabled (MetaInputSettings *input_settings,
- ClutterInputDevice *device)
-{
- MetaInputSettingsClass *input_settings_class;
- MetaInputSettingsPrivate *priv;
- gboolean enabled;
-
- if (device &&
- clutter_input_device_get_device_type (device) != CLUTTER_TOUCHPAD_DEVICE)
- return;
-
- priv = meta_input_settings_get_instance_private (input_settings);
- input_settings_class = META_INPUT_SETTINGS_GET_CLASS (input_settings);
- enabled = g_settings_get_boolean (priv->touchpad_settings, "tap-to-click");
-
- if (device)
- {
- enabled = force_enable_on_tablet (input_settings, device, enabled);
- settings_device_set_bool_setting (input_settings, device,
- input_settings_class->set_tap_enabled,
- enabled);
- }
- else
- {
- settings_set_bool_setting (input_settings, CLUTTER_TOUCHPAD_DEVICE,
- force_enable_on_tablet,
- input_settings_class->set_tap_enabled,
- enabled);
- }
-}
-
-static void
-update_touchpad_tap_button_map (MetaInputSettings *input_settings,
- ClutterInputDevice *device)
-{
- MetaInputSettingsClass *input_settings_class;
- GDesktopTouchpadTapButtonMap method;
- MetaInputSettingsPrivate *priv;
-
- if (device &&
- clutter_input_device_get_device_type (device) != CLUTTER_TOUCHPAD_DEVICE)
- return;
-
- priv = meta_input_settings_get_instance_private (input_settings);
- input_settings_class = META_INPUT_SETTINGS_GET_CLASS (input_settings);
- method = g_settings_get_enum (priv->touchpad_settings, "tap-button-map");
-
- if (device)
- {
- settings_device_set_uint_setting (input_settings, device,
- input_settings_class->set_tap_button_map,
- method);
- }
- else
- {
- settings_set_uint_setting (input_settings, CLUTTER_TOUCHPAD_DEVICE,
- (ConfigUintFunc) input_settings_class->set_tap_button_map,
- method);
- }
-}
-
-static void
-update_touchpad_tap_and_drag_enabled (MetaInputSettings *input_settings,
- ClutterInputDevice *device)
-{
- MetaInputSettingsClass *input_settings_class;
- MetaInputSettingsPrivate *priv;
- gboolean enabled;
-
- if (device &&
- clutter_input_device_get_device_type (device) != CLUTTER_TOUCHPAD_DEVICE)
- return;
-
- priv = meta_input_settings_get_instance_private (input_settings);
- input_settings_class = META_INPUT_SETTINGS_GET_CLASS (input_settings);
- enabled = g_settings_get_boolean (priv->touchpad_settings, "tap-and-drag");
-
- if (device)
- {
- enabled = force_enable_on_tablet (input_settings, device, enabled);
- settings_device_set_bool_setting (input_settings, device,
- input_settings_class->set_tap_and_drag_enabled,
- enabled);
- }
- else
- {
- settings_set_bool_setting (input_settings, CLUTTER_TOUCHPAD_DEVICE,
- force_enable_on_tablet,
- input_settings_class->set_tap_and_drag_enabled,
- enabled);
- }
-}
-
-static void
-update_touchpad_tap_and_drag_lock_enabled (MetaInputSettings *input_settings,
- ClutterInputDevice *device)
-{
- MetaInputSettingsClass *input_settings_class;
- MetaInputSettingsPrivate *priv;
- gboolean enabled;
-
- if (device &&
- clutter_input_device_get_device_type (device) != CLUTTER_TOUCHPAD_DEVICE)
- return;
-
- priv = meta_input_settings_get_instance_private (input_settings);
- input_settings_class = META_INPUT_SETTINGS_GET_CLASS (input_settings);
- enabled = g_settings_get_boolean (priv->touchpad_settings, "tap-and-drag-lock");
-
- if (device)
- {
- settings_device_set_bool_setting (input_settings, device,
- input_settings_class->set_tap_and_drag_lock_enabled,
- enabled);
- }
- else
- {
- settings_set_bool_setting (input_settings, CLUTTER_TOUCHPAD_DEVICE,
- NULL,
- input_settings_class->set_tap_and_drag_lock_enabled,
- enabled);
- }
-}
-
-static void
-update_touchpad_edge_scroll (MetaInputSettings *input_settings,
- ClutterInputDevice *device)
-{
- MetaInputSettingsClass *input_settings_class;
- gboolean edge_scroll_enabled;
- gboolean two_finger_scroll_enabled;
- gboolean two_finger_scroll_available;
- MetaInputSettingsPrivate *priv;
-
- if (device &&
- clutter_input_device_get_device_type (device) != CLUTTER_TOUCHPAD_DEVICE)
- return;
-
- priv = meta_input_settings_get_instance_private (input_settings);
- input_settings_class = META_INPUT_SETTINGS_GET_CLASS (input_settings);
- edge_scroll_enabled = g_settings_get_boolean (priv->touchpad_settings, "edge-scrolling-enabled");
- two_finger_scroll_enabled = g_settings_get_boolean (priv->touchpad_settings, "two-finger-scrolling-enabled");
- two_finger_scroll_available = g_hash_table_size (priv->two_finger_devices) > 0;
-
- /* If both are enabled we prefer two finger. */
- if (edge_scroll_enabled && two_finger_scroll_enabled && two_finger_scroll_available)
- edge_scroll_enabled = FALSE;
-
- if (device)
- {
- settings_device_set_bool_setting (input_settings, device,
- input_settings_class->set_edge_scroll,
- edge_scroll_enabled);
- }
- else
- {
- settings_set_bool_setting (input_settings, CLUTTER_TOUCHPAD_DEVICE, NULL,
- (ConfigBoolFunc) input_settings_class->set_edge_scroll,
- edge_scroll_enabled);
- }
-}
-
-static void
-update_touchpad_two_finger_scroll (MetaInputSettings *input_settings,
- ClutterInputDevice *device)
-{
- MetaInputSettingsClass *input_settings_class;
- gboolean two_finger_scroll_enabled;
- MetaInputSettingsPrivate *priv;
-
- if (device &&
- clutter_input_device_get_device_type (device) != CLUTTER_TOUCHPAD_DEVICE)
- return;
-
- priv = meta_input_settings_get_instance_private (input_settings);
- input_settings_class = META_INPUT_SETTINGS_GET_CLASS (input_settings);
- two_finger_scroll_enabled = g_settings_get_boolean (priv->touchpad_settings, "two-finger-scrolling-enabled");
-
- /* Disable edge since they can't both be set. */
- if (two_finger_scroll_enabled)
- update_touchpad_edge_scroll (input_settings, device);
-
- if (device)
- {
- settings_device_set_bool_setting (input_settings, device,
- input_settings_class->set_two_finger_scroll,
- two_finger_scroll_enabled);
- }
- else
- {
- settings_set_bool_setting (input_settings, CLUTTER_TOUCHPAD_DEVICE, NULL,
- (ConfigBoolFunc) input_settings_class->set_two_finger_scroll,
- two_finger_scroll_enabled);
- }
-
- /* Edge might have been disabled because two finger was on. */
- if (!two_finger_scroll_enabled)
- update_touchpad_edge_scroll (input_settings, device);
-}
-
-static void
-update_touchpad_click_method (MetaInputSettings *input_settings,
- ClutterInputDevice *device)
-{
- MetaInputSettingsClass *input_settings_class;
- GDesktopTouchpadClickMethod method;
- MetaInputSettingsPrivate *priv;
-
- if (device &&
- clutter_input_device_get_device_type (device) != CLUTTER_TOUCHPAD_DEVICE)
- return;
-
- priv = meta_input_settings_get_instance_private (input_settings);
- input_settings_class = META_INPUT_SETTINGS_GET_CLASS (input_settings);
- method = g_settings_get_enum (priv->touchpad_settings, "click-method");
-
- if (device)
- {
- settings_device_set_uint_setting (input_settings, device,
- input_settings_class->set_click_method,
- method);
- }
- else
- {
- settings_set_uint_setting (input_settings, CLUTTER_TOUCHPAD_DEVICE,
- (ConfigUintFunc) input_settings_class->set_click_method,
- method);
- }
-}
-
-static void
-update_touchpad_send_events (MetaInputSettings *input_settings,
- ClutterInputDevice *device)
-{
- MetaInputSettingsClass *input_settings_class;
- MetaInputSettingsPrivate *priv;
- GDesktopDeviceSendEvents mode;
-
- if (device &&
- clutter_input_device_get_device_type (device) != CLUTTER_TOUCHPAD_DEVICE)
- return;
-
- priv = meta_input_settings_get_instance_private (input_settings);
- input_settings_class = META_INPUT_SETTINGS_GET_CLASS (input_settings);
- mode = g_settings_get_enum (priv->touchpad_settings, "send-events");
-
- if (device)
- {
- settings_device_set_uint_setting (input_settings, device,
- input_settings_class->set_send_events,
- mode);
- }
- else
- {
- settings_set_uint_setting (input_settings, CLUTTER_TOUCHPAD_DEVICE,
- input_settings_class->set_send_events,
- mode);
- }
-}
-
-static void
-update_trackball_scroll_button (MetaInputSettings *input_settings,
- ClutterInputDevice *device)
-{
- MetaInputSettingsClass *input_settings_class;
- MetaInputSettingsPrivate *priv;
- guint button;
- gboolean button_lock;
-
- priv = meta_input_settings_get_instance_private (input_settings);
- input_settings_class = META_INPUT_SETTINGS_GET_CLASS (input_settings);
-
- if (device && !input_settings_class->is_trackball_device (input_settings, device))
- return;
-
- /* This key is 'i' in the schema but it also specifies a minimum
- * range of 0 so the cast here is safe. */
- button = (guint) g_settings_get_int (priv->trackball_settings, "scroll-wheel-emulation-button");
- button_lock = g_settings_get_boolean (priv->trackball_settings, "scroll-wheel-emulation-button-lock");
-
- if (device)
- {
- input_settings_class->set_scroll_button (input_settings, device, button, button_lock);
- }
- else if (!device)
- {
- GList *l;
-
- for (l = priv->devices; l; l = l->next)
- {
- device = l->data;
-
- if (input_settings_class->is_trackball_device (input_settings, device))
- input_settings_class->set_scroll_button (input_settings, device, button, button_lock);
- }
- }
-}
-
-static void
-update_keyboard_repeat (MetaInputSettings *input_settings)
-{
- MetaInputSettingsClass *input_settings_class;
- MetaInputSettingsPrivate *priv;
- guint delay, interval;
- gboolean repeat;
-
- priv = meta_input_settings_get_instance_private (input_settings);
- repeat = g_settings_get_boolean (priv->keyboard_settings, "repeat");
- delay = g_settings_get_uint (priv->keyboard_settings, "delay");
- interval = g_settings_get_uint (priv->keyboard_settings, "repeat-interval");
-
- delay = MAX (1, delay);
- interval = MAX (1, interval);
-
- input_settings_class = META_INPUT_SETTINGS_GET_CLASS (input_settings);
- input_settings_class->set_keyboard_repeat (input_settings,
- repeat, delay, interval);
-}
-
-static void
-update_tablet_keep_aspect (MetaInputSettings *input_settings,
- GSettings *settings,
- ClutterInputDevice *device)
-{
- MetaInputSettingsPrivate *priv;
- MetaInputSettingsClass *input_settings_class;
- DeviceMappingInfo *info;
- gboolean keep_aspect;
- double aspect_ratio;
-
- if (clutter_input_device_get_device_type (device) != CLUTTER_TABLET_DEVICE &&
- clutter_input_device_get_device_type (device) != CLUTTER_PEN_DEVICE &&
- clutter_input_device_get_device_type (device) != CLUTTER_ERASER_DEVICE)
- return;
-
- priv = meta_input_settings_get_instance_private (input_settings);
-
- info = g_hash_table_lookup (priv->mappable_devices, device);
- if (!info)
- return;
-
-#ifdef HAVE_LIBWACOM
- {
- WacomDevice *wacom_device;
-
- wacom_device = meta_input_device_get_wacom_device (META_INPUT_DEVICE (device));
-
- /* Keep aspect only makes sense in external tablets */
- if (wacom_device &&
- libwacom_get_integration_flags (wacom_device) != WACOM_DEVICE_INTEGRATED_NONE)
- return;
- }
-#endif
-
- keep_aspect = g_settings_get_boolean (settings, "keep-aspect");
-
- if (keep_aspect)
- aspect_ratio = info->aspect_ratio;
- else
- aspect_ratio = 0;
-
- input_settings_class = META_INPUT_SETTINGS_GET_CLASS (input_settings);
- input_settings_class->set_tablet_aspect_ratio (input_settings, device, aspect_ratio);
-}
-
-static void
-update_tablet_mapping (MetaInputSettings *input_settings,
- GSettings *settings,
- ClutterInputDevice *device)
-{
- MetaInputSettingsClass *input_settings_class;
- GDesktopTabletMapping mapping;
-
- if (clutter_input_device_get_device_type (device) != CLUTTER_TABLET_DEVICE &&
- clutter_input_device_get_device_type (device) != CLUTTER_PEN_DEVICE &&
- clutter_input_device_get_device_type (device) != CLUTTER_ERASER_DEVICE)
- return;
-
-#ifdef HAVE_LIBWACOM
- {
- WacomDevice *wacom_device;
-
- wacom_device = meta_input_device_get_wacom_device (META_INPUT_DEVICE (device));
-
- /* Tablet mapping only makes sense on external tablets */
- if (wacom_device &&
- (libwacom_get_integration_flags (wacom_device) != WACOM_DEVICE_INTEGRATED_NONE))
- return;
- }
-#endif
-
- input_settings_class = META_INPUT_SETTINGS_GET_CLASS (input_settings);
- mapping = g_settings_get_enum (settings, "mapping");
-
- settings_device_set_uint_setting (input_settings, device,
- input_settings_class->set_tablet_mapping,
- mapping);
-}
-
-static void
-update_tablet_area (MetaInputSettings *input_settings,
- GSettings *settings,
- ClutterInputDevice *device)
-{
- MetaInputSettingsClass *input_settings_class;
- GVariant *variant;
- const gdouble *area;
- gsize n_elems;
-
- if (clutter_input_device_get_device_type (device) != CLUTTER_TABLET_DEVICE &&
- clutter_input_device_get_device_type (device) != CLUTTER_PEN_DEVICE &&
- clutter_input_device_get_device_type (device) != CLUTTER_ERASER_DEVICE)
- return;
-
-#ifdef HAVE_LIBWACOM
- {
- WacomDevice *wacom_device;
-
- wacom_device = meta_input_device_get_wacom_device (META_INPUT_DEVICE (device));
-
- /* Tablet area only makes sense on system/display integrated tablets */
- if (wacom_device &&
- (libwacom_get_integration_flags (wacom_device) &
- (WACOM_DEVICE_INTEGRATED_SYSTEM | WACOM_DEVICE_INTEGRATED_DISPLAY)) == 0)
- return;
- }
-#endif
-
- input_settings_class = META_INPUT_SETTINGS_GET_CLASS (input_settings);
- variant = g_settings_get_value (settings, "area");
-
- area = g_variant_get_fixed_array (variant, &n_elems, sizeof (gdouble));
- if (n_elems == 4)
- {
- input_settings_class->set_tablet_area (input_settings, device,
- area[0], area[1],
- area[2], area[3]);
- }
-
- g_variant_unref (variant);
-}
-
-static void
-update_tablet_left_handed (MetaInputSettings *input_settings,
- GSettings *settings,
- ClutterInputDevice *device)
-{
- MetaInputSettingsClass *input_settings_class;
- gboolean enabled;
-
- if (clutter_input_device_get_device_type (device) != CLUTTER_TABLET_DEVICE &&
- clutter_input_device_get_device_type (device) != CLUTTER_PEN_DEVICE &&
- clutter_input_device_get_device_type (device) != CLUTTER_ERASER_DEVICE &&
- clutter_input_device_get_device_type (device) != CLUTTER_PAD_DEVICE)
- return;
-
-#ifdef HAVE_LIBWACOM
- {
- WacomDevice *wacom_device;
-
- wacom_device = meta_input_device_get_wacom_device (META_INPUT_DEVICE (device));
-
- /* Left handed mode only makes sense on external tablets */
- if (wacom_device &&
- (libwacom_get_integration_flags (wacom_device) != WACOM_DEVICE_INTEGRATED_NONE))
- return;
- }
-#endif
-
- input_settings_class = META_INPUT_SETTINGS_GET_CLASS (input_settings);
- enabled = g_settings_get_boolean (settings, "left-handed");
-
- settings_device_set_bool_setting (input_settings, device,
- input_settings_class->set_left_handed,
- enabled);
-}
-
-static void
-meta_input_settings_changed_cb (GSettings *settings,
- const char *key,
- gpointer user_data)
-{
- MetaInputSettings *input_settings = META_INPUT_SETTINGS (user_data);
- MetaInputSettingsPrivate *priv = meta_input_settings_get_instance_private (input_settings);
-
- if (settings == priv->mouse_settings)
- {
- if (strcmp (key, "left-handed") == 0)
- update_mouse_left_handed (input_settings, NULL);
- else if (strcmp (key, "speed") == 0)
- update_device_speed (input_settings, NULL);
- else if (strcmp (key, "natural-scroll") == 0)
- update_device_natural_scroll (input_settings, NULL);
- else if (strcmp (key, "accel-profile") == 0)
- update_pointer_accel_profile (input_settings, settings, NULL);
- else if (strcmp (key, "middle-click-emulation") == 0)
- update_middle_click_emulation (input_settings, settings, NULL);
- }
- else if (settings == priv->touchpad_settings)
- {
- if (strcmp (key, "left-handed") == 0)
- update_touchpad_left_handed (input_settings, NULL);
- else if (strcmp (key, "speed") == 0)
- update_device_speed (input_settings, NULL);
- else if (strcmp (key, "natural-scroll") == 0)
- update_device_natural_scroll (input_settings, NULL);
- else if (strcmp (key, "tap-to-click") == 0)
- update_touchpad_tap_enabled (input_settings, NULL);
- else if (strcmp (key, "tap-button-map") == 0)
- update_touchpad_tap_button_map (input_settings, NULL);
- else if (strcmp (key, "tap-and-drag") == 0)
- update_touchpad_tap_and_drag_enabled (input_settings, NULL);
- else if (strcmp (key, "tap-and-drag-lock") == 0)
- update_touchpad_tap_and_drag_lock_enabled (input_settings, NULL);
- else if (strcmp(key, "disable-while-typing") == 0)
- update_touchpad_disable_while_typing (input_settings, NULL);
- else if (strcmp (key, "send-events") == 0)
- update_touchpad_send_events (input_settings, NULL);
- else if (strcmp (key, "edge-scrolling-enabled") == 0)
- update_touchpad_edge_scroll (input_settings, NULL);
- else if (strcmp (key, "two-finger-scrolling-enabled") == 0)
- update_touchpad_two_finger_scroll (input_settings, NULL);
- else if (strcmp (key, "click-method") == 0)
- update_touchpad_click_method (input_settings, NULL);
- else if (strcmp (key, "middle-click-emulation") == 0)
- update_middle_click_emulation (input_settings, settings, NULL);
- }
- else if (settings == priv->trackball_settings)
- {
- if (strcmp (key, "scroll-wheel-emulation-button") == 0 ||
- strcmp (key, "scroll-wheel-emulation-button-lock") == 0)
- update_trackball_scroll_button (input_settings, NULL);
- else if (strcmp (key, "accel-profile") == 0)
- update_pointer_accel_profile (input_settings, settings, NULL);
- else if (strcmp (key, "middle-click-emulation") == 0)
- update_middle_click_emulation (input_settings, settings, NULL);
- }
- else if (settings == priv->keyboard_settings)
- {
- if (strcmp (key, "repeat") == 0 ||
- strcmp (key, "repeat-interval") == 0 ||
- strcmp (key, "delay") == 0)
- update_keyboard_repeat (input_settings);
- }
-}
-
-static void
-mapped_device_changed_cb (GSettings *settings,
- const gchar *key,
- DeviceMappingInfo *info)
-{
- if (strcmp (key, "mapping") == 0)
- update_tablet_mapping (info->input_settings, settings, info->device);
- else if (strcmp (key, "area") == 0)
- update_tablet_area (info->input_settings, settings, info->device);
- else if (strcmp (key, "keep-aspect") == 0)
- update_tablet_keep_aspect (info->input_settings, settings, info->device);
- else if (strcmp (key, "left-handed") == 0)
- update_tablet_left_handed (info->input_settings, settings, info->device);
-}
-
-static void
-apply_mappable_device_settings (MetaInputSettings *input_settings,
- DeviceMappingInfo *info)
-{
- ClutterInputDeviceType device_type;
-
- device_type = clutter_input_device_get_device_type (info->device);
-
- if (device_type == CLUTTER_TABLET_DEVICE ||
- device_type == CLUTTER_PEN_DEVICE ||
- device_type == CLUTTER_ERASER_DEVICE ||
- device_type == CLUTTER_PAD_DEVICE)
- {
- update_tablet_mapping (input_settings, info->settings, info->device);
- update_tablet_area (input_settings, info->settings, info->device);
- update_tablet_keep_aspect (input_settings, info->settings, info->device);
- update_tablet_left_handed (input_settings, info->settings, info->device);
- }
-}
-
-struct _keyboard_a11y_settings_flags_pair {
- const char *name;
- MetaKeyboardA11yFlags flag;
-} keyboard_a11y_settings_flags_pair[] = {
- { "enable", META_A11Y_KEYBOARD_ENABLED },
- { "timeout-enable", META_A11Y_TIMEOUT_ENABLED },
- { "mousekeys-enable", META_A11Y_MOUSE_KEYS_ENABLED },
- { "slowkeys-enable", META_A11Y_SLOW_KEYS_ENABLED },
- { "slowkeys-beep-press", META_A11Y_SLOW_KEYS_BEEP_PRESS },
- { "slowkeys-beep-accept", META_A11Y_SLOW_KEYS_BEEP_ACCEPT },
- { "slowkeys-beep-reject", META_A11Y_SLOW_KEYS_BEEP_REJECT },
- { "bouncekeys-enable", META_A11Y_BOUNCE_KEYS_ENABLED },
- { "bouncekeys-beep-reject", META_A11Y_BOUNCE_KEYS_BEEP_REJECT },
- { "togglekeys-enable", META_A11Y_TOGGLE_KEYS_ENABLED },
- { "stickykeys-enable", META_A11Y_STICKY_KEYS_ENABLED },
- { "stickykeys-modifier-beep", META_A11Y_STICKY_KEYS_BEEP },
- { "stickykeys-two-key-off", META_A11Y_STICKY_KEYS_TWO_KEY_OFF },
- { "feature-state-change-beep", META_A11Y_FEATURE_STATE_CHANGE_BEEP },
-};
-
-static void
-load_keyboard_a11y_settings (MetaInputSettings *input_settings)
-{
- MetaInputSettingsPrivate *priv = meta_input_settings_get_instance_private (input_settings);
- MetaKbdA11ySettings kbd_a11y_settings = { 0 };
- guint i;
-
- kbd_a11y_settings.controls = 0;
- for (i = 0; i < G_N_ELEMENTS (keyboard_a11y_settings_flags_pair); i++)
- {
- if (g_settings_get_boolean (priv->keyboard_a11y_settings, keyboard_a11y_settings_flags_pair[i].name))
- kbd_a11y_settings.controls |= keyboard_a11y_settings_flags_pair[i].flag;
- }
-
- kbd_a11y_settings.timeout_delay = g_settings_get_int (priv->keyboard_a11y_settings,
- "disable-timeout");
- kbd_a11y_settings.slowkeys_delay = g_settings_get_int (priv->keyboard_a11y_settings,
- "slowkeys-delay");
- kbd_a11y_settings.debounce_delay = g_settings_get_int (priv->keyboard_a11y_settings,
- "bouncekeys-delay");
- kbd_a11y_settings.mousekeys_init_delay = g_settings_get_int (priv->keyboard_a11y_settings,
- "mousekeys-init-delay");
- kbd_a11y_settings.mousekeys_max_speed = g_settings_get_int (priv->keyboard_a11y_settings,
- "mousekeys-max-speed");
- kbd_a11y_settings.mousekeys_accel_time = g_settings_get_int (priv->keyboard_a11y_settings,
- "mousekeys-accel-time");
-
- priv->kbd_a11y_settings = kbd_a11y_settings;
- g_signal_emit (input_settings, signals[KBD_A11Y_CHANGED], 0, &priv->kbd_a11y_settings);
-}
-
-void
-meta_input_settings_notify_kbd_a11y_change (MetaInputSettings *input_settings,
- MetaKeyboardA11yFlags new_flags,
- MetaKeyboardA11yFlags what_changed)
-{
- MetaInputSettingsPrivate *priv = meta_input_settings_get_instance_private (input_settings);
- guint i;
-
- for (i = 0; i < G_N_ELEMENTS (keyboard_a11y_settings_flags_pair); i++)
- {
- if (keyboard_a11y_settings_flags_pair[i].flag & what_changed)
- g_settings_set_boolean (priv->keyboard_a11y_settings,
- keyboard_a11y_settings_flags_pair[i].name,
- (new_flags & keyboard_a11y_settings_flags_pair[i].flag) ? TRUE : FALSE);
- }
-}
-
-static void
-meta_input_keyboard_a11y_settings_changed (GSettings *settings,
- const char *key,
- gpointer user_data)
-{
- MetaInputSettings *input_settings = META_INPUT_SETTINGS (user_data);
-
- load_keyboard_a11y_settings (input_settings);
-}
-
-static GSettings *
-lookup_device_settings (ClutterInputDevice *device)
-{
- const gchar *group, *schema, *vendor, *product;
- ClutterInputDeviceType type;
- GSettings *settings;
- gchar *path;
-
- type = clutter_input_device_get_device_type (device);
-
- if (type == CLUTTER_TOUCHSCREEN_DEVICE)
- {
- group = "touchscreens";
- schema = "org.gnome.desktop.peripherals.touchscreen";
- }
- else if (type == CLUTTER_TABLET_DEVICE ||
- type == CLUTTER_PEN_DEVICE ||
- type == CLUTTER_ERASER_DEVICE ||
- type == CLUTTER_CURSOR_DEVICE ||
- type == CLUTTER_PAD_DEVICE)
- {
- group = "tablets";
- schema = "org.gnome.desktop.peripherals.tablet";
- }
- else
- return NULL;
-
- vendor = clutter_input_device_get_vendor_id (device);
- product = clutter_input_device_get_product_id (device);
- path = g_strdup_printf ("/org/gnome/desktop/peripherals/%s/%s:%s/",
- group, vendor, product);
-
- settings = g_settings_new_with_path (schema, path);
- g_free (path);
-
- return settings;
-}
-
-static GSettings *
-lookup_tool_settings (ClutterInputDeviceTool *tool,
- ClutterInputDevice *device)
-{
- GSettings *tool_settings;
- guint64 serial;
- gchar *path;
-
- tool_settings = g_object_get_qdata (G_OBJECT (tool), quark_tool_settings);
- if (tool_settings)
- return tool_settings;
-
- serial = clutter_input_device_tool_get_serial (tool);
-
- /* The Wacom driver uses serial 1 for serial-less devices but 1 is not a
- * real serial, so let's custom-case this */
- if (serial == 0 || serial == 1)
- {
- path = g_strdup_printf ("/org/gnome/desktop/peripherals/stylus/default-%s:%s/",
- clutter_input_device_get_vendor_id (device),
- clutter_input_device_get_product_id (device));
- }
- else
- {
- path = g_strdup_printf ("/org/gnome/desktop/peripherals/stylus/%" G_GINT64_MODIFIER "x/",
- serial);
- }
-
- tool_settings =
- g_settings_new_with_path ("org.gnome.desktop.peripherals.tablet.stylus",
- path);
- g_object_set_qdata_full (G_OBJECT (tool), quark_tool_settings, tool_settings,
- (GDestroyNotify) g_object_unref);
- g_free (path);
-
- return tool_settings;
-}
-
-static void
-device_mapping_info_free (DeviceMappingInfo *info)
-{
- g_clear_signal_handler (&info->changed_id, info->settings);
- g_object_unref (info->settings);
- g_free (info->group_modes);
- g_free (info);
-}
-
-static gboolean
-check_add_mappable_device (MetaInputSettings *input_settings,
- ClutterInputDevice *device)
-{
- MetaInputSettingsPrivate *priv;
- DeviceMappingInfo *info;
- ClutterInputDeviceType device_type;
- GSettings *settings;
-
- device_type = clutter_input_device_get_device_type (device);
-
- if ((device_type == CLUTTER_TABLET_DEVICE ||
- device_type == CLUTTER_PEN_DEVICE ||
- device_type == CLUTTER_ERASER_DEVICE ||
- device_type == CLUTTER_PAD_DEVICE) &&
- g_getenv ("MUTTER_DISABLE_WACOM_CONFIGURATION") != NULL)
- return FALSE;
-
- settings = lookup_device_settings (device);
-
- if (!settings)
- return FALSE;
-
- priv = meta_input_settings_get_instance_private (input_settings);
-
- info = g_new0 (DeviceMappingInfo, 1);
- info->input_settings = input_settings;
- info->device = device;
- info->settings = settings;
-
- if (device_type == CLUTTER_PAD_DEVICE)
- {
- info->group_modes =
- g_new0 (guint, clutter_input_device_get_n_mode_groups (device));
- }
-
- info->changed_id = g_signal_connect (settings, "changed",
- G_CALLBACK (mapped_device_changed_cb),
- info);
-
- g_hash_table_insert (priv->mappable_devices, device, info);
-
- apply_mappable_device_settings (input_settings, info);
-
- return TRUE;
-}
-
-static void
-apply_device_settings (MetaInputSettings *input_settings,
- ClutterInputDevice *device)
-{
- MetaInputSettingsPrivate *priv =
- meta_input_settings_get_instance_private (input_settings);
-
- update_device_speed (input_settings, device);
- update_device_natural_scroll (input_settings, device);
-
- update_mouse_left_handed (input_settings, device);
- update_pointer_accel_profile (input_settings,
- priv->mouse_settings,
- device);
-
- update_touchpad_left_handed (input_settings, device);
- update_touchpad_tap_enabled (input_settings, device);
- update_touchpad_tap_button_map (input_settings, device);
- update_touchpad_tap_and_drag_enabled (input_settings, device);
- update_touchpad_tap_and_drag_lock_enabled (input_settings, device);
- update_touchpad_disable_while_typing (input_settings, device);
- update_touchpad_send_events (input_settings, device);
- update_touchpad_two_finger_scroll (input_settings, device);
- update_touchpad_edge_scroll (input_settings, device);
- update_touchpad_click_method (input_settings, device);
-
- update_trackball_scroll_button (input_settings, device);
- update_pointer_accel_profile (input_settings,
- priv->trackball_settings,
- device);
-
- update_middle_click_emulation (input_settings, priv->mouse_settings, device);
- update_middle_click_emulation (input_settings, priv->touchpad_settings, device);
- update_middle_click_emulation (input_settings, priv->trackball_settings, device);
-}
-
-static void
-update_stylus_pressure (MetaInputSettings *input_settings,
- ClutterInputDevice *device,
- ClutterInputDeviceTool *tool)
-{
- MetaInputSettingsClass *input_settings_class;
- GSettings *tool_settings;
- const gint32 *curve;
- GVariant *variant;
- gsize n_elems;
-
- if (clutter_input_device_get_device_type (device) != CLUTTER_TABLET_DEVICE &&
- clutter_input_device_get_device_type (device) != CLUTTER_PEN_DEVICE &&
- clutter_input_device_get_device_type (device) != CLUTTER_ERASER_DEVICE)
- return;
-
- if (!tool)
- return;
-
- tool_settings = lookup_tool_settings (tool, device);
-
- if (clutter_input_device_tool_get_tool_type (tool) ==
- CLUTTER_INPUT_DEVICE_TOOL_ERASER)
- variant = g_settings_get_value (tool_settings, "eraser-pressure-curve");
- else
- variant = g_settings_get_value (tool_settings, "pressure-curve");
-
- curve = g_variant_get_fixed_array (variant, &n_elems, sizeof (gint32));
- if (n_elems != 4)
- return;
-
- input_settings_class = META_INPUT_SETTINGS_GET_CLASS (input_settings);
- input_settings_class->set_stylus_pressure (input_settings, device, tool, curve);
-}
-
-static void
-update_stylus_buttonmap (MetaInputSettings *input_settings,
- ClutterInputDevice *device,
- ClutterInputDeviceTool *tool)
-{
- MetaInputSettingsClass *input_settings_class;
- GDesktopStylusButtonAction primary, secondary, tertiary;
- GSettings *tool_settings;
-
- if (clutter_input_device_get_device_type (device) != CLUTTER_TABLET_DEVICE &&
- clutter_input_device_get_device_type (device) != CLUTTER_PEN_DEVICE &&
- clutter_input_device_get_device_type (device) != CLUTTER_ERASER_DEVICE)
- return;
-
- if (!tool)
- return;
-
- tool_settings = lookup_tool_settings (tool, device);
-
- primary = g_settings_get_enum (tool_settings, "button-action");
- secondary = g_settings_get_enum (tool_settings, "secondary-button-action");
- tertiary = g_settings_get_enum (tool_settings, "tertiary-button-action");
-
- input_settings_class = META_INPUT_SETTINGS_GET_CLASS (input_settings);
- input_settings_class->set_stylus_button_map (input_settings, device, tool,
- primary, secondary, tertiary);
-}
-
-static void
-apply_stylus_settings (MetaInputSettings *input_settings,
- ClutterInputDevice *device,
- ClutterInputDeviceTool *tool)
-{
- update_stylus_pressure (input_settings, device, tool);
- update_stylus_buttonmap (input_settings, device, tool);
-}
-
-static void
-evaluate_two_finger_scrolling (MetaInputSettings *input_settings,
- ClutterInputDevice *device)
-{
- MetaInputSettingsClass *klass;
- MetaInputSettingsPrivate *priv;
-
- if (clutter_input_device_get_device_type (device) != CLUTTER_TOUCHPAD_DEVICE)
- return;
-
- klass = META_INPUT_SETTINGS_GET_CLASS (input_settings);
- priv = meta_input_settings_get_instance_private (input_settings);
-
- if (klass->has_two_finger_scroll (input_settings, device))
- g_hash_table_add (priv->two_finger_devices, device);
-}
-
-void
-meta_input_settings_add_device (MetaInputSettings *input_settings,
- ClutterInputDevice *device)
-{
- MetaInputSettingsPrivate *priv =
- meta_input_settings_get_instance_private (input_settings);
-
- if (clutter_input_device_get_device_mode (device) == CLUTTER_INPUT_MODE_LOGICAL)
- return;
-
- priv->devices = g_list_prepend (priv->devices, device);
- evaluate_two_finger_scrolling (input_settings, device);
-
- apply_device_settings (input_settings, device);
- check_add_mappable_device (input_settings, device);
-}
-
-void
-meta_input_settings_remove_device (MetaInputSettings *input_settings,
- ClutterInputDevice *device)
-{
- MetaInputSettingsPrivate *priv;
-
- priv = meta_input_settings_get_instance_private (input_settings);
- g_hash_table_remove (priv->mappable_devices, device);
- g_hash_table_remove (priv->current_tools, device);
-
- if (g_hash_table_remove (priv->two_finger_devices, device) &&
- g_hash_table_size (priv->two_finger_devices) == 0)
- apply_device_settings (input_settings, NULL);
-
- priv->devices = g_list_remove (priv->devices, device);
-}
-
-static void
-current_tool_changed_cb (GSettings *settings,
- const char *key,
- gpointer user_data)
-{
- CurrentToolInfo *info = user_data;
-
- apply_stylus_settings (info->input_settings, info->device, info->tool);
-}
-
-static CurrentToolInfo *
-current_tool_info_new (MetaInputSettings *input_settings,
- ClutterInputDevice *device,
- ClutterInputDeviceTool *tool)
-{
- CurrentToolInfo *info;
-
- info = g_new0 (CurrentToolInfo, 1);
- info->input_settings = input_settings;
- info->device = device;
- info->tool = tool;
- info->settings = lookup_tool_settings (tool, device);
- info->changed_id =
- g_signal_connect (info->settings, "changed",
- G_CALLBACK (current_tool_changed_cb),
- info);
- return info;
-}
-
-static void
-current_tool_info_free (CurrentToolInfo *info)
-{
- g_clear_signal_handler (&info->changed_id, info->settings);
- g_free (info);
-}
-
-void
-meta_input_settings_notify_tool_change (MetaInputSettings *input_settings,
- ClutterInputDevice *device,
- ClutterInputDeviceTool *tool)
-{
- MetaInputSettingsPrivate *priv;
-
- priv = meta_input_settings_get_instance_private (input_settings);
-
- if (tool)
- {
- CurrentToolInfo *current_tool;
-
- current_tool = current_tool_info_new (input_settings, device, tool);
- g_hash_table_insert (priv->current_tools, device, current_tool);
- apply_stylus_settings (input_settings, device, tool);
- }
- else
- {
- g_hash_table_remove (priv->current_tools, device);
- }
-}
-
-static void
-check_mappable_devices (MetaInputSettings *input_settings)
-{
- MetaInputSettingsPrivate *priv;
- GList *l;
-
- priv = meta_input_settings_get_instance_private (input_settings);
-
- for (l = priv->devices; l; l = l->next)
- {
- ClutterInputDevice *device = l->data;
-
- if (clutter_input_device_get_device_mode (device) == CLUTTER_INPUT_MODE_LOGICAL)
- continue;
-
- check_add_mappable_device (input_settings, device);
- }
-}
-
-static void
-meta_input_settings_constructed (GObject *object)
-{
- MetaInputSettings *input_settings = META_INPUT_SETTINGS (object);
- GSList *devices, *d;
-
- devices = meta_input_settings_get_devices (input_settings, CLUTTER_TOUCHPAD_DEVICE);
- for (d = devices; d; d = d->next)
- evaluate_two_finger_scrolling (input_settings, d->data);
-
- g_slist_free (devices);
-
- apply_device_settings (input_settings, NULL);
- update_keyboard_repeat (input_settings);
- check_mappable_devices (input_settings);
-
- load_keyboard_a11y_settings (input_settings);
-}
-
-static void
-meta_input_settings_class_init (MetaInputSettingsClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- object_class->dispose = meta_input_settings_dispose;
- object_class->constructed = meta_input_settings_constructed;
-
- quark_tool_settings =
- g_quark_from_static_string ("meta-input-settings-tool-settings");
-
- signals[KBD_A11Y_CHANGED] =
- g_signal_new ("kbd-a11y-changed",
- G_TYPE_FROM_CLASS (object_class),
- G_SIGNAL_RUN_LAST,
- 0, NULL, NULL, NULL,
- G_TYPE_NONE, 1,
- G_TYPE_POINTER);
-
-}
-
-static void
-meta_input_settings_init (MetaInputSettings *settings)
-{
- MetaInputSettingsPrivate *priv;
-
- priv = meta_input_settings_get_instance_private (settings);
-
- priv->mouse_settings = g_settings_new ("org.gnome.desktop.peripherals.mouse");
- g_signal_connect (priv->mouse_settings, "changed",
- G_CALLBACK (meta_input_settings_changed_cb), settings);
-
- priv->touchpad_settings = g_settings_new ("org.gnome.desktop.peripherals.touchpad");
- g_signal_connect (priv->touchpad_settings, "changed",
- G_CALLBACK (meta_input_settings_changed_cb), settings);
-
- priv->trackball_settings = g_settings_new ("org.gnome.desktop.peripherals.trackball");
- g_signal_connect (priv->trackball_settings, "changed",
- G_CALLBACK (meta_input_settings_changed_cb), settings);
-
- priv->keyboard_settings = g_settings_new ("org.gnome.desktop.peripherals.keyboard");
- g_signal_connect (priv->keyboard_settings, "changed",
- G_CALLBACK (meta_input_settings_changed_cb), settings);
-
- priv->keyboard_a11y_settings = g_settings_new ("org.gnome.desktop.a11y.keyboard");
- g_signal_connect (priv->keyboard_a11y_settings, "changed",
- G_CALLBACK (meta_input_keyboard_a11y_settings_changed), settings);
-
- priv->mappable_devices =
- g_hash_table_new_full (NULL, NULL, NULL, (GDestroyNotify) device_mapping_info_free);
-
- priv->current_tools =
- g_hash_table_new_full (NULL, NULL, NULL, (GDestroyNotify) current_tool_info_free);
-
- priv->two_finger_devices = g_hash_table_new (NULL, NULL);
-}
-
-void
-meta_input_settings_maybe_save_numlock_state (MetaInputSettings *input_settings,
- gboolean numlock_state)
-{
- MetaInputSettingsPrivate *priv;
-
- priv = meta_input_settings_get_instance_private (input_settings);
-
- if (!g_settings_get_boolean (priv->keyboard_settings, "remember-numlock-state"))
- return;
-
- if (numlock_state == g_settings_get_boolean (priv->keyboard_settings, "numlock-state"))
- return;
-
- g_settings_set_boolean (priv->keyboard_settings, "numlock-state", numlock_state);
-}
-
-gboolean
-meta_input_settings_maybe_restore_numlock_state (MetaInputSettings *input_settings)
-{
- MetaInputSettingsPrivate *priv;
- gboolean numlock_state = FALSE;
-
- priv = meta_input_settings_get_instance_private (input_settings);
-
- if (g_settings_get_boolean (priv->keyboard_settings, "remember-numlock-state"))
- numlock_state = g_settings_get_boolean (priv->keyboard_settings, "numlock-state");
-
- return numlock_state;
-}
-
-void
-meta_input_settings_set_device_matrix (MetaInputSettings *input_settings,
- ClutterInputDevice *device,
- float matrix[6])
-{
- g_return_if_fail (META_IS_INPUT_SETTINGS (input_settings));
- g_return_if_fail (CLUTTER_IS_INPUT_DEVICE (device));
-
- META_INPUT_SETTINGS_GET_CLASS (input_settings)->set_matrix (input_settings,
- device,
- matrix);
-}
-
-void
-meta_input_settings_set_device_enabled (MetaInputSettings *input_settings,
- ClutterInputDevice *device,
- gboolean enabled)
-{
- GDesktopDeviceSendEvents mode;
-
- g_return_if_fail (META_IS_INPUT_SETTINGS (input_settings));
- g_return_if_fail (CLUTTER_IS_INPUT_DEVICE (device));
-
- mode = enabled ?
- G_DESKTOP_DEVICE_SEND_EVENTS_ENABLED :
- G_DESKTOP_DEVICE_SEND_EVENTS_DISABLED;
-
- META_INPUT_SETTINGS_GET_CLASS (input_settings)->set_send_events (input_settings,
- device,
- mode);
-}
-
-void
-meta_input_settings_set_device_aspect_ratio (MetaInputSettings *input_settings,
- ClutterInputDevice *device,
- double aspect_ratio)
-{
- MetaInputSettingsPrivate *priv;
- DeviceMappingInfo *info;
-
- g_return_if_fail (META_IS_INPUT_SETTINGS (input_settings));
- g_return_if_fail (CLUTTER_IS_INPUT_DEVICE (device));
-
- priv = meta_input_settings_get_instance_private (input_settings);
-
- info = g_hash_table_lookup (priv->mappable_devices, device);
- if (!info)
- return;
-
- info->aspect_ratio = aspect_ratio;
- update_tablet_keep_aspect (input_settings, info->settings, device);
-}
-
-void
-meta_input_settings_get_kbd_a11y_settings (MetaInputSettings *input_settings,
- MetaKbdA11ySettings *a11y_settings)
-{
- MetaInputSettingsPrivate *priv;
-
- g_return_if_fail (META_IS_INPUT_SETTINGS (input_settings));
-
- priv = meta_input_settings_get_instance_private (input_settings);
-
- *a11y_settings = priv->kbd_a11y_settings;
-}
diff --git a/src/backends/meta-keymap-utils.c b/src/backends/meta-keymap-utils.c
deleted file mode 100644
index 123eb2303..000000000
--- a/src/backends/meta-keymap-utils.c
+++ /dev/null
@@ -1,56 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-/*
- * Utilities for use with libxkbcommon
- *
- * Copyright 2019 Red Hat, Inc.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "config.h"
-
-#include "backends/meta-keymap-utils.h"
-
-#include <glib.h>
-#include <limits.h>
-
-struct xkb_context *
-meta_create_xkb_context (void)
-{
- struct xkb_context *ctx;
- char xdg[PATH_MAX] = {0};
- const char *env;
-
- /*
- * We can only append search paths in libxkbcommon, so we start with an
- * empty set, then add the XDG dir, then add the default search paths.
- */
- ctx = xkb_context_new (XKB_CONTEXT_NO_DEFAULT_INCLUDES);
-
- env = g_getenv ("XDG_CONFIG_HOME");
- if (env)
- {
- g_snprintf (xdg, sizeof xdg, "%s/xkb", env);
- }
- else if ((env = g_getenv ("HOME")))
- {
- g_snprintf (xdg, sizeof xdg, "%s/.config/xkb", env);
- }
-
- if (env)
- xkb_context_include_path_append (ctx, xdg);
- xkb_context_include_path_append_default (ctx);
-
- return ctx;
-}
diff --git a/src/backends/meta-keymap-utils.h b/src/backends/meta-keymap-utils.h
deleted file mode 100644
index 3806824e4..000000000
--- a/src/backends/meta-keymap-utils.h
+++ /dev/null
@@ -1,28 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-/*
- * Utilities for use with libxkbcommon
- *
- * Copyright 2020 Red Hat, Inc.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef META_KEYMAP_UTILS_H
-#define META_KEYMAP_UTILS_H
-
-#include <xkbcommon/xkbcommon.h>
-
-struct xkb_context * meta_create_xkb_context (void);
-
-#endif /* META_KEYMAP_UTILS_H */
diff --git a/src/backends/meta-logical-monitor.c b/src/backends/meta-logical-monitor.c
deleted file mode 100644
index b562e5acb..000000000
--- a/src/backends/meta-logical-monitor.c
+++ /dev/null
@@ -1,343 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2016 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-
-/**
- * SECTION:meta-logical-monitor
- * @title: MetaLogicalMonitor
- * @short_description: An abstraction for a monitor(set) and its configuration.
- *
- * A logical monitor is a group of one or more physical monitors that
- * must behave and be treated as single one. This happens, for example,
- * when 2 monitors are mirrored. Each physical monitor is represented
- * by a #MetaMonitor.
- *
- * #MetaLogicalMonitor has a single viewport, with its owns transformations
- * (such as scaling), that are applied to all the #MetaMonitor<!-- -->s that
- * are grouped by it.
- *
- * #MetaLogicalMonitor provides an abstraction that makes it easy to handle
- * the specifics of setting up different #MetaMonitor<!-- -->s. It then can
- * be used more easily by #MetaRendererView.
- */
-
-#include "config.h"
-
-#include "backends/meta-logical-monitor.h"
-
-#include "backends/meta-backend-private.h"
-#include "backends/meta-crtc.h"
-#include "backends/meta-output.h"
-
-G_DEFINE_TYPE (MetaLogicalMonitor, meta_logical_monitor, G_TYPE_OBJECT)
-
-static MetaMonitor *
-get_first_monitor (MetaMonitorManager *monitor_manager,
- GList *monitor_configs)
-{
- MetaMonitorConfig *first_monitor_config;
- MetaMonitorSpec *first_monitor_spec;
-
- first_monitor_config = g_list_first (monitor_configs)->data;
- first_monitor_spec = first_monitor_config->monitor_spec;
-
- return meta_monitor_manager_get_monitor_from_spec (monitor_manager,
- first_monitor_spec);
-}
-
-typedef struct
-{
- MetaMonitorManager *monitor_manager;
- MetaLogicalMonitor *logical_monitor;
-} AddMonitorFromConfigData;
-
-static void
-add_monitor_from_config (MetaMonitorConfig *monitor_config,
- AddMonitorFromConfigData *data)
-{
- MetaMonitorSpec *monitor_spec;
- MetaMonitor *monitor;
-
- monitor_spec = monitor_config->monitor_spec;
- monitor = meta_monitor_manager_get_monitor_from_spec (data->monitor_manager,
- monitor_spec);
-
- meta_logical_monitor_add_monitor (data->logical_monitor, monitor);
-}
-
-MetaLogicalMonitor *
-meta_logical_monitor_new (MetaMonitorManager *monitor_manager,
- MetaLogicalMonitorConfig *logical_monitor_config,
- int monitor_number)
-{
- MetaLogicalMonitor *logical_monitor;
- GList *monitor_configs;
- MetaMonitor *first_monitor;
- MetaOutput *main_output;
-
- logical_monitor = g_object_new (META_TYPE_LOGICAL_MONITOR, NULL);
-
- monitor_configs = logical_monitor_config->monitor_configs;
- first_monitor = get_first_monitor (monitor_manager, monitor_configs);
- main_output = meta_monitor_get_main_output (first_monitor);
-
- logical_monitor->number = monitor_number;
- logical_monitor->winsys_id = meta_output_get_id (main_output);
- logical_monitor->scale = logical_monitor_config->scale;
- logical_monitor->transform = logical_monitor_config->transform;
- logical_monitor->in_fullscreen = -1;
- logical_monitor->rect = logical_monitor_config->layout;
-
- logical_monitor->is_presentation = TRUE;
- g_list_foreach (monitor_configs, (GFunc) add_monitor_from_config,
- &(AddMonitorFromConfigData) {
- .monitor_manager = monitor_manager,
- .logical_monitor = logical_monitor
- });
-
- return logical_monitor;
-}
-
-static MetaMonitorTransform
-derive_monitor_transform (MetaMonitor *monitor)
-{
- MetaOutput *main_output;
- MetaCrtc *crtc;
- const MetaCrtcConfig *crtc_config;
- MetaMonitorTransform transform;
-
- main_output = meta_monitor_get_main_output (monitor);
- crtc = meta_output_get_assigned_crtc (main_output);
- crtc_config = meta_crtc_get_config (crtc);
- transform = crtc_config->transform;
-
- return meta_monitor_crtc_to_logical_transform (monitor, transform);
-}
-
-MetaLogicalMonitor *
-meta_logical_monitor_new_derived (MetaMonitorManager *monitor_manager,
- MetaMonitor *monitor,
- MetaRectangle *layout,
- float scale,
- int monitor_number)
-{
- MetaLogicalMonitor *logical_monitor;
- MetaOutput *main_output;
- MetaMonitorTransform transform;
-
- logical_monitor = g_object_new (META_TYPE_LOGICAL_MONITOR, NULL);
-
- transform = derive_monitor_transform (monitor);
-
- main_output = meta_monitor_get_main_output (monitor);
- logical_monitor->number = monitor_number;
- logical_monitor->winsys_id = meta_output_get_id (main_output);
- logical_monitor->scale = scale;
- logical_monitor->transform = transform;
- logical_monitor->in_fullscreen = -1;
- logical_monitor->rect = *layout;
-
- logical_monitor->is_presentation = TRUE;
- meta_logical_monitor_add_monitor (logical_monitor, monitor);
-
- return logical_monitor;
-}
-
-void
-meta_logical_monitor_add_monitor (MetaLogicalMonitor *logical_monitor,
- MetaMonitor *monitor)
-{
- GList *l;
- gboolean is_presentation;
-
- is_presentation = logical_monitor->is_presentation;
- logical_monitor->monitors = g_list_append (logical_monitor->monitors,
- g_object_ref (monitor));
-
- for (l = logical_monitor->monitors; l; l = l->next)
- {
- MetaMonitor *monitor = l->data;
- GList *outputs;
- GList *l_output;
-
- outputs = meta_monitor_get_outputs (monitor);
- for (l_output = outputs; l_output; l_output = l_output->next)
- {
- MetaOutput *output = l_output->data;
-
- is_presentation = (is_presentation &&
- meta_output_is_presentation (output));
- }
- }
-
- logical_monitor->is_presentation = is_presentation;
-
- meta_monitor_set_logical_monitor (monitor, logical_monitor);
-}
-
-gboolean
-meta_logical_monitor_is_primary (MetaLogicalMonitor *logical_monitor)
-{
- return logical_monitor->is_primary;
-}
-
-void
-meta_logical_monitor_make_primary (MetaLogicalMonitor *logical_monitor)
-{
- logical_monitor->is_primary = TRUE;
-}
-
-float
-meta_logical_monitor_get_scale (MetaLogicalMonitor *logical_monitor)
-{
- return logical_monitor->scale;
-}
-
-MetaMonitorTransform
-meta_logical_monitor_get_transform (MetaLogicalMonitor *logical_monitor)
-{
- return logical_monitor->transform;
-}
-
-MetaRectangle
-meta_logical_monitor_get_layout (MetaLogicalMonitor *logical_monitor)
-{
- return logical_monitor->rect;
-}
-
-GList *
-meta_logical_monitor_get_monitors (MetaLogicalMonitor *logical_monitor)
-{
- return logical_monitor->monitors;
-}
-
-typedef struct _ForeachCrtcData
-{
- MetaLogicalMonitor *logical_monitor;
- MetaLogicalMonitorCrtcFunc func;
- gpointer user_data;
-} ForeachCrtcData;
-
-static gboolean
-foreach_crtc (MetaMonitor *monitor,
- MetaMonitorMode *mode,
- MetaMonitorCrtcMode *monitor_crtc_mode,
- gpointer user_data,
- GError **error)
-{
- ForeachCrtcData *data = user_data;
-
- data->func (data->logical_monitor,
- monitor,
- monitor_crtc_mode->output,
- meta_output_get_assigned_crtc (monitor_crtc_mode->output),
- data->user_data);
-
- return TRUE;
-}
-
-void
-meta_logical_monitor_foreach_crtc (MetaLogicalMonitor *logical_monitor,
- MetaLogicalMonitorCrtcFunc func,
- gpointer user_data)
-{
- GList *l;
-
- for (l = logical_monitor->monitors; l; l = l->next)
- {
- MetaMonitor *monitor = l->data;
- MetaMonitorMode *mode;
- ForeachCrtcData data = {
- .logical_monitor = logical_monitor,
- .func = func,
- .user_data = user_data
- };
-
- mode = meta_monitor_get_current_mode (monitor);
- meta_monitor_mode_foreach_crtc (monitor, mode, foreach_crtc, &data, NULL);
- }
-}
-
-static void
-meta_logical_monitor_init (MetaLogicalMonitor *logical_monitor)
-{
-}
-
-static void
-meta_logical_monitor_dispose (GObject *object)
-{
- MetaLogicalMonitor *logical_monitor = META_LOGICAL_MONITOR (object);
-
- if (logical_monitor->monitors)
- {
- g_list_free_full (logical_monitor->monitors, g_object_unref);
- logical_monitor->monitors = NULL;
- }
-
- G_OBJECT_CLASS (meta_logical_monitor_parent_class)->dispose (object);
-}
-
-static void
-meta_logical_monitor_class_init (MetaLogicalMonitorClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- object_class->dispose = meta_logical_monitor_dispose;
-}
-
-gboolean
-meta_logical_monitor_has_neighbor (MetaLogicalMonitor *logical_monitor,
- MetaLogicalMonitor *neighbor,
- MetaDisplayDirection neighbor_direction)
-{
- switch (neighbor_direction)
- {
- case META_DISPLAY_RIGHT:
- if (neighbor->rect.x == (logical_monitor->rect.x +
- logical_monitor->rect.width) &&
- meta_rectangle_vert_overlap (&neighbor->rect,
- &logical_monitor->rect))
- return TRUE;
- break;
- case META_DISPLAY_LEFT:
- if (logical_monitor->rect.x == (neighbor->rect.x +
- neighbor->rect.width) &&
- meta_rectangle_vert_overlap (&neighbor->rect,
- &logical_monitor->rect))
- return TRUE;
- break;
- case META_DISPLAY_UP:
- if (logical_monitor->rect.y == (neighbor->rect.y +
- neighbor->rect.height) &&
- meta_rectangle_horiz_overlap (&neighbor->rect,
- &logical_monitor->rect))
- return TRUE;
- break;
- case META_DISPLAY_DOWN:
- if (neighbor->rect.y == (logical_monitor->rect.y +
- logical_monitor->rect.height) &&
- meta_rectangle_horiz_overlap (&neighbor->rect,
- &logical_monitor->rect))
- return TRUE;
- break;
- }
-
- return FALSE;
-}
diff --git a/src/backends/meta-logical-monitor.h b/src/backends/meta-logical-monitor.h
deleted file mode 100644
index d5ef1da83..000000000
--- a/src/backends/meta-logical-monitor.h
+++ /dev/null
@@ -1,107 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2016 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-
-#ifndef META_LOGICAL_MONITOR_H
-#define META_LOGICAL_MONITOR_H
-
-#include <glib-object.h>
-
-#include "backends/meta-monitor.h"
-#include "backends/meta-monitor-config-manager.h"
-#include "backends/meta-monitor-manager-private.h"
-#include "core/util-private.h"
-#include "meta/boxes.h"
-
-#define META_MAX_OUTPUTS_PER_MONITOR 4
-
-struct _MetaLogicalMonitor
-{
- GObject parent;
-
- int number;
- MetaRectangle rect;
- gboolean is_primary;
- gboolean is_presentation; /* XXX: not yet used */
- gboolean in_fullscreen;
- float scale;
- MetaMonitorTransform transform;
-
- /* The primary or first output for this monitor, 0 if we can't figure out.
- It can be matched to a winsys_id of a MetaOutput.
-
- This is used as an opaque token on reconfiguration when switching from
- clone to extended, to decide on what output the windows should go next
- (it's an attempt to keep windows on the same monitor, and preferably on
- the primary one).
- */
- uint64_t winsys_id;
-
- GList *monitors;
-};
-
-#define META_TYPE_LOGICAL_MONITOR (meta_logical_monitor_get_type ())
-G_DECLARE_FINAL_TYPE (MetaLogicalMonitor, meta_logical_monitor,
- META, LOGICAL_MONITOR,
- GObject)
-
-typedef void (* MetaLogicalMonitorCrtcFunc) (MetaLogicalMonitor *logical_monitor,
- MetaMonitor *monitor,
- MetaOutput *output,
- MetaCrtc *crtc,
- gpointer user_data);
-
-MetaLogicalMonitor * meta_logical_monitor_new (MetaMonitorManager *monitor_manager,
- MetaLogicalMonitorConfig *logical_monitor_config,
- int monitor_number);
-
-MetaLogicalMonitor * meta_logical_monitor_new_derived (MetaMonitorManager *monitor_manager,
- MetaMonitor *monitor,
- MetaRectangle *layout,
- float scale,
- int monitor_number);
-
-void meta_logical_monitor_add_monitor (MetaLogicalMonitor *logical_monitor,
- MetaMonitor *monitor);
-
-META_EXPORT_TEST
-gboolean meta_logical_monitor_is_primary (MetaLogicalMonitor *logical_monitor);
-
-void meta_logical_monitor_make_primary (MetaLogicalMonitor *logical_monitor);
-
-float meta_logical_monitor_get_scale (MetaLogicalMonitor *logical_monitor);
-
-MetaMonitorTransform meta_logical_monitor_get_transform (MetaLogicalMonitor *logical_monitor);
-
-META_EXPORT_TEST
-MetaRectangle meta_logical_monitor_get_layout (MetaLogicalMonitor *logical_monitor);
-
-META_EXPORT_TEST
-GList * meta_logical_monitor_get_monitors (MetaLogicalMonitor *logical_monitor);
-
-gboolean meta_logical_monitor_has_neighbor (MetaLogicalMonitor *logical_monitor,
- MetaLogicalMonitor *neighbor,
- MetaDisplayDirection neighbor_dir);
-
-void meta_logical_monitor_foreach_crtc (MetaLogicalMonitor *logical_monitor,
- MetaLogicalMonitorCrtcFunc func,
- gpointer user_data);
-
-#endif /* META_LOGICAL_MONITOR_H */
diff --git a/src/backends/meta-monitor-config-manager.c b/src/backends/meta-monitor-config-manager.c
deleted file mode 100644
index 0253e072f..000000000
--- a/src/backends/meta-monitor-config-manager.c
+++ /dev/null
@@ -1,1899 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2016 Red Hat
- * Copyright (c) 2018 DisplayLink (UK) Ltd.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-
-#include "config.h"
-
-#include "backends/meta-monitor-config-manager.h"
-
-#include "backends/meta-backend-private.h"
-#include "backends/meta-monitor-config-migration.h"
-#include "backends/meta-monitor-config-store.h"
-#include "backends/meta-monitor-manager-private.h"
-#include "backends/meta-output.h"
-#include "core/boxes-private.h"
-
-#define CONFIG_HISTORY_MAX_SIZE 3
-
-struct _MetaMonitorConfigManager
-{
- GObject parent;
-
- MetaMonitorManager *monitor_manager;
-
- MetaMonitorConfigStore *config_store;
-
- MetaMonitorsConfig *current_config;
- GQueue config_history;
-};
-
-G_DEFINE_TYPE (MetaMonitorConfigManager, meta_monitor_config_manager,
- G_TYPE_OBJECT)
-
-G_DEFINE_TYPE (MetaMonitorsConfig, meta_monitors_config,
- G_TYPE_OBJECT)
-
-static void
-meta_crtc_assignment_free (MetaCrtcAssignment *assignment);
-
-static void
-meta_output_assignment_free (MetaOutputAssignment *assignment);
-
-MetaMonitorConfigManager *
-meta_monitor_config_manager_new (MetaMonitorManager *monitor_manager)
-{
- MetaMonitorConfigManager *config_manager;
-
- config_manager = g_object_new (META_TYPE_MONITOR_CONFIG_MANAGER, NULL);
- config_manager->monitor_manager = monitor_manager;
- config_manager->config_store =
- meta_monitor_config_store_new (monitor_manager);
-
- return config_manager;
-}
-
-MetaMonitorConfigStore *
-meta_monitor_config_manager_get_store (MetaMonitorConfigManager *config_manager)
-{
- return config_manager->config_store;
-}
-
-static gboolean
-is_crtc_reserved (MetaCrtc *crtc,
- GArray *reserved_crtcs)
-{
- unsigned int i;
-
- for (i = 0; i < reserved_crtcs->len; i++)
- {
- uint64_t id;
-
- id = g_array_index (reserved_crtcs, uint64_t, i);
- if (id == meta_crtc_get_id (crtc))
- return TRUE;
- }
-
- return FALSE;
-}
-
-static gboolean
-is_crtc_assigned (MetaCrtc *crtc,
- GPtrArray *crtc_assignments)
-{
- unsigned int i;
-
- for (i = 0; i < crtc_assignments->len; i++)
- {
- MetaCrtcAssignment *assigned_crtc_assignment =
- g_ptr_array_index (crtc_assignments, i);
-
- if (assigned_crtc_assignment->crtc == crtc)
- return TRUE;
- }
-
- return FALSE;
-}
-
-static MetaCrtc *
-find_unassigned_crtc (MetaOutput *output,
- GPtrArray *crtc_assignments,
- GArray *reserved_crtcs)
-{
- MetaCrtc *crtc;
- const MetaOutputInfo *output_info;
- unsigned int i;
-
- crtc = meta_output_get_assigned_crtc (output);
- if (crtc && !is_crtc_assigned (crtc, crtc_assignments))
- return crtc;
-
- output_info = meta_output_get_info (output);
-
- /* then try to assign a CRTC that wasn't used */
- for (i = 0; i < output_info->n_possible_crtcs; i++)
- {
- crtc = output_info->possible_crtcs[i];
-
- if (is_crtc_assigned (crtc, crtc_assignments))
- continue;
-
- if (is_crtc_reserved (crtc, reserved_crtcs))
- continue;
-
- return crtc;
- }
-
- /* finally just give a CRTC that we haven't assigned */
- for (i = 0; i < output_info->n_possible_crtcs; i++)
- {
- crtc = output_info->possible_crtcs[i];
-
- if (is_crtc_assigned (crtc, crtc_assignments))
- continue;
-
- return crtc;
- }
-
- return NULL;
-}
-
-typedef struct
-{
- MetaMonitorManager *monitor_manager;
- MetaMonitorsConfig *config;
- MetaLogicalMonitorConfig *logical_monitor_config;
- MetaMonitorConfig *monitor_config;
- GPtrArray *crtc_assignments;
- GPtrArray *output_assignments;
- GArray *reserved_crtcs;
-} MonitorAssignmentData;
-
-static gboolean
-assign_monitor_crtc (MetaMonitor *monitor,
- MetaMonitorMode *mode,
- MetaMonitorCrtcMode *monitor_crtc_mode,
- gpointer user_data,
- GError **error)
-{
- MonitorAssignmentData *data = user_data;
- MetaOutput *output;
- MetaCrtc *crtc;
- MetaMonitorTransform transform;
- MetaMonitorTransform crtc_transform;
- MetaMonitorTransform crtc_hw_transform;
- int crtc_x, crtc_y;
- float x_offset, y_offset;
- float scale = 0.0;
- float width, height;
- MetaCrtcMode *crtc_mode;
- const MetaCrtcModeInfo *crtc_mode_info;
- graphene_rect_t crtc_layout;
- MetaCrtcAssignment *crtc_assignment;
- MetaOutputAssignment *output_assignment;
- MetaMonitorConfig *first_monitor_config;
- gboolean assign_output_as_primary;
- gboolean assign_output_as_presentation;
-
- output = monitor_crtc_mode->output;
-
- crtc = find_unassigned_crtc (output,
- data->crtc_assignments,
- data->reserved_crtcs);
-
- if (!crtc)
- {
- MetaMonitorSpec *monitor_spec = meta_monitor_get_spec (monitor);
-
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- "No available CRTC for monitor '%s %s' not found",
- monitor_spec->vendor, monitor_spec->product);
- return FALSE;
- }
-
- transform = data->logical_monitor_config->transform;
- crtc_transform = meta_monitor_logical_to_crtc_transform (monitor, transform);
- if (meta_monitor_manager_is_transform_handled (data->monitor_manager,
- crtc,
- crtc_transform))
- crtc_hw_transform = crtc_transform;
- else
- crtc_hw_transform = META_MONITOR_TRANSFORM_NORMAL;
-
- meta_monitor_calculate_crtc_pos (monitor, mode, output, crtc_transform,
- &crtc_x, &crtc_y);
-
- x_offset = data->logical_monitor_config->layout.x;
- y_offset = data->logical_monitor_config->layout.y;
-
- switch (data->config->layout_mode)
- {
- case META_LOGICAL_MONITOR_LAYOUT_MODE_LOGICAL:
- scale = data->logical_monitor_config->scale;
- break;
- case META_LOGICAL_MONITOR_LAYOUT_MODE_PHYSICAL:
- scale = 1.0;
- break;
- }
-
- crtc_mode = monitor_crtc_mode->crtc_mode;
- crtc_mode_info = meta_crtc_mode_get_info (monitor_crtc_mode->crtc_mode);
-
- if (meta_monitor_transform_is_rotated (crtc_transform))
- {
- width = crtc_mode_info->height / scale;
- height = crtc_mode_info->width / scale;
- }
- else
- {
- width = crtc_mode_info->width / scale;
- height = crtc_mode_info->height / scale;
- }
-
- crtc_layout = GRAPHENE_RECT_INIT (x_offset + (crtc_x / scale),
- y_offset + (crtc_y / scale),
- width,
- height);
-
- crtc_assignment = g_new0 (MetaCrtcAssignment, 1);
- *crtc_assignment = (MetaCrtcAssignment) {
- .crtc = crtc,
- .mode = crtc_mode,
- .layout = crtc_layout,
- .transform = crtc_hw_transform,
- .outputs = g_ptr_array_new ()
- };
- g_ptr_array_add (crtc_assignment->outputs, output);
-
- /*
- * Only one output can be marked as primary (due to Xrandr limitation),
- * so only mark the main output of the first monitor in the logical monitor
- * as such.
- */
- first_monitor_config = data->logical_monitor_config->monitor_configs->data;
- if (data->logical_monitor_config->is_primary &&
- data->monitor_config == first_monitor_config &&
- meta_monitor_get_main_output (monitor) == output)
- assign_output_as_primary = TRUE;
- else
- assign_output_as_primary = FALSE;
-
- if (data->logical_monitor_config->is_presentation)
- assign_output_as_presentation = TRUE;
- else
- assign_output_as_presentation = FALSE;
-
- output_assignment = g_new0 (MetaOutputAssignment, 1);
- *output_assignment = (MetaOutputAssignment) {
- .output = output,
- .is_primary = assign_output_as_primary,
- .is_presentation = assign_output_as_presentation,
- .is_underscanning = data->monitor_config->enable_underscanning
- };
-
- g_ptr_array_add (data->crtc_assignments, crtc_assignment);
- g_ptr_array_add (data->output_assignments, output_assignment);
-
- return TRUE;
-}
-
-static gboolean
-assign_monitor_crtcs (MetaMonitorManager *manager,
- MetaMonitorsConfig *config,
- MetaLogicalMonitorConfig *logical_monitor_config,
- MetaMonitorConfig *monitor_config,
- GPtrArray *crtc_assignments,
- GPtrArray *output_assignments,
- GArray *reserved_crtcs,
- GError **error)
-{
- MetaMonitorSpec *monitor_spec = monitor_config->monitor_spec;
- MetaMonitorModeSpec *monitor_mode_spec = monitor_config->mode_spec;
- MetaMonitor *monitor;
- MetaMonitorMode *monitor_mode;
- MonitorAssignmentData data;
-
- monitor = meta_monitor_manager_get_monitor_from_spec (manager, monitor_spec);
- if (!monitor)
- {
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- "Configured monitor '%s %s' not found",
- monitor_spec->vendor, monitor_spec->product);
- return FALSE;
- }
-
- monitor_mode = meta_monitor_get_mode_from_spec (monitor, monitor_mode_spec);
- if (!monitor_mode)
- {
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- "Invalid mode %dx%d (%f) for monitor '%s %s'",
- monitor_mode_spec->width, monitor_mode_spec->height,
- monitor_mode_spec->refresh_rate,
- monitor_spec->vendor, monitor_spec->product);
- return FALSE;
- }
-
- data = (MonitorAssignmentData) {
- .monitor_manager = manager,
- .config = config,
- .logical_monitor_config = logical_monitor_config,
- .monitor_config = monitor_config,
- .crtc_assignments = crtc_assignments,
- .output_assignments = output_assignments,
- .reserved_crtcs = reserved_crtcs
- };
- if (!meta_monitor_mode_foreach_crtc (monitor, monitor_mode,
- assign_monitor_crtc,
- &data,
- error))
- return FALSE;
-
- return TRUE;
-}
-
-static gboolean
-assign_logical_monitor_crtcs (MetaMonitorManager *manager,
- MetaMonitorsConfig *config,
- MetaLogicalMonitorConfig *logical_monitor_config,
- GPtrArray *crtc_assignments,
- GPtrArray *output_assignments,
- GArray *reserved_crtcs,
- GError **error)
-{
- GList *l;
-
- for (l = logical_monitor_config->monitor_configs; l; l = l->next)
- {
- MetaMonitorConfig *monitor_config = l->data;
-
- if (!assign_monitor_crtcs (manager,
- config,
- logical_monitor_config,
- monitor_config,
- crtc_assignments, output_assignments,
- reserved_crtcs, error))
- return FALSE;
- }
-
- return TRUE;
-}
-
-gboolean
-meta_monitor_config_manager_assign (MetaMonitorManager *manager,
- MetaMonitorsConfig *config,
- GPtrArray **out_crtc_assignments,
- GPtrArray **out_output_assignments,
- GError **error)
-{
- GPtrArray *crtc_assignments;
- GPtrArray *output_assignments;
- GArray *reserved_crtcs;
- GList *l;
-
- crtc_assignments =
- g_ptr_array_new_with_free_func ((GDestroyNotify) meta_crtc_assignment_free);
- output_assignments =
- g_ptr_array_new_with_free_func ((GDestroyNotify) meta_output_assignment_free);
- reserved_crtcs = g_array_new (FALSE, FALSE, sizeof (uint64_t));
-
- for (l = config->logical_monitor_configs; l; l = l->next)
- {
- MetaLogicalMonitorConfig *logical_monitor_config = l->data;
- GList *k;
-
- for (k = logical_monitor_config->monitor_configs; k; k = k->next)
- {
- MetaMonitorConfig *monitor_config = k->data;
- MetaMonitorSpec *monitor_spec = monitor_config->monitor_spec;
- MetaMonitor *monitor;
- GList *o;
-
- monitor = meta_monitor_manager_get_monitor_from_spec (manager, monitor_spec);
-
- for (o = meta_monitor_get_outputs (monitor); o; o = o->next)
- {
- MetaOutput *output = o->data;
- MetaCrtc *crtc;
-
- crtc = meta_output_get_assigned_crtc (output);
- if (crtc)
- {
- uint64_t crtc_id = meta_crtc_get_id (crtc);
-
- g_array_append_val (reserved_crtcs, crtc_id);
- }
- }
- }
- }
-
- for (l = config->logical_monitor_configs; l; l = l->next)
- {
- MetaLogicalMonitorConfig *logical_monitor_config = l->data;
-
- if (!assign_logical_monitor_crtcs (manager,
- config, logical_monitor_config,
- crtc_assignments, output_assignments,
- reserved_crtcs, error))
- {
- g_ptr_array_free (crtc_assignments, TRUE);
- g_ptr_array_free (output_assignments, TRUE);
- g_array_free (reserved_crtcs, TRUE);
- return FALSE;
- }
- }
-
- g_array_free (reserved_crtcs, TRUE);
-
- *out_crtc_assignments = crtc_assignments;
- *out_output_assignments = output_assignments;
-
- return TRUE;
-}
-
-static gboolean
-is_lid_closed (MetaMonitorManager *monitor_manager)
-{
- MetaBackend *backend;
-
- backend = meta_monitor_manager_get_backend (monitor_manager);
- return meta_backend_is_lid_closed (backend);
-}
-
-MetaMonitorsConfigKey *
-meta_create_monitors_config_key_for_current_state (MetaMonitorManager *monitor_manager)
-{
- MetaMonitorsConfigKey *config_key;
- MetaMonitorSpec *laptop_monitor_spec;
- GList *l;
- GList *monitor_specs;
-
- laptop_monitor_spec = NULL;
- monitor_specs = NULL;
- for (l = monitor_manager->monitors; l; l = l->next)
- {
- MetaMonitor *monitor = l->data;
- MetaMonitorSpec *monitor_spec;
-
- if (meta_monitor_is_laptop_panel (monitor))
- {
- laptop_monitor_spec = meta_monitor_get_spec (monitor);
-
- if (is_lid_closed (monitor_manager))
- continue;
- }
-
- monitor_spec = meta_monitor_spec_clone (meta_monitor_get_spec (monitor));
- monitor_specs = g_list_prepend (monitor_specs, monitor_spec);
- }
-
- if (!monitor_specs && laptop_monitor_spec)
- {
- monitor_specs =
- g_list_prepend (NULL, meta_monitor_spec_clone (laptop_monitor_spec));
- }
-
- if (!monitor_specs)
- return NULL;
-
- monitor_specs = g_list_sort (monitor_specs,
- (GCompareFunc) meta_monitor_spec_compare);
-
- config_key = g_new0 (MetaMonitorsConfigKey, 1);
- *config_key = (MetaMonitorsConfigKey) {
- .monitor_specs = monitor_specs
- };
-
- return config_key;
-}
-
-MetaMonitorsConfig *
-meta_monitor_config_manager_get_stored (MetaMonitorConfigManager *config_manager)
-{
- MetaMonitorManager *monitor_manager = config_manager->monitor_manager;
- MetaMonitorsConfigKey *config_key;
- MetaMonitorsConfig *config;
- GError *error = NULL;
-
- config_key =
- meta_create_monitors_config_key_for_current_state (monitor_manager);
- if (!config_key)
- return NULL;
-
- config = meta_monitor_config_store_lookup (config_manager->config_store,
- config_key);
- meta_monitors_config_key_free (config_key);
-
- if (!config)
- return NULL;
-
- if (config->flags & META_MONITORS_CONFIG_FLAG_MIGRATED)
- {
- if (!meta_finish_monitors_config_migration (monitor_manager, config,
- &error))
- {
- g_warning ("Failed to finish monitors config migration: %s",
- error->message);
- g_error_free (error);
- meta_monitor_config_store_remove (config_manager->config_store, config);
- return NULL;
- }
- }
-
- return config;
-}
-
-typedef enum _MonitorMatchRule
-{
- MONITOR_MATCH_ALL = 0,
- MONITOR_MATCH_EXTERNAL = (1 << 0)
-} MonitorMatchRule;
-
-static MetaMonitor *
-find_monitor_with_highest_preferred_resolution (MetaMonitorManager *monitor_manager,
- MonitorMatchRule match_rule)
-{
- GList *monitors;
- GList *l;
- int largest_area = 0;
- MetaMonitor *largest_monitor = NULL;
-
- monitors = meta_monitor_manager_get_monitors (monitor_manager);
- for (l = monitors; l; l = l->next)
- {
- MetaMonitor *monitor = l->data;
- MetaMonitorMode *mode;
- int width, height;
- int area;
-
- if (match_rule & MONITOR_MATCH_EXTERNAL)
- {
- if (meta_monitor_is_laptop_panel (monitor))
- continue;
- }
-
- mode = meta_monitor_get_preferred_mode (monitor);
- meta_monitor_mode_get_resolution (mode, &width, &height);
- area = width * height;
-
- if (area > largest_area)
- {
- largest_area = area;
- largest_monitor = monitor;
- }
- }
-
- return largest_monitor;
-}
-
-/*
- * Try to find the primary monitor. The priority of classification is:
- *
- * 1. Find the primary monitor as reported by the underlying system,
- * 2. Find the laptop panel
- * 3. Find the external monitor with highest resolution
- *
- * If the laptop lid is closed, exclude the laptop panel from possible
- * alternatives, except if no other alternatives exist.
- */
-static MetaMonitor *
-find_primary_monitor (MetaMonitorManager *monitor_manager)
-{
- MetaMonitor *monitor;
-
- if (is_lid_closed (monitor_manager))
- {
- monitor = meta_monitor_manager_get_primary_monitor (monitor_manager);
- if (monitor && !meta_monitor_is_laptop_panel (monitor))
- return monitor;
-
- monitor =
- find_monitor_with_highest_preferred_resolution (monitor_manager,
- MONITOR_MATCH_EXTERNAL);
- if (monitor)
- return monitor;
-
- return find_monitor_with_highest_preferred_resolution (monitor_manager,
- MONITOR_MATCH_ALL);
- }
- else
- {
- monitor = meta_monitor_manager_get_primary_monitor (monitor_manager);
- if (monitor)
- return monitor;
-
- monitor = meta_monitor_manager_get_laptop_panel (monitor_manager);
- if (monitor)
- return monitor;
-
- return find_monitor_with_highest_preferred_resolution (monitor_manager,
- MONITOR_MATCH_ALL);
- }
-}
-
-static MetaMonitorConfig *
-create_monitor_config (MetaMonitor *monitor,
- MetaMonitorMode *mode)
-{
- MetaMonitorSpec *monitor_spec;
- MetaMonitorModeSpec *mode_spec;
- MetaMonitorConfig *monitor_config;
-
- monitor_spec = meta_monitor_get_spec (monitor);
- mode_spec = meta_monitor_mode_get_spec (mode);
-
- monitor_config = g_new0 (MetaMonitorConfig, 1);
- *monitor_config = (MetaMonitorConfig) {
- .monitor_spec = meta_monitor_spec_clone (monitor_spec),
- .mode_spec = g_memdup2 (mode_spec, sizeof (MetaMonitorModeSpec)),
- .enable_underscanning = meta_monitor_is_underscanning (monitor)
- };
-
- return monitor_config;
-}
-
-static MetaMonitorTransform
-get_monitor_transform (MetaMonitorManager *monitor_manager,
- MetaMonitor *monitor)
-{
- MetaOrientationManager *orientation_manager;
- MetaBackend *backend;
-
- if (!meta_monitor_is_laptop_panel (monitor))
- return META_MONITOR_TRANSFORM_NORMAL;
-
- backend = meta_monitor_manager_get_backend (monitor_manager);
- orientation_manager = meta_backend_get_orientation_manager (backend);
-
- switch (meta_orientation_manager_get_orientation (orientation_manager))
- {
- case META_ORIENTATION_BOTTOM_UP:
- return META_MONITOR_TRANSFORM_180;
- case META_ORIENTATION_LEFT_UP:
- return META_MONITOR_TRANSFORM_90;
- case META_ORIENTATION_RIGHT_UP:
- return META_MONITOR_TRANSFORM_270;
- case META_ORIENTATION_UNDEFINED:
- case META_ORIENTATION_NORMAL:
- default:
- return META_MONITOR_TRANSFORM_NORMAL;
- }
-}
-
-static MetaLogicalMonitorConfig *
-create_preferred_logical_monitor_config (MetaMonitorManager *monitor_manager,
- MetaMonitor *monitor,
- int x,
- int y,
- MetaLogicalMonitorConfig *primary_logical_monitor_config,
- MetaLogicalMonitorLayoutMode layout_mode)
-{
- MetaMonitorMode *mode;
- int width, height;
- float scale;
- MetaMonitorTransform transform;
- MetaMonitorConfig *monitor_config;
- MetaLogicalMonitorConfig *logical_monitor_config;
-
- mode = meta_monitor_get_preferred_mode (monitor);
- meta_monitor_mode_get_resolution (mode, &width, &height);
-
- if ((meta_monitor_manager_get_capabilities (monitor_manager) &
- META_MONITOR_MANAGER_CAPABILITY_GLOBAL_SCALE_REQUIRED) &&
- primary_logical_monitor_config)
- scale = primary_logical_monitor_config->scale;
- else
- scale = meta_monitor_manager_calculate_monitor_mode_scale (monitor_manager,
- monitor,
- mode);
-
- switch (layout_mode)
- {
- case META_LOGICAL_MONITOR_LAYOUT_MODE_LOGICAL:
- width = (int) roundf (width / scale);
- height = (int) roundf (height / scale);
- break;
- case META_LOGICAL_MONITOR_LAYOUT_MODE_PHYSICAL:
- break;
- }
-
- monitor_config = create_monitor_config (monitor, mode);
-
- transform = get_monitor_transform (monitor_manager, monitor);
- if (meta_monitor_transform_is_rotated (transform))
- {
- int temp = width;
- width = height;
- height = temp;
- }
-
- logical_monitor_config = g_new0 (MetaLogicalMonitorConfig, 1);
- *logical_monitor_config = (MetaLogicalMonitorConfig) {
- .layout = (MetaRectangle) {
- .x = x,
- .y = y,
- .width = width,
- .height = height
- },
- .transform = transform,
- .scale = scale,
- .monitor_configs = g_list_append (NULL, monitor_config)
- };
-
- return logical_monitor_config;
-}
-
-MetaMonitorsConfig *
-meta_monitor_config_manager_create_linear (MetaMonitorConfigManager *config_manager)
-{
- MetaMonitorManager *monitor_manager = config_manager->monitor_manager;
- GList *logical_monitor_configs;
- MetaMonitor *primary_monitor;
- MetaLogicalMonitorLayoutMode layout_mode;
- MetaLogicalMonitorConfig *primary_logical_monitor_config;
- int x;
- GList *monitors;
- GList *l;
- MetaMonitorsConfig *monitors_config;
-
- primary_monitor = find_primary_monitor (monitor_manager);
- if (!primary_monitor)
- return NULL;
-
- layout_mode = meta_monitor_manager_get_default_layout_mode (monitor_manager);
-
- primary_logical_monitor_config =
- create_preferred_logical_monitor_config (monitor_manager,
- primary_monitor,
- 0, 0,
- NULL,
- layout_mode);
- primary_logical_monitor_config->is_primary = TRUE;
- logical_monitor_configs = g_list_append (NULL,
- primary_logical_monitor_config);
-
- x = primary_logical_monitor_config->layout.width;
- monitors = meta_monitor_manager_get_monitors (monitor_manager);
- for (l = monitors; l; l = l->next)
- {
- MetaMonitor *monitor = l->data;
- MetaLogicalMonitorConfig *logical_monitor_config;
-
- if (monitor == primary_monitor)
- continue;
-
- if (meta_monitor_is_laptop_panel (monitor) &&
- is_lid_closed (monitor_manager))
- continue;
-
- logical_monitor_config =
- create_preferred_logical_monitor_config (monitor_manager,
- monitor,
- x, 0,
- primary_logical_monitor_config,
- layout_mode);
- logical_monitor_configs = g_list_append (logical_monitor_configs,
- logical_monitor_config);
-
- x += logical_monitor_config->layout.width;
- }
-
- monitors_config = meta_monitors_config_new (monitor_manager,
- logical_monitor_configs,
- layout_mode,
- META_MONITORS_CONFIG_FLAG_NONE);
-
- if (monitors_config)
- meta_monitors_config_set_switch_config (monitors_config, META_MONITOR_SWITCH_CONFIG_ALL_LINEAR);
-
- return monitors_config;
-}
-
-MetaMonitorsConfig *
-meta_monitor_config_manager_create_fallback (MetaMonitorConfigManager *config_manager)
-{
- MetaMonitorManager *monitor_manager = config_manager->monitor_manager;
- MetaMonitor *primary_monitor;
- GList *logical_monitor_configs;
- MetaLogicalMonitorLayoutMode layout_mode;
- MetaLogicalMonitorConfig *primary_logical_monitor_config;
-
- primary_monitor = find_primary_monitor (monitor_manager);
- if (!primary_monitor)
- return NULL;
-
- layout_mode = meta_monitor_manager_get_default_layout_mode (monitor_manager);
-
- primary_logical_monitor_config =
- create_preferred_logical_monitor_config (monitor_manager,
- primary_monitor,
- 0, 0,
- NULL,
- layout_mode);
- primary_logical_monitor_config->is_primary = TRUE;
- logical_monitor_configs = g_list_append (NULL,
- primary_logical_monitor_config);
-
- return meta_monitors_config_new (monitor_manager,
- logical_monitor_configs,
- layout_mode,
- META_MONITORS_CONFIG_FLAG_NONE);
-}
-
-MetaMonitorsConfig *
-meta_monitor_config_manager_create_suggested (MetaMonitorConfigManager *config_manager)
-{
- MetaMonitorManager *monitor_manager = config_manager->monitor_manager;
- MetaLogicalMonitorConfig *primary_logical_monitor_config = NULL;
- MetaMonitor *primary_monitor;
- MetaLogicalMonitorLayoutMode layout_mode;
- GList *logical_monitor_configs;
- GList *region;
- int x, y;
- GList *monitors;
- GList *l;
-
- primary_monitor = find_primary_monitor (monitor_manager);
- if (!primary_monitor)
- return NULL;
-
- if (!meta_monitor_get_suggested_position (primary_monitor, &x, &y))
- return NULL;
-
- layout_mode = meta_monitor_manager_get_default_layout_mode (monitor_manager);
-
- primary_logical_monitor_config =
- create_preferred_logical_monitor_config (monitor_manager,
- primary_monitor,
- x, y,
- NULL,
- layout_mode);
- primary_logical_monitor_config->is_primary = TRUE;
- logical_monitor_configs = g_list_append (NULL,
- primary_logical_monitor_config);
- region = g_list_prepend (NULL, &primary_logical_monitor_config->layout);
-
- monitors = meta_monitor_manager_get_monitors (monitor_manager);
- for (l = monitors; l; l = l->next)
- {
- MetaMonitor *monitor = l->data;
- MetaLogicalMonitorConfig *logical_monitor_config;
-
- if (monitor == primary_monitor)
- continue;
-
- if (!meta_monitor_get_suggested_position (monitor, &x, &y))
- continue;
-
- logical_monitor_config =
- create_preferred_logical_monitor_config (monitor_manager,
- monitor,
- x, y,
- primary_logical_monitor_config,
- layout_mode);
- logical_monitor_configs = g_list_append (logical_monitor_configs,
- logical_monitor_config);
-
- if (meta_rectangle_overlaps_with_region (region,
- &logical_monitor_config->layout))
- {
- g_warning ("Suggested monitor config has overlapping region, rejecting");
- g_list_free (region);
- g_list_free_full (logical_monitor_configs,
- (GDestroyNotify) meta_logical_monitor_config_free);
- return NULL;
- }
-
- region = g_list_prepend (region, &logical_monitor_config->layout);
- }
-
- g_list_free (region);
-
- if (!logical_monitor_configs)
- return NULL;
-
- return meta_monitors_config_new (monitor_manager,
- logical_monitor_configs,
- layout_mode,
- META_MONITORS_CONFIG_FLAG_NONE);
-}
-
-static GList *
-clone_monitor_config_list (GList *monitor_configs_in)
-{
- MetaMonitorConfig *monitor_config_in;
- MetaMonitorConfig *monitor_config_out;
- GList *monitor_configs_out = NULL;
- GList *l;
-
- for (l = monitor_configs_in; l; l = l->next)
- {
- monitor_config_in = l->data;
- monitor_config_out = g_new0 (MetaMonitorConfig, 1);
- *monitor_config_out = (MetaMonitorConfig) {
- .monitor_spec = meta_monitor_spec_clone (monitor_config_in->monitor_spec),
- .mode_spec = g_memdup2 (monitor_config_in->mode_spec,
- sizeof (MetaMonitorModeSpec)),
- .enable_underscanning = monitor_config_in->enable_underscanning
- };
- monitor_configs_out =
- g_list_append (monitor_configs_out, monitor_config_out);
- }
-
- return monitor_configs_out;
-}
-
-static GList *
-clone_logical_monitor_config_list (GList *logical_monitor_configs_in)
-{
- MetaLogicalMonitorConfig *logical_monitor_config_in;
- MetaLogicalMonitorConfig *logical_monitor_config_out;
- GList *logical_monitor_configs_out = NULL;
- GList *l;
-
- for (l = logical_monitor_configs_in; l; l = l->next)
- {
- logical_monitor_config_in = l->data;
-
- logical_monitor_config_out =
- g_memdup2 (logical_monitor_config_in,
- sizeof (MetaLogicalMonitorConfig));
- logical_monitor_config_out->monitor_configs =
- clone_monitor_config_list (logical_monitor_config_in->monitor_configs);
-
- logical_monitor_configs_out =
- g_list_append (logical_monitor_configs_out, logical_monitor_config_out);
- }
-
- return logical_monitor_configs_out;
-}
-
-static MetaLogicalMonitorConfig *
-find_logical_config_for_builtin_display_rotation (MetaMonitorConfigManager *config_manager,
- GList *logical_monitor_configs)
-{
- MetaLogicalMonitorConfig *logical_monitor_config;
- MetaMonitorConfig *monitor_config;
- MetaMonitor *panel;
- GList *l;
-
- panel = meta_monitor_manager_get_laptop_panel (config_manager->monitor_manager);
- if (panel && meta_monitor_is_active (panel))
- {
- for (l = logical_monitor_configs; l; l = l->next)
- {
- logical_monitor_config = l->data;
- /*
- * We only want to return the config for the panel if it is
- * configured on its own, so we skip configs which contain clones.
- */
- if (g_list_length (logical_monitor_config->monitor_configs) != 1)
- continue;
-
- monitor_config = logical_monitor_config->monitor_configs->data;
- if (meta_monitor_spec_equals (meta_monitor_get_spec (panel),
- monitor_config->monitor_spec))
- return logical_monitor_config;
- }
- }
-
- return NULL;
-}
-
-static MetaMonitorsConfig *
-create_for_builtin_display_rotation (MetaMonitorConfigManager *config_manager,
- gboolean rotate,
- MetaMonitorTransform transform)
-{
- MetaMonitorManager *monitor_manager = config_manager->monitor_manager;
- MetaLogicalMonitorConfig *logical_monitor_config;
- MetaLogicalMonitorConfig *current_logical_monitor_config;
- GList *logical_monitor_configs, *current_configs;
- MetaLogicalMonitorLayoutMode layout_mode;
-
- if (!config_manager->current_config)
- return NULL;
-
- current_configs = config_manager->current_config->logical_monitor_configs;
- current_logical_monitor_config =
- find_logical_config_for_builtin_display_rotation (config_manager,
- current_configs);
- if (!current_logical_monitor_config)
- return NULL;
-
- if (rotate)
- transform = (current_logical_monitor_config->transform + 1) % META_MONITOR_TRANSFORM_FLIPPED;
- else
- {
- /*
- * The transform coming from the accelerometer should be applied to
- * the crtc as is, without taking panel-orientation into account, this
- * is done so that non panel-orientation aware desktop environments do the
- * right thing. Mutter corrects for panel-orientation when applying the
- * transform from a logical-monitor-config, so we must convert here.
- */
- MetaMonitor *panel =
- meta_monitor_manager_get_laptop_panel (config_manager->monitor_manager);
-
- transform = meta_monitor_crtc_to_logical_transform (panel, transform);
- }
-
- if (current_logical_monitor_config->transform == transform)
- return NULL;
-
- logical_monitor_configs =
- clone_logical_monitor_config_list (config_manager->current_config->logical_monitor_configs);
- logical_monitor_config =
- find_logical_config_for_builtin_display_rotation (config_manager, logical_monitor_configs);
- logical_monitor_config->transform = transform;
-
- if (meta_monitor_transform_is_rotated (current_logical_monitor_config->transform) !=
- meta_monitor_transform_is_rotated (logical_monitor_config->transform))
- {
- int temp = logical_monitor_config->layout.width;
- logical_monitor_config->layout.width = logical_monitor_config->layout.height;
- logical_monitor_config->layout.height = temp;
- }
-
- layout_mode = config_manager->current_config->layout_mode;
- return meta_monitors_config_new (monitor_manager,
- logical_monitor_configs,
- layout_mode,
- META_MONITORS_CONFIG_FLAG_NONE);
-}
-
-MetaMonitorsConfig *
-meta_monitor_config_manager_create_for_orientation (MetaMonitorConfigManager *config_manager,
- MetaMonitorTransform transform)
-{
- return create_for_builtin_display_rotation (config_manager, FALSE, transform);
-}
-
-MetaMonitorsConfig *
-meta_monitor_config_manager_create_for_rotate_monitor (MetaMonitorConfigManager *config_manager)
-{
- return create_for_builtin_display_rotation (config_manager, TRUE, META_MONITOR_TRANSFORM_NORMAL);
-}
-
-static MetaMonitorsConfig *
-create_for_switch_config_all_mirror (MetaMonitorConfigManager *config_manager)
-{
- MetaMonitorManager *monitor_manager = config_manager->monitor_manager;
- MetaLogicalMonitorLayoutMode layout_mode;
- MetaLogicalMonitorConfig *logical_monitor_config = NULL;
- GList *logical_monitor_configs;
- GList *monitor_configs = NULL;
- gint common_mode_w = 0, common_mode_h = 0;
- float best_scale = 1.0;
- MetaMonitor *monitor;
- GList *modes;
- GList *monitors;
- GList *l;
- MetaMonitorsConfig *monitors_config;
-
- monitors = meta_monitor_manager_get_monitors (monitor_manager);
- monitor = monitors->data;
- modes = meta_monitor_get_modes (monitor);
- for (l = modes; l; l = l->next)
- {
- MetaMonitorMode *mode = l->data;
- gboolean common_mode_size = TRUE;
- gint mode_w, mode_h;
- GList *ll;
-
- meta_monitor_mode_get_resolution (mode, &mode_w, &mode_h);
-
- for (ll = monitors->next; ll; ll = ll->next)
- {
- MetaMonitor *monitor_b = ll->data;
- gboolean have_same_mode_size = FALSE;
- GList *mm;
-
- for (mm = meta_monitor_get_modes (monitor_b); mm; mm = mm->next)
- {
- MetaMonitorMode *mode_b = mm->data;
- gint mode_b_w, mode_b_h;
-
- meta_monitor_mode_get_resolution (mode_b, &mode_b_w, &mode_b_h);
-
- if (mode_w == mode_b_w &&
- mode_h == mode_b_h)
- {
- have_same_mode_size = TRUE;
- break;
- }
- }
-
- if (!have_same_mode_size)
- {
- common_mode_size = FALSE;
- break;
- }
- }
-
- if (common_mode_size &&
- common_mode_w * common_mode_h < mode_w * mode_h)
- {
- common_mode_w = mode_w;
- common_mode_h = mode_h;
- }
- }
-
- if (common_mode_w == 0 || common_mode_h == 0)
- return NULL;
-
- for (l = monitors; l; l = l->next)
- {
- MetaMonitor *monitor = l->data;
- MetaMonitorMode *mode = NULL;
- GList *ll;
- float scale;
-
- for (ll = meta_monitor_get_modes (monitor); ll; ll = ll->next)
- {
- gint mode_w, mode_h;
-
- mode = ll->data;
- meta_monitor_mode_get_resolution (mode, &mode_w, &mode_h);
-
- if (mode_w == common_mode_w && mode_h == common_mode_h)
- break;
- }
-
- if (!mode)
- continue;
-
- scale = meta_monitor_manager_calculate_monitor_mode_scale (monitor_manager, monitor, mode);
- best_scale = MAX (best_scale, scale);
- monitor_configs = g_list_prepend (monitor_configs, create_monitor_config (monitor, mode));
- }
-
- logical_monitor_config = g_new0 (MetaLogicalMonitorConfig, 1);
- *logical_monitor_config = (MetaLogicalMonitorConfig) {
- .layout = (MetaRectangle) {
- .x = 0,
- .y = 0,
- .width = common_mode_w,
- .height = common_mode_h
- },
- .scale = best_scale,
- .monitor_configs = monitor_configs
- };
-
- logical_monitor_configs = g_list_append (NULL, logical_monitor_config);
- layout_mode = meta_monitor_manager_get_default_layout_mode (monitor_manager);
- monitors_config = meta_monitors_config_new (monitor_manager,
- logical_monitor_configs,
- layout_mode,
- META_MONITORS_CONFIG_FLAG_NONE);
-
- if (monitors_config)
- meta_monitors_config_set_switch_config (monitors_config, META_MONITOR_SWITCH_CONFIG_ALL_MIRROR);
-
- return monitors_config;
-}
-
-static MetaMonitorsConfig *
-create_for_switch_config_external (MetaMonitorConfigManager *config_manager)
-{
- MetaMonitorManager *monitor_manager = config_manager->monitor_manager;
- GList *logical_monitor_configs = NULL;
- int x = 0;
- MetaLogicalMonitorLayoutMode layout_mode;
- GList *monitors;
- GList *l;
- MetaMonitorsConfig *monitors_config;
-
- layout_mode = meta_monitor_manager_get_default_layout_mode (monitor_manager);
-
- monitors = meta_monitor_manager_get_monitors (monitor_manager);
- for (l = monitors; l; l = l->next)
- {
- MetaMonitor *monitor = l->data;
- MetaLogicalMonitorConfig *logical_monitor_config;
-
- if (meta_monitor_is_laptop_panel (monitor))
- continue;
-
- logical_monitor_config =
- create_preferred_logical_monitor_config (monitor_manager,
- monitor,
- x, 0,
- NULL,
- layout_mode);
- logical_monitor_configs = g_list_append (logical_monitor_configs,
- logical_monitor_config);
-
- if (x == 0)
- logical_monitor_config->is_primary = TRUE;
-
- x += logical_monitor_config->layout.width;
- }
-
- if (!logical_monitor_configs)
- return NULL;
-
- monitors_config = meta_monitors_config_new (monitor_manager,
- logical_monitor_configs,
- layout_mode,
- META_MONITORS_CONFIG_FLAG_NONE);
-
- if (monitors_config)
- meta_monitors_config_set_switch_config (monitors_config, META_MONITOR_SWITCH_CONFIG_EXTERNAL);
-
- return monitors_config;
-}
-
-static MetaMonitorsConfig *
-create_for_switch_config_builtin (MetaMonitorConfigManager *config_manager)
-{
- MetaMonitorManager *monitor_manager = config_manager->monitor_manager;
- MetaLogicalMonitorLayoutMode layout_mode;
- GList *logical_monitor_configs;
- MetaLogicalMonitorConfig *primary_logical_monitor_config;
- MetaMonitor *monitor;
- MetaMonitorsConfig *monitors_config;
-
- monitor = meta_monitor_manager_get_laptop_panel (monitor_manager);
- if (!monitor)
- return NULL;
-
- layout_mode = meta_monitor_manager_get_default_layout_mode (monitor_manager);
-
- primary_logical_monitor_config =
- create_preferred_logical_monitor_config (monitor_manager,
- monitor,
- 0, 0,
- NULL,
- layout_mode);
- primary_logical_monitor_config->is_primary = TRUE;
- logical_monitor_configs = g_list_append (NULL,
- primary_logical_monitor_config);
-
- monitors_config = meta_monitors_config_new (monitor_manager,
- logical_monitor_configs,
- layout_mode,
- META_MONITORS_CONFIG_FLAG_NONE);
-
- if (monitors_config)
- meta_monitors_config_set_switch_config (monitors_config, META_MONITOR_SWITCH_CONFIG_BUILTIN);
-
- return monitors_config;
-}
-
-MetaMonitorsConfig *
-meta_monitor_config_manager_create_for_switch_config (MetaMonitorConfigManager *config_manager,
- MetaMonitorSwitchConfigType config_type)
-{
- MetaMonitorManager *monitor_manager = config_manager->monitor_manager;
- MetaMonitorsConfig *config;
-
- if (!meta_monitor_manager_can_switch_config (monitor_manager))
- return NULL;
-
- switch (config_type)
- {
- case META_MONITOR_SWITCH_CONFIG_ALL_MIRROR:
- config = create_for_switch_config_all_mirror (config_manager);
- break;
- case META_MONITOR_SWITCH_CONFIG_ALL_LINEAR:
- config = meta_monitor_config_manager_create_linear (config_manager);
- break;
- case META_MONITOR_SWITCH_CONFIG_EXTERNAL:
- config = create_for_switch_config_external (config_manager);
- break;
- case META_MONITOR_SWITCH_CONFIG_BUILTIN:
- config = create_for_switch_config_builtin (config_manager);
- break;
- case META_MONITOR_SWITCH_CONFIG_UNKNOWN:
- default:
- g_warn_if_reached ();
- return NULL;
- }
-
- return config;
-}
-
-void
-meta_monitor_config_manager_set_current (MetaMonitorConfigManager *config_manager,
- MetaMonitorsConfig *config)
-{
- if (config_manager->current_config)
- {
- g_queue_push_head (&config_manager->config_history,
- g_object_ref (config_manager->current_config));
- if (g_queue_get_length (&config_manager->config_history) >
- CONFIG_HISTORY_MAX_SIZE)
- g_object_unref (g_queue_pop_tail (&config_manager->config_history));
- }
-
- g_set_object (&config_manager->current_config, config);
-}
-
-void
-meta_monitor_config_manager_save_current (MetaMonitorConfigManager *config_manager)
-{
- g_return_if_fail (config_manager->current_config);
-
- meta_monitor_config_store_add (config_manager->config_store,
- config_manager->current_config);
-}
-
-MetaMonitorsConfig *
-meta_monitor_config_manager_get_current (MetaMonitorConfigManager *config_manager)
-{
- return config_manager->current_config;
-}
-
-MetaMonitorsConfig *
-meta_monitor_config_manager_pop_previous (MetaMonitorConfigManager *config_manager)
-{
- return g_queue_pop_head (&config_manager->config_history);
-}
-
-MetaMonitorsConfig *
-meta_monitor_config_manager_get_previous (MetaMonitorConfigManager *config_manager)
-{
- return g_queue_peek_head (&config_manager->config_history);
-}
-
-void
-meta_monitor_config_manager_clear_history (MetaMonitorConfigManager *config_manager)
-{
- g_queue_foreach (&config_manager->config_history, (GFunc) g_object_unref, NULL);
- g_queue_clear (&config_manager->config_history);
-}
-
-static void
-meta_monitor_config_manager_dispose (GObject *object)
-{
- MetaMonitorConfigManager *config_manager =
- META_MONITOR_CONFIG_MANAGER (object);
-
- g_clear_object (&config_manager->current_config);
- meta_monitor_config_manager_clear_history (config_manager);
-
- G_OBJECT_CLASS (meta_monitor_config_manager_parent_class)->dispose (object);
-}
-
-static void
-meta_monitor_config_manager_init (MetaMonitorConfigManager *config_manager)
-{
- g_queue_init (&config_manager->config_history);
-}
-
-static void
-meta_monitor_config_manager_class_init (MetaMonitorConfigManagerClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- object_class->dispose = meta_monitor_config_manager_dispose;
-}
-
-void
-meta_monitor_config_free (MetaMonitorConfig *monitor_config)
-{
- if (monitor_config->monitor_spec)
- meta_monitor_spec_free (monitor_config->monitor_spec);
- g_free (monitor_config->mode_spec);
- g_free (monitor_config);
-}
-
-void
-meta_logical_monitor_config_free (MetaLogicalMonitorConfig *logical_monitor_config)
-{
- g_list_free_full (logical_monitor_config->monitor_configs,
- (GDestroyNotify) meta_monitor_config_free);
- g_free (logical_monitor_config);
-}
-
-static MetaMonitorsConfigKey *
-meta_monitors_config_key_new (GList *logical_monitor_configs,
- GList *disabled_monitor_specs)
-{
- MetaMonitorsConfigKey *config_key;
- GList *monitor_specs;
- GList *l;
-
- monitor_specs = NULL;
- for (l = logical_monitor_configs; l; l = l->next)
- {
- MetaLogicalMonitorConfig *logical_monitor_config = l->data;
- GList *k;
-
- for (k = logical_monitor_config->monitor_configs; k; k = k->next)
- {
- MetaMonitorConfig *monitor_config = k->data;
- MetaMonitorSpec *monitor_spec;
-
- monitor_spec = meta_monitor_spec_clone (monitor_config->monitor_spec);
- monitor_specs = g_list_prepend (monitor_specs, monitor_spec);
- }
- }
-
- for (l = disabled_monitor_specs; l; l = l->next)
- {
- MetaMonitorSpec *monitor_spec = l->data;
-
- monitor_spec = meta_monitor_spec_clone (monitor_spec);
- monitor_specs = g_list_prepend (monitor_specs, monitor_spec);
- }
-
- monitor_specs = g_list_sort (monitor_specs,
- (GCompareFunc) meta_monitor_spec_compare);
-
- config_key = g_new0 (MetaMonitorsConfigKey, 1);
- *config_key = (MetaMonitorsConfigKey) {
- .monitor_specs = monitor_specs
- };
-
- return config_key;
-}
-
-void
-meta_monitors_config_key_free (MetaMonitorsConfigKey *config_key)
-{
- g_list_free_full (config_key->monitor_specs,
- (GDestroyNotify) meta_monitor_spec_free);
- g_free (config_key);
-}
-
-unsigned int
-meta_monitors_config_key_hash (gconstpointer data)
-{
- const MetaMonitorsConfigKey *config_key = data;
- GList *l;
- unsigned long hash;
-
- hash = 0;
- for (l = config_key->monitor_specs; l; l = l->next)
- {
- MetaMonitorSpec *monitor_spec = l->data;
-
- hash ^= (g_str_hash (monitor_spec->connector) ^
- g_str_hash (monitor_spec->vendor) ^
- g_str_hash (monitor_spec->product) ^
- g_str_hash (monitor_spec->serial));
- }
-
- return hash;
-}
-
-gboolean
-meta_monitors_config_key_equal (gconstpointer data_a,
- gconstpointer data_b)
-{
- const MetaMonitorsConfigKey *config_key_a = data_a;
- const MetaMonitorsConfigKey *config_key_b = data_b;
- GList *l_a, *l_b;
-
- for (l_a = config_key_a->monitor_specs, l_b = config_key_b->monitor_specs;
- l_a && l_b;
- l_a = l_a->next, l_b = l_b->next)
- {
- MetaMonitorSpec *monitor_spec_a = l_a->data;
- MetaMonitorSpec *monitor_spec_b = l_b->data;
-
- if (!meta_monitor_spec_equals (monitor_spec_a, monitor_spec_b))
- return FALSE;
- }
-
- if (l_a || l_b)
- return FALSE;
-
- return TRUE;
-}
-
-MetaMonitorSwitchConfigType
-meta_monitors_config_get_switch_config (MetaMonitorsConfig *config)
-{
- return config->switch_config;
-}
-
-void
-meta_monitors_config_set_switch_config (MetaMonitorsConfig *config,
- MetaMonitorSwitchConfigType switch_config)
-{
- config->switch_config = switch_config;
-}
-
-MetaMonitorsConfig *
-meta_monitors_config_new_full (GList *logical_monitor_configs,
- GList *disabled_monitor_specs,
- MetaLogicalMonitorLayoutMode layout_mode,
- MetaMonitorsConfigFlag flags)
-{
- MetaMonitorsConfig *config;
-
- config = g_object_new (META_TYPE_MONITORS_CONFIG, NULL);
- config->logical_monitor_configs = logical_monitor_configs;
- config->disabled_monitor_specs = disabled_monitor_specs;
- config->key = meta_monitors_config_key_new (logical_monitor_configs,
- disabled_monitor_specs);
- config->layout_mode = layout_mode;
- config->flags = flags;
- config->switch_config = META_MONITOR_SWITCH_CONFIG_UNKNOWN;
-
- return config;
-}
-
-MetaMonitorsConfig *
-meta_monitors_config_new (MetaMonitorManager *monitor_manager,
- GList *logical_monitor_configs,
- MetaLogicalMonitorLayoutMode layout_mode,
- MetaMonitorsConfigFlag flags)
-{
- GList *disabled_monitor_specs = NULL;
- GList *monitors;
- GList *l;
-
- monitors = meta_monitor_manager_get_monitors (monitor_manager);
- for (l = monitors; l; l = l->next)
- {
- MetaMonitor *monitor = l->data;
- MetaMonitorSpec *monitor_spec;
-
- if (is_lid_closed (monitor_manager) &&
- meta_monitor_is_laptop_panel (monitor))
- continue;
-
- monitor_spec = meta_monitor_get_spec (monitor);
- if (meta_logical_monitor_configs_have_monitor (logical_monitor_configs,
- monitor_spec))
- continue;
-
- disabled_monitor_specs =
- g_list_prepend (disabled_monitor_specs,
- meta_monitor_spec_clone (monitor_spec));
- }
-
- return meta_monitors_config_new_full (logical_monitor_configs,
- disabled_monitor_specs,
- layout_mode,
- flags);
-}
-
-static void
-meta_monitors_config_finalize (GObject *object)
-{
- MetaMonitorsConfig *config = META_MONITORS_CONFIG (object);
-
- meta_monitors_config_key_free (config->key);
- g_list_free_full (config->logical_monitor_configs,
- (GDestroyNotify) meta_logical_monitor_config_free);
- g_list_free_full (config->disabled_monitor_specs,
- (GDestroyNotify) meta_monitor_spec_free);
-
- G_OBJECT_CLASS (meta_monitors_config_parent_class)->finalize (object);
-}
-
-static void
-meta_monitors_config_init (MetaMonitorsConfig *config)
-{
-}
-
-static void
-meta_monitors_config_class_init (MetaMonitorsConfigClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- object_class->finalize = meta_monitors_config_finalize;
-}
-
-static void
-meta_crtc_assignment_free (MetaCrtcAssignment *assignment)
-{
- g_ptr_array_free (assignment->outputs, TRUE);
- g_free (assignment);
-}
-
-static void
-meta_output_assignment_free (MetaOutputAssignment *assignment)
-{
- g_free (assignment);
-}
-
-gboolean
-meta_verify_monitor_mode_spec (MetaMonitorModeSpec *monitor_mode_spec,
- GError **error)
-{
- if (monitor_mode_spec->width > 0 &&
- monitor_mode_spec->height > 0 &&
- monitor_mode_spec->refresh_rate > 0.0f)
- {
- return TRUE;
- }
- else
- {
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- "Monitor mode invalid");
- return FALSE;
- }
-}
-
-gboolean
-meta_verify_monitor_spec (MetaMonitorSpec *monitor_spec,
- GError **error)
-{
- if (monitor_spec->connector &&
- monitor_spec->vendor &&
- monitor_spec->product &&
- monitor_spec->serial)
- {
- return TRUE;
- }
- else
- {
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- "Monitor spec incomplete");
- return FALSE;
- }
-}
-
-gboolean
-meta_verify_monitor_config (MetaMonitorConfig *monitor_config,
- GError **error)
-{
- if (monitor_config->monitor_spec && monitor_config->mode_spec)
- {
- return TRUE;
- }
- else
- {
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- "Monitor config incomplete");
- return FALSE;
- }
-}
-
-gboolean
-meta_verify_logical_monitor_config (MetaLogicalMonitorConfig *logical_monitor_config,
- MetaLogicalMonitorLayoutMode layout_mode,
- MetaMonitorManager *monitor_manager,
- GError **error)
-{
- GList *l;
- int expected_mode_width = 0;
- int expected_mode_height = 0;
-
- if (logical_monitor_config->layout.x < 0 ||
- logical_monitor_config->layout.y < 0)
- {
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- "Invalid logical monitor position (%d, %d)",
- logical_monitor_config->layout.x,
- logical_monitor_config->layout.y);
- return FALSE;
- }
-
- if (!logical_monitor_config->monitor_configs)
- {
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- "Logical monitor is empty");
- return FALSE;
- }
-
- if (meta_monitor_transform_is_rotated (logical_monitor_config->transform))
- {
- expected_mode_width = logical_monitor_config->layout.height;
- expected_mode_height = logical_monitor_config->layout.width;
- }
- else
- {
- expected_mode_width = logical_monitor_config->layout.width;
- expected_mode_height = logical_monitor_config->layout.height;
- }
-
- switch (layout_mode)
- {
- case META_LOGICAL_MONITOR_LAYOUT_MODE_LOGICAL:
- expected_mode_width = roundf (expected_mode_width *
- logical_monitor_config->scale);
- expected_mode_height = roundf (expected_mode_height *
- logical_monitor_config->scale);
- break;
- case META_LOGICAL_MONITOR_LAYOUT_MODE_PHYSICAL:
- break;
- }
-
- for (l = logical_monitor_config->monitor_configs; l; l = l->next)
- {
- MetaMonitorConfig *monitor_config = l->data;
-
- if (monitor_config->mode_spec->width != expected_mode_width ||
- monitor_config->mode_spec->height != expected_mode_height)
- {
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- "Monitor modes in logical monitor conflict");
- return FALSE;
- }
- }
-
- return TRUE;
-}
-
-static gboolean
-has_adjacent_neighbour (MetaMonitorsConfig *config,
- MetaLogicalMonitorConfig *logical_monitor_config)
-{
- GList *l;
-
- if (!config->logical_monitor_configs->next)
- {
- g_assert (config->logical_monitor_configs->data ==
- logical_monitor_config);
- return TRUE;
- }
-
- for (l = config->logical_monitor_configs; l; l = l->next)
- {
- MetaLogicalMonitorConfig *other_logical_monitor_config = l->data;
-
- if (logical_monitor_config == other_logical_monitor_config)
- continue;
-
- if (meta_rectangle_is_adjacent_to (&logical_monitor_config->layout,
- &other_logical_monitor_config->layout))
- return TRUE;
- }
-
- return FALSE;
-}
-
-gboolean
-meta_logical_monitor_configs_have_monitor (GList *logical_monitor_configs,
- MetaMonitorSpec *monitor_spec)
-{
- GList *l;
-
- for (l = logical_monitor_configs; l; l = l->next)
- {
- MetaLogicalMonitorConfig *logical_monitor_config = l->data;
- GList *k;
-
- for (k = logical_monitor_config->monitor_configs; k; k = k->next)
- {
- MetaMonitorConfig *monitor_config = k->data;
-
- if (meta_monitor_spec_equals (monitor_spec,
- monitor_config->monitor_spec))
- return TRUE;
- }
- }
-
- return FALSE;
-}
-
-static gboolean
-meta_monitors_config_is_monitor_enabled (MetaMonitorsConfig *config,
- MetaMonitorSpec *monitor_spec)
-{
- return meta_logical_monitor_configs_have_monitor (config->logical_monitor_configs,
- monitor_spec);
-}
-
-gboolean
-meta_verify_monitors_config (MetaMonitorsConfig *config,
- MetaMonitorManager *monitor_manager,
- GError **error)
-{
- int min_x, min_y;
- gboolean has_primary;
- GList *region;
- GList *l;
- gboolean global_scale_required;
-
- if (!config->logical_monitor_configs)
- {
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- "Monitors config incomplete");
- return FALSE;
- }
-
- global_scale_required =
- !!(meta_monitor_manager_get_capabilities (monitor_manager) &
- META_MONITOR_MANAGER_CAPABILITY_GLOBAL_SCALE_REQUIRED);
-
- min_x = INT_MAX;
- min_y = INT_MAX;
- region = NULL;
- has_primary = FALSE;
- for (l = config->logical_monitor_configs; l; l = l->next)
- {
- MetaLogicalMonitorConfig *logical_monitor_config = l->data;
-
- if (global_scale_required)
- {
- MetaLogicalMonitorConfig *prev_logical_monitor_config =
- l->prev ? l->prev->data : NULL;
-
- if (prev_logical_monitor_config &&
- (prev_logical_monitor_config->scale !=
- logical_monitor_config->scale))
- {
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- "Logical monitor scales must be identical");
- return FALSE;
- }
- }
-
- if (meta_rectangle_overlaps_with_region (region,
- &logical_monitor_config->layout))
- {
- g_list_free (region);
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- "Logical monitors overlap");
- return FALSE;
- }
-
- if (has_primary && logical_monitor_config->is_primary)
- {
- g_list_free (region);
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- "Config contains multiple primary logical monitors");
- return FALSE;
- }
- else if (logical_monitor_config->is_primary)
- {
- has_primary = TRUE;
- }
-
- if (!has_adjacent_neighbour (config, logical_monitor_config))
- {
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- "Logical monitors not adjacent");
- return FALSE;
- }
-
- min_x = MIN (logical_monitor_config->layout.x, min_x);
- min_y = MIN (logical_monitor_config->layout.y, min_y);
-
- region = g_list_prepend (region, &logical_monitor_config->layout);
- }
-
- g_list_free (region);
-
- for (l = config->disabled_monitor_specs; l; l = l->next)
- {
- MetaMonitorSpec *monitor_spec = l->data;
-
- if (meta_monitors_config_is_monitor_enabled (config, monitor_spec))
- {
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- "Assigned monitor explicitly disabled");
- return FALSE;
- }
- }
-
- if (min_x != 0 || min_y != 0)
- {
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- "Logical monitors positions are offset");
- return FALSE;
- }
-
- if (!has_primary)
- {
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- "Config is missing primary logical");
- return FALSE;
- }
-
- return TRUE;
-}
diff --git a/src/backends/meta-monitor-config-manager.h b/src/backends/meta-monitor-config-manager.h
deleted file mode 100644
index 86756a7e3..000000000
--- a/src/backends/meta-monitor-config-manager.h
+++ /dev/null
@@ -1,201 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2016 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-
-#ifndef META_MONITOR_CONFIG_MANAGER_H
-#define META_MONITOR_CONFIG_MANAGER_H
-
-#include "backends/meta-monitor.h"
-#include "backends/meta-monitor-manager-private.h"
-
-#define META_TYPE_MONITOR_CONFIG_MANAGER (meta_monitor_config_manager_get_type ())
-G_DECLARE_FINAL_TYPE (MetaMonitorConfigManager, meta_monitor_config_manager,
- META, MONITOR_CONFIG_MANAGER, GObject)
-
-typedef struct _MetaMonitorConfig
-{
- MetaMonitorSpec *monitor_spec;
- MetaMonitorModeSpec *mode_spec;
- gboolean enable_underscanning;
-} MetaMonitorConfig;
-
-typedef struct _MetaLogicalMonitorConfig
-{
- MetaRectangle layout;
- GList *monitor_configs;
- MetaMonitorTransform transform;
- float scale;
- gboolean is_primary;
- gboolean is_presentation;
-} MetaLogicalMonitorConfig;
-
-typedef struct _MetaMonitorsConfigKey
-{
- GList *monitor_specs;
-} MetaMonitorsConfigKey;
-
-typedef enum _MetaMonitorsConfigFlag
-{
- META_MONITORS_CONFIG_FLAG_NONE = 0,
- META_MONITORS_CONFIG_FLAG_MIGRATED = (1 << 0),
- META_MONITORS_CONFIG_FLAG_SYSTEM_CONFIG = (1 << 1),
-} MetaMonitorsConfigFlag;
-
-struct _MetaMonitorsConfig
-{
- GObject parent;
-
- MetaMonitorsConfigKey *key;
- GList *logical_monitor_configs;
-
- GList *disabled_monitor_specs;
-
- MetaMonitorsConfigFlag flags;
-
- MetaLogicalMonitorLayoutMode layout_mode;
-
- MetaMonitorSwitchConfigType switch_config;
-};
-
-#define META_TYPE_MONITORS_CONFIG (meta_monitors_config_get_type ())
-G_DECLARE_FINAL_TYPE (MetaMonitorsConfig, meta_monitors_config,
- META, MONITORS_CONFIG, GObject)
-
-META_EXPORT_TEST
-MetaMonitorConfigManager * meta_monitor_config_manager_new (MetaMonitorManager *monitor_manager);
-
-META_EXPORT_TEST
-MetaMonitorConfigStore * meta_monitor_config_manager_get_store (MetaMonitorConfigManager *config_manager);
-
-META_EXPORT_TEST
-gboolean meta_monitor_config_manager_assign (MetaMonitorManager *manager,
- MetaMonitorsConfig *config,
- GPtrArray **crtc_assignments,
- GPtrArray **output_assignments,
- GError **error);
-
-META_EXPORT_TEST
-MetaMonitorsConfig * meta_monitor_config_manager_get_stored (MetaMonitorConfigManager *config_manager);
-
-META_EXPORT_TEST
-MetaMonitorsConfig * meta_monitor_config_manager_create_linear (MetaMonitorConfigManager *config_manager);
-
-META_EXPORT_TEST
-MetaMonitorsConfig * meta_monitor_config_manager_create_fallback (MetaMonitorConfigManager *config_manager);
-
-META_EXPORT_TEST
-MetaMonitorsConfig * meta_monitor_config_manager_create_suggested (MetaMonitorConfigManager *config_manager);
-
-META_EXPORT_TEST
-MetaMonitorsConfig * meta_monitor_config_manager_create_for_orientation (MetaMonitorConfigManager *config_manager,
- MetaMonitorTransform transform);
-
-META_EXPORT_TEST
-MetaMonitorsConfig * meta_monitor_config_manager_create_for_rotate_monitor (MetaMonitorConfigManager *config_manager);
-
-META_EXPORT_TEST
-MetaMonitorsConfig * meta_monitor_config_manager_create_for_switch_config (MetaMonitorConfigManager *config_manager,
- MetaMonitorSwitchConfigType config_type);
-
-META_EXPORT_TEST
-void meta_monitor_config_manager_set_current (MetaMonitorConfigManager *config_manager,
- MetaMonitorsConfig *config);
-
-META_EXPORT_TEST
-MetaMonitorsConfig * meta_monitor_config_manager_get_current (MetaMonitorConfigManager *config_manager);
-
-META_EXPORT_TEST
-MetaMonitorsConfig * meta_monitor_config_manager_pop_previous (MetaMonitorConfigManager *config_manager);
-
-META_EXPORT_TEST
-MetaMonitorsConfig * meta_monitor_config_manager_get_previous (MetaMonitorConfigManager *config_manager);
-
-META_EXPORT_TEST
-void meta_monitor_config_manager_clear_history (MetaMonitorConfigManager *config_manager);
-
-META_EXPORT_TEST
-void meta_monitor_config_manager_save_current (MetaMonitorConfigManager *config_manager);
-
-META_EXPORT_TEST
-MetaMonitorsConfig * meta_monitors_config_new_full (GList *logical_monitor_configs,
- GList *disabled_monitors,
- MetaLogicalMonitorLayoutMode layout_mode,
- MetaMonitorsConfigFlag flags);
-
-META_EXPORT_TEST
-MetaMonitorsConfig * meta_monitors_config_new (MetaMonitorManager *monitor_manager,
- GList *logical_monitor_configs,
- MetaLogicalMonitorLayoutMode layout_mode,
- MetaMonitorsConfigFlag flags);
-
-META_EXPORT_TEST
-MetaMonitorSwitchConfigType meta_monitors_config_get_switch_config (MetaMonitorsConfig *config);
-
-META_EXPORT_TEST
-void meta_monitors_config_set_switch_config (MetaMonitorsConfig *config,
- MetaMonitorSwitchConfigType switch_config);
-
-META_EXPORT_TEST
-unsigned int meta_monitors_config_key_hash (gconstpointer config_key);
-
-META_EXPORT_TEST
-gboolean meta_monitors_config_key_equal (gconstpointer config_key_a,
- gconstpointer config_key_b);
-
-META_EXPORT_TEST
-void meta_monitors_config_key_free (MetaMonitorsConfigKey *config_key);
-
-META_EXPORT_TEST
-void meta_logical_monitor_config_free (MetaLogicalMonitorConfig *logical_monitor_config);
-
-META_EXPORT_TEST
-void meta_monitor_config_free (MetaMonitorConfig *monitor_config);
-
-META_EXPORT_TEST
-MetaMonitorsConfigKey * meta_create_monitors_config_key_for_current_state (MetaMonitorManager *monitor_manager);
-
-META_EXPORT_TEST
-gboolean meta_logical_monitor_configs_have_monitor (GList *logical_monitor_configs,
- MetaMonitorSpec *monitor_spec);
-
-META_EXPORT_TEST
-gboolean meta_verify_monitor_mode_spec (MetaMonitorModeSpec *monitor_mode_spec,
- GError **error);
-
-META_EXPORT_TEST
-gboolean meta_verify_monitor_spec (MetaMonitorSpec *monitor_spec,
- GError **error);
-
-META_EXPORT_TEST
-gboolean meta_verify_monitor_config (MetaMonitorConfig *monitor_config,
- GError **error);
-
-META_EXPORT_TEST
-gboolean meta_verify_logical_monitor_config (MetaLogicalMonitorConfig *logical_monitor_config,
- MetaLogicalMonitorLayoutMode layout_mode,
- MetaMonitorManager *monitor_manager,
- GError **error);
-
-META_EXPORT_TEST
-gboolean meta_verify_monitors_config (MetaMonitorsConfig *config,
- MetaMonitorManager *monitor_manager,
- GError **error);
-
-#endif /* META_MONITOR_CONFIG_MANAGER_H */
diff --git a/src/backends/meta-monitor-config-migration.c b/src/backends/meta-monitor-config-migration.c
deleted file mode 100644
index d619dc433..000000000
--- a/src/backends/meta-monitor-config-migration.c
+++ /dev/null
@@ -1,1233 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2001, 2002 Havoc Pennington
- * Copyright (C) 2002, 2003 Red Hat Inc.
- * Some ICCCM manager selection code derived from fvwm2,
- * Copyright (C) 2001 Dominik Vogt, Matthias Clasen, and fvwm2 team
- * Copyright (C) 2003 Rob Adams
- * Copyright (C) 2004-2006 Elijah Newren
- * Copyright (C) 2013, 2017 Red Hat Inc.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, see <http://www.gnu.org/licenses/>.
- */
-
-/*
- * Portions of this file are derived from gnome-desktop/libgnome-desktop/gnome-rr-config.c
- *
- * Copyright 2007, 2008, Red Hat, Inc.
- * Copyright 2010 Giovanni Campagna
- *
- * Author: Soren Sandmann <sandmann@redhat.com>
- */
-
-#include "config.h"
-
-#include "backends/meta-monitor-config-migration.h"
-
-#include <gio/gio.h>
-#include <string.h>
-
-#include "backends/meta-monitor-config-manager.h"
-#include "backends/meta-monitor-config-store.h"
-#include "backends/meta-monitor-manager-private.h"
-#include "meta/boxes.h"
-
-#define META_MONITORS_CONFIG_MIGRATION_ERROR (meta_monitors_config_migration_error_quark ())
-static GQuark meta_monitors_config_migration_error_quark (void);
-
-G_DEFINE_QUARK (meta-monitors-config-migration-error-quark,
- meta_monitors_config_migration_error)
-
-enum _MetaConfigMigrationError
-{
- META_MONITORS_CONFIG_MIGRATION_ERROR_NOT_TILED,
- META_MONITORS_CONFIG_MIGRATION_ERROR_NOT_MAIN_TILE
-} MetaConfigMigrationError;
-
-typedef struct
-{
- char *connector;
- char *vendor;
- char *product;
- char *serial;
-} MetaOutputKey;
-
-typedef struct
-{
- gboolean enabled;
- MetaRectangle rect;
- float refresh_rate;
- MetaMonitorTransform transform;
-
- gboolean is_primary;
- gboolean is_presentation;
- gboolean is_underscanning;
-} MetaOutputConfig;
-
-typedef struct _MetaLegacyMonitorsConfig
-{
- MetaOutputKey *keys;
- MetaOutputConfig *outputs;
- unsigned int n_outputs;
-} MetaLegacyMonitorsConfig;
-
-typedef enum
-{
- STATE_INITIAL,
- STATE_MONITORS,
- STATE_CONFIGURATION,
- STATE_OUTPUT,
- STATE_OUTPUT_FIELD,
- STATE_CLONE
-} ParserState;
-
-typedef struct
-{
- ParserState state;
- int unknown_count;
-
- GArray *key_array;
- GArray *output_array;
- MetaOutputKey key;
- MetaOutputConfig output;
-
- char *output_field;
-
- GHashTable *configs;
-} ConfigParser;
-
-static MetaLegacyMonitorsConfig *
-legacy_config_new (void)
-{
- return g_new0 (MetaLegacyMonitorsConfig, 1);
-}
-
-static void
-legacy_config_free (gpointer data)
-{
- MetaLegacyMonitorsConfig *config = data;
-
- g_free (config->keys);
- g_free (config->outputs);
- g_free (config);
-}
-
-static unsigned long
-output_key_hash (const MetaOutputKey *key)
-{
- return (g_str_hash (key->connector) ^
- g_str_hash (key->vendor) ^
- g_str_hash (key->product) ^
- g_str_hash (key->serial));
-}
-
-static gboolean
-output_key_equal (const MetaOutputKey *one,
- const MetaOutputKey *two)
-{
- return (strcmp (one->connector, two->connector) == 0 &&
- strcmp (one->vendor, two->vendor) == 0 &&
- strcmp (one->product, two->product) == 0 &&
- strcmp (one->serial, two->serial) == 0);
-}
-
-static unsigned int
-legacy_config_hash (gconstpointer data)
-{
- const MetaLegacyMonitorsConfig *config = data;
- unsigned int i, hash;
-
- hash = 0;
- for (i = 0; i < config->n_outputs; i++)
- hash ^= output_key_hash (&config->keys[i]);
-
- return hash;
-}
-
-static gboolean
-legacy_config_equal (gconstpointer one,
- gconstpointer two)
-{
- const MetaLegacyMonitorsConfig *c_one = one;
- const MetaLegacyMonitorsConfig *c_two = two;
- unsigned int i;
- gboolean ok;
-
- if (c_one->n_outputs != c_two->n_outputs)
- return FALSE;
-
- ok = TRUE;
- for (i = 0; i < c_one->n_outputs && ok; i++)
- ok = output_key_equal (&c_one->keys[i],
- &c_two->keys[i]);
-
- return ok;
-}
-
-static void
-free_output_key (MetaOutputKey *key)
-{
- g_free (key->connector);
- g_free (key->vendor);
- g_free (key->product);
- g_free (key->serial);
-}
-
-static void
-handle_start_element (GMarkupParseContext *context,
- const char *element_name,
- const char **attribute_names,
- const char **attribute_values,
- gpointer user_data,
- GError **error)
-{
- ConfigParser *parser = user_data;
-
- switch (parser->state)
- {
- case STATE_INITIAL:
- {
- char *version;
-
- if (strcmp (element_name, "monitors") != 0)
- {
- g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_UNKNOWN_ELEMENT,
- "Invalid document element %s", element_name);
- return;
- }
-
- if (!g_markup_collect_attributes (element_name,
- attribute_names,
- attribute_values,
- error,
- G_MARKUP_COLLECT_STRING,
- "version", &version,
- G_MARKUP_COLLECT_INVALID))
- return;
-
- if (strcmp (version, "1") != 0)
- {
- g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
- "Invalid or unsupported version %s", version);
- return;
- }
-
- parser->state = STATE_MONITORS;
- return;
- }
-
- case STATE_MONITORS:
- {
- if (strcmp (element_name, "configuration") != 0)
- {
- g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_UNKNOWN_ELEMENT,
- "Invalid toplevel element %s", element_name);
- return;
- }
-
- parser->key_array = g_array_new (FALSE, FALSE,
- sizeof (MetaOutputKey));
- parser->output_array = g_array_new (FALSE, FALSE,
- sizeof (MetaOutputConfig));
- parser->state = STATE_CONFIGURATION;
- return;
- }
-
- case STATE_CONFIGURATION:
- {
- if (strcmp (element_name, "clone") == 0 &&
- parser->unknown_count == 0)
- {
- parser->state = STATE_CLONE;
- }
- else if (strcmp (element_name, "output") == 0 &&
- parser->unknown_count == 0)
- {
- char *name;
-
- if (!g_markup_collect_attributes (element_name,
- attribute_names,
- attribute_values,
- error,
- G_MARKUP_COLLECT_STRING,
- "name", &name,
- G_MARKUP_COLLECT_INVALID))
- return;
-
- memset (&parser->key, 0, sizeof (MetaOutputKey));
- memset (&parser->output, 0, sizeof (MetaOutputConfig));
-
- parser->key.connector = g_strdup (name);
- parser->state = STATE_OUTPUT;
- }
- else
- {
- parser->unknown_count++;
- }
-
- return;
- }
-
- case STATE_OUTPUT:
- {
- if ((strcmp (element_name, "vendor") == 0 ||
- strcmp (element_name, "product") == 0 ||
- strcmp (element_name, "serial") == 0 ||
- strcmp (element_name, "width") == 0 ||
- strcmp (element_name, "height") == 0 ||
- strcmp (element_name, "rate") == 0 ||
- strcmp (element_name, "x") == 0 ||
- strcmp (element_name, "y") == 0 ||
- strcmp (element_name, "rotation") == 0 ||
- strcmp (element_name, "reflect_x") == 0 ||
- strcmp (element_name, "reflect_y") == 0 ||
- strcmp (element_name, "primary") == 0 ||
- strcmp (element_name, "presentation") == 0 ||
- strcmp (element_name, "underscanning") == 0) &&
- parser->unknown_count == 0)
- {
- parser->state = STATE_OUTPUT_FIELD;
-
- parser->output_field = g_strdup (element_name);
- }
- else
- {
- parser->unknown_count++;
- }
-
- return;
- }
-
- case STATE_CLONE:
- case STATE_OUTPUT_FIELD:
- {
- g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
- "Unexpected element %s", element_name);
- return;
- }
-
- default:
- g_assert_not_reached ();
- }
-}
-
-static void
-handle_end_element (GMarkupParseContext *context,
- const char *element_name,
- gpointer user_data,
- GError **error)
-{
- ConfigParser *parser = user_data;
-
- switch (parser->state)
- {
- case STATE_MONITORS:
- {
- parser->state = STATE_INITIAL;
- return;
- }
-
- case STATE_CONFIGURATION:
- {
- if (strcmp (element_name, "configuration") == 0 &&
- parser->unknown_count == 0)
- {
- MetaLegacyMonitorsConfig *config = legacy_config_new ();
-
- g_assert (parser->key_array->len == parser->output_array->len);
-
- config->n_outputs = parser->key_array->len;
- config->keys = (void*)g_array_free (parser->key_array, FALSE);
- config->outputs = (void*)g_array_free (parser->output_array, FALSE);
-
- g_hash_table_replace (parser->configs, config, config);
-
- parser->key_array = NULL;
- parser->output_array = NULL;
- parser->state = STATE_MONITORS;
- }
- else
- {
- parser->unknown_count--;
-
- g_assert (parser->unknown_count >= 0);
- }
-
- return;
- }
-
- case STATE_OUTPUT:
- {
- if (strcmp (element_name, "output") == 0 && parser->unknown_count == 0)
- {
- if (parser->key.vendor == NULL ||
- parser->key.product == NULL ||
- parser->key.serial == NULL)
- {
- /* Disconnected output, ignore */
- free_output_key (&parser->key);
- }
- else
- {
- if (parser->output.rect.width == 0 ||
- parser->output.rect.height == 0)
- parser->output.enabled = FALSE;
- else
- parser->output.enabled = TRUE;
-
- g_array_append_val (parser->key_array, parser->key);
- g_array_append_val (parser->output_array, parser->output);
- }
-
- memset (&parser->key, 0, sizeof (MetaOutputKey));
- memset (&parser->output, 0, sizeof (MetaOutputConfig));
-
- parser->state = STATE_CONFIGURATION;
- }
- else
- {
- parser->unknown_count--;
-
- g_assert (parser->unknown_count >= 0);
- }
-
- return;
- }
-
- case STATE_CLONE:
- {
- parser->state = STATE_CONFIGURATION;
- return;
- }
-
- case STATE_OUTPUT_FIELD:
- {
- g_free (parser->output_field);
- parser->output_field = NULL;
-
- parser->state = STATE_OUTPUT;
- return;
- }
-
- case STATE_INITIAL:
- default:
- g_assert_not_reached ();
- }
-}
-
-static void
-read_int (const char *text,
- gsize text_len,
- gint *field,
- GError **error)
-{
- char buf[64];
- gint64 v;
- char *end;
-
- strncpy (buf, text, text_len);
- buf[MIN (63, text_len)] = 0;
-
- v = g_ascii_strtoll (buf, &end, 10);
-
- /* Limit reasonable values (actual limits are a lot smaller that these) */
- if (*end || v < 0 || v > G_MAXINT16)
- g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
- "Expected a number, got %s", buf);
- else
- *field = v;
-}
-
-static void
-read_float (const char *text,
- gsize text_len,
- gfloat *field,
- GError **error)
-{
- char buf[64];
- gfloat v;
- char *end;
-
- strncpy (buf, text, text_len);
- buf[MIN (63, text_len)] = 0;
-
- v = g_ascii_strtod (buf, &end);
-
- /* Limit reasonable values (actual limits are a lot smaller that these) */
- if (*end)
- g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
- "Expected a number, got %s", buf);
- else
- *field = v;
-}
-
-static gboolean
-read_bool (const char *text,
- gsize text_len,
- GError **error)
-{
- if (strncmp (text, "no", text_len) == 0)
- return FALSE;
- else if (strncmp (text, "yes", text_len) == 0)
- return TRUE;
- else
- g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
- "Invalid boolean value %.*s", (int)text_len, text);
-
- return FALSE;
-}
-
-static gboolean
-is_all_whitespace (const char *text,
- gsize text_len)
-{
- gsize i;
-
- for (i = 0; i < text_len; i++)
- if (!g_ascii_isspace (text[i]))
- return FALSE;
-
- return TRUE;
-}
-
-static void
-handle_text (GMarkupParseContext *context,
- const gchar *text,
- gsize text_len,
- gpointer user_data,
- GError **error)
-{
- ConfigParser *parser = user_data;
-
- switch (parser->state)
- {
- case STATE_MONITORS:
- {
- if (!is_all_whitespace (text, text_len))
- g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
- "Unexpected content at this point");
- return;
- }
-
- case STATE_CONFIGURATION:
- {
- if (parser->unknown_count == 0)
- {
- if (!is_all_whitespace (text, text_len))
- g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
- "Unexpected content at this point");
- }
- else
- {
- /* Handling unknown element, ignore */
- }
-
- return;
- }
-
- case STATE_OUTPUT:
- {
- if (parser->unknown_count == 0)
- {
- if (!is_all_whitespace (text, text_len))
- g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
- "Unexpected content at this point");
- }
- else
- {
- /* Handling unknown element, ignore */
- }
- return;
- }
-
- case STATE_CLONE:
- {
- /* Ignore the clone flag */
- return;
- }
-
- case STATE_OUTPUT_FIELD:
- {
- if (strcmp (parser->output_field, "vendor") == 0)
- parser->key.vendor = g_strndup (text, text_len);
- else if (strcmp (parser->output_field, "product") == 0)
- parser->key.product = g_strndup (text, text_len);
- else if (strcmp (parser->output_field, "serial") == 0)
- parser->key.serial = g_strndup (text, text_len);
- else if (strcmp (parser->output_field, "width") == 0)
- read_int (text, text_len, &parser->output.rect.width, error);
- else if (strcmp (parser->output_field, "height") == 0)
- read_int (text, text_len, &parser->output.rect.height, error);
- else if (strcmp (parser->output_field, "rate") == 0)
- read_float (text, text_len, &parser->output.refresh_rate, error);
- else if (strcmp (parser->output_field, "x") == 0)
- read_int (text, text_len, &parser->output.rect.x, error);
- else if (strcmp (parser->output_field, "y") == 0)
- read_int (text, text_len, &parser->output.rect.y, error);
- else if (strcmp (parser->output_field, "rotation") == 0)
- {
- if (strncmp (text, "normal", text_len) == 0)
- parser->output.transform = META_MONITOR_TRANSFORM_NORMAL;
- else if (strncmp (text, "left", text_len) == 0)
- parser->output.transform = META_MONITOR_TRANSFORM_90;
- else if (strncmp (text, "upside_down", text_len) == 0)
- parser->output.transform = META_MONITOR_TRANSFORM_180;
- else if (strncmp (text, "right", text_len) == 0)
- parser->output.transform = META_MONITOR_TRANSFORM_270;
- else
- g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
- "Invalid rotation type %.*s", (int)text_len, text);
- }
- else if (strcmp (parser->output_field, "reflect_x") == 0)
- parser->output.transform += read_bool (text, text_len, error) ?
- META_MONITOR_TRANSFORM_FLIPPED : 0;
- else if (strcmp (parser->output_field, "reflect_y") == 0)
- {
- if (read_bool (text, text_len, error))
- g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
- "Y reflection is not supported");
- }
- else if (strcmp (parser->output_field, "primary") == 0)
- parser->output.is_primary = read_bool (text, text_len, error);
- else if (strcmp (parser->output_field, "presentation") == 0)
- parser->output.is_presentation = read_bool (text, text_len, error);
- else if (strcmp (parser->output_field, "underscanning") == 0)
- parser->output.is_underscanning = read_bool (text, text_len, error);
- else
- g_assert_not_reached ();
- return;
- }
-
- case STATE_INITIAL:
- default:
- g_assert_not_reached ();
- }
-}
-
-static const GMarkupParser config_parser = {
- .start_element = handle_start_element,
- .end_element = handle_end_element,
- .text = handle_text,
-};
-
-static GHashTable *
-load_config_file (GFile *file,
- GError **error)
-{
- g_autofree char *contents = NULL;
- gsize size;
- g_autoptr (GMarkupParseContext) context = NULL;
- ConfigParser parser = { 0 };
-
- if (!g_file_load_contents (file, NULL, &contents, &size, NULL, error))
- return FALSE;
-
- parser.configs = g_hash_table_new_full (legacy_config_hash,
- legacy_config_equal,
- legacy_config_free,
- NULL);
- parser.state = STATE_INITIAL;
-
- context = g_markup_parse_context_new (&config_parser,
- G_MARKUP_TREAT_CDATA_AS_TEXT |
- G_MARKUP_PREFIX_ERROR_POSITION,
- &parser, NULL);
- if (!g_markup_parse_context_parse (context, contents, size, error))
- {
- if (parser.key_array)
- g_array_free (parser.key_array, TRUE);
- if (parser.output_array)
- g_array_free (parser.output_array, TRUE);
-
- free_output_key (&parser.key);
- g_free (parser.output_field);
- g_hash_table_destroy (parser.configs);
-
- return NULL;
- }
-
- return parser.configs;
-}
-
-static MetaMonitorConfig *
-create_monitor_config (MetaOutputKey *output_key,
- MetaOutputConfig *output_config,
- int mode_width,
- int mode_height,
- GError **error)
-{
- MetaMonitorModeSpec *mode_spec;
- MetaMonitorSpec *monitor_spec;
- MetaMonitorConfig *monitor_config;
-
- mode_spec = g_new0 (MetaMonitorModeSpec, 1);
- *mode_spec = (MetaMonitorModeSpec) {
- .width = mode_width,
- .height = mode_height,
- .refresh_rate = output_config->refresh_rate
- };
-
- if (!meta_verify_monitor_mode_spec (mode_spec, error))
- {
- g_free (mode_spec);
- return NULL;
- }
-
- monitor_spec = g_new0 (MetaMonitorSpec, 1);
- *monitor_spec = (MetaMonitorSpec) {
- .connector = output_key->connector,
- .vendor = output_key->vendor,
- .product = output_key->product,
- .serial = output_key->serial
- };
-
- monitor_config = g_new0 (MetaMonitorConfig, 1);
- *monitor_config = (MetaMonitorConfig) {
- .monitor_spec = monitor_spec,
- .mode_spec = mode_spec,
- .enable_underscanning = output_config->is_underscanning
- };
-
- if (!meta_verify_monitor_config (monitor_config, error))
- {
- meta_monitor_config_free (monitor_config);
- return NULL;
- }
-
- return monitor_config;
-}
-
-typedef struct _MonitorTile
-{
- MetaOutputKey *output_key;
- MetaOutputConfig *output_config;
-} MonitorTile;
-
-static MetaMonitorConfig *
-try_derive_tiled_monitor_config (MetaLegacyMonitorsConfig *config,
- MetaOutputKey *output_key,
- MetaOutputConfig *output_config,
- MetaMonitorConfigStore *config_store,
- MetaRectangle *out_layout,
- GError **error)
-{
- MonitorTile top_left_tile = { 0 };
- MonitorTile top_right_tile = { 0 };
- MonitorTile bottom_left_tile = { 0 };
- MonitorTile bottom_right_tile = { 0 };
- MonitorTile origin_tile = { 0 };
- MetaMonitorTransform transform = output_config->transform;
- unsigned int i;
- int max_x = 0;
- int min_x = INT_MAX;
- int max_y = 0;
- int min_y = INT_MAX;
- int mode_width = 0;
- int mode_height = 0;
- MetaMonitorConfig *monitor_config;
-
- /*
- * In order to derive a monitor configuration for a tiled monitor,
- * try to find the origin tile, then combine the discovered output
- * tiles to given the configured transform a monitor mode.
- *
- * If the origin tile is not the main tile (tile always enabled
- * even for non-tiled modes), this will fail, but since infermation
- * about tiling is lost, there is no way to discover it.
- */
-
- for (i = 0; i < config->n_outputs; i++)
- {
- MetaOutputKey *other_output_key = &config->keys[i];
- MetaOutputConfig *other_output_config = &config->outputs[i];
- MetaRectangle *rect;
-
- if (strcmp (output_key->vendor, other_output_key->vendor) != 0 ||
- strcmp (output_key->product, other_output_key->product) != 0 ||
- strcmp (output_key->serial, other_output_key->serial) != 0)
- continue;
-
- rect = &other_output_config->rect;
- min_x = MIN (min_x, rect->x);
- min_y = MIN (min_y, rect->y);
- max_x = MAX (max_x, rect->x + rect->width);
- max_y = MAX (max_y, rect->y + rect->height);
-
- if (min_x == rect->x &&
- min_y == rect->y)
- {
- top_left_tile = (MonitorTile) {
- .output_key = other_output_key,
- .output_config = other_output_config
- };
- }
- if (max_x == rect->x + rect->width &&
- min_y == rect->y)
- {
- top_right_tile = (MonitorTile) {
- .output_key = other_output_key,
- .output_config = other_output_config
- };
- }
- if (min_x == rect->x &&
- max_y == rect->y + rect->height)
- {
- bottom_left_tile = (MonitorTile) {
- .output_key = other_output_key,
- .output_config = other_output_config
- };
- }
- if (max_x == rect->x + rect->width &&
- max_y == rect->y + rect->height)
- {
- bottom_right_tile = (MonitorTile) {
- .output_key = other_output_key,
- .output_config = other_output_config
- };
- }
- }
-
- if (top_left_tile.output_key == bottom_right_tile.output_key)
- {
- g_set_error_literal (error,
- META_MONITORS_CONFIG_MIGRATION_ERROR,
- META_MONITORS_CONFIG_MIGRATION_ERROR_NOT_TILED,
- "Not a tiled monitor");
- return NULL;
- }
-
- switch (transform)
- {
- case META_MONITOR_TRANSFORM_NORMAL:
- origin_tile = top_left_tile;
- mode_width = max_x - min_x;
- mode_height = max_y - min_y;
- break;
- case META_MONITOR_TRANSFORM_90:
- origin_tile = bottom_left_tile;
- mode_width = max_y - min_y;
- mode_height = max_x - min_x;
- break;
- case META_MONITOR_TRANSFORM_180:
- origin_tile = bottom_right_tile;
- mode_width = max_x - min_x;
- mode_height = max_y - min_y;
- break;
- case META_MONITOR_TRANSFORM_270:
- origin_tile = top_right_tile;
- mode_width = max_y - min_y;
- mode_height = max_x - min_x;
- break;
- case META_MONITOR_TRANSFORM_FLIPPED:
- origin_tile = bottom_left_tile;
- mode_width = max_x - min_x;
- mode_height = max_y - min_y;
- break;
- case META_MONITOR_TRANSFORM_FLIPPED_90:
- origin_tile = bottom_right_tile;
- mode_width = max_y - min_y;
- mode_height = max_x - min_x;
- break;
- case META_MONITOR_TRANSFORM_FLIPPED_180:
- origin_tile = top_right_tile;
- mode_width = max_x - min_x;
- mode_height = max_y - min_y;
- break;
- case META_MONITOR_TRANSFORM_FLIPPED_270:
- origin_tile = top_left_tile;
- mode_width = max_y - min_y;
- mode_height = max_x - min_x;
- break;
- }
-
- g_assert (origin_tile.output_key);
- g_assert (origin_tile.output_config);
-
- if (origin_tile.output_key != output_key)
- {
- g_set_error_literal (error,
- META_MONITORS_CONFIG_MIGRATION_ERROR,
- META_MONITORS_CONFIG_MIGRATION_ERROR_NOT_MAIN_TILE,
- "Not the main tile");
- return NULL;
- }
-
- monitor_config = create_monitor_config (origin_tile.output_key,
- origin_tile.output_config,
- mode_width, mode_height,
- error);
- if (!monitor_config)
- return NULL;
-
- *out_layout = (MetaRectangle) {
- .x = min_x,
- .y = min_y,
- .width = max_x - min_x,
- .height = max_y - min_y
- };
-
- return monitor_config;
-}
-
-static MetaMonitorConfig *
-derive_monitor_config (MetaOutputKey *output_key,
- MetaOutputConfig *output_config,
- MetaRectangle *out_layout,
- GError **error)
-{
- int mode_width;
- int mode_height;
- MetaMonitorConfig *monitor_config;
-
- if (meta_monitor_transform_is_rotated (output_config->transform))
- {
- mode_width = output_config->rect.height;
- mode_height = output_config->rect.width;
- }
- else
- {
- mode_width = output_config->rect.width;
- mode_height = output_config->rect.height;
- }
-
- monitor_config = create_monitor_config (output_key, output_config,
- mode_width, mode_height,
- error);
- if (!monitor_config)
- return NULL;
-
- *out_layout = output_config->rect;
-
- return monitor_config;
-}
-
-static MetaLogicalMonitorConfig *
-ensure_logical_monitor (GList **logical_monitor_configs,
- MetaOutputConfig *output_config,
- MetaRectangle *layout)
-{
- MetaLogicalMonitorConfig *new_logical_monitor_config;
- GList *l;
-
- for (l = *logical_monitor_configs; l; l = l->next)
- {
- MetaLogicalMonitorConfig *logical_monitor_config = l->data;
-
- if (meta_rectangle_equal (&logical_monitor_config->layout, layout))
- return logical_monitor_config;
- }
-
- new_logical_monitor_config = g_new0 (MetaLogicalMonitorConfig, 1);
- *new_logical_monitor_config = (MetaLogicalMonitorConfig) {
- .layout = *layout,
- .is_primary = output_config->is_primary,
- .is_presentation = output_config->is_presentation,
- .transform = output_config->transform,
- .scale = -1.0,
- };
-
- *logical_monitor_configs = g_list_append (*logical_monitor_configs,
- new_logical_monitor_config);
-
- return new_logical_monitor_config;
-}
-
-static GList *
-derive_logical_monitor_configs (MetaLegacyMonitorsConfig *config,
- MetaMonitorConfigStore *config_store,
- GError **error)
-{
- GList *logical_monitor_configs = NULL;
- unsigned int i;
-
- for (i = 0; i < config->n_outputs; i++)
- {
- MetaOutputKey *output_key = &config->keys[i];
- MetaOutputConfig *output_config = &config->outputs[i];
- MetaMonitorConfig *monitor_config = NULL;
- MetaRectangle layout;
- MetaLogicalMonitorConfig *logical_monitor_config;
-
- if (!output_config->enabled)
- continue;
-
- if (output_key->vendor &&
- g_strcmp0 (output_key->vendor, "unknown") != 0 &&
- output_key->product &&
- g_strcmp0 (output_key->product, "unknown") != 0 &&
- output_key->serial &&
- g_strcmp0 (output_key->serial, "unknown") != 0)
- {
- monitor_config = try_derive_tiled_monitor_config (config,
- output_key,
- output_config,
- config_store,
- &layout,
- error);
- if (!monitor_config)
- {
- if ((*error)->domain == META_MONITORS_CONFIG_MIGRATION_ERROR)
- {
- int error_code = (*error)->code;
-
- g_clear_error (error);
-
- switch (error_code)
- {
- case META_MONITORS_CONFIG_MIGRATION_ERROR_NOT_TILED:
- break;
- case META_MONITORS_CONFIG_MIGRATION_ERROR_NOT_MAIN_TILE:
- continue;
- }
- }
- else
- {
- g_list_free_full (logical_monitor_configs,
- (GDestroyNotify) meta_logical_monitor_config_free);
- return NULL;
- }
- }
- }
-
- if (!monitor_config)
- monitor_config = derive_monitor_config (output_key, output_config,
- &layout,
- error);
-
- if (!monitor_config)
- {
- g_list_free_full (logical_monitor_configs,
- (GDestroyNotify) meta_logical_monitor_config_free);
- return NULL;
- }
-
- logical_monitor_config =
- ensure_logical_monitor (&logical_monitor_configs,
- output_config, &layout);
-
- logical_monitor_config->monitor_configs =
- g_list_append (logical_monitor_config->monitor_configs, monitor_config);
- }
-
- if (!logical_monitor_configs)
- {
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Empty configuration");
- return NULL;
- }
-
- return logical_monitor_configs;
-}
-
-static char *
-generate_config_name (MetaLegacyMonitorsConfig *config)
-{
- char **output_strings;
- unsigned int i;
- char *key_name;
-
- output_strings = g_new0 (char *, config->n_outputs + 1);
- for (i = 0; i < config->n_outputs; i++)
- {
- MetaOutputKey *output_key = &config->keys[i];
-
- output_strings[i] = g_strdup_printf ("%s:%s:%s:%s",
- output_key->connector,
- output_key->vendor,
- output_key->product,
- output_key->serial);
- }
-
- key_name = g_strjoinv (", ", output_strings);
-
- g_strfreev (output_strings);
-
- return key_name;
-}
-
-static GList *
-find_disabled_monitor_specs (MetaLegacyMonitorsConfig *legacy_config)
-{
- GList *disabled_monitors = NULL;
- unsigned int i;
-
- for (i = 0; i < legacy_config->n_outputs; i++)
- {
- MetaOutputKey *output_key = &legacy_config->keys[i];
- MetaOutputConfig *output_config = &legacy_config->outputs[i];
- MetaMonitorSpec *monitor_spec;
-
- if (output_config->enabled)
- continue;
-
- monitor_spec = g_new0 (MetaMonitorSpec, 1);
- *monitor_spec = (MetaMonitorSpec) {
- .connector = output_key->connector,
- .vendor = output_key->vendor,
- .product = output_key->product,
- .serial = output_key->serial
- };
-
- disabled_monitors = g_list_prepend (disabled_monitors, monitor_spec);
- }
-
- return disabled_monitors;
-}
-
-static void
-migrate_config (gpointer key,
- gpointer value,
- gpointer user_data)
-{
- MetaLegacyMonitorsConfig *legacy_config = key;
- MetaMonitorConfigStore *config_store = user_data;
- MetaMonitorManager *monitor_manager =
- meta_monitor_config_store_get_monitor_manager (config_store);
- GList *logical_monitor_configs;
- MetaLogicalMonitorLayoutMode layout_mode;
- GError *error = NULL;
- GList *disabled_monitor_specs;
- MetaMonitorsConfig *config;
-
- logical_monitor_configs = derive_logical_monitor_configs (legacy_config,
- config_store,
- &error);
- if (!logical_monitor_configs)
- {
- g_autofree char *config_name = NULL;
-
- config_name = generate_config_name (legacy_config);
- g_warning ("Failed to migrate monitor configuration for %s: %s",
- config_name, error->message);
- return;
- }
-
- disabled_monitor_specs = find_disabled_monitor_specs (legacy_config);
-
- layout_mode = META_LOGICAL_MONITOR_LAYOUT_MODE_PHYSICAL;
- config = meta_monitors_config_new_full (logical_monitor_configs,
- disabled_monitor_specs,
- layout_mode,
- META_MONITORS_CONFIG_FLAG_MIGRATED);
- if (!meta_verify_monitors_config (config, monitor_manager, &error))
- {
- g_autofree char *config_name = NULL;
-
- config_name = generate_config_name (legacy_config);
- g_warning ("Ignoring invalid monitor configuration for %s: %s",
- config_name, error->message);
- g_object_unref (config);
- return;
- }
-
- meta_monitor_config_store_add (config_store, config);
-}
-
-gboolean
-meta_migrate_old_monitors_config (MetaMonitorConfigStore *config_store,
- GFile *in_file,
- GError **error)
-{
- g_autoptr (GHashTable) configs = NULL;
-
- configs = load_config_file (in_file, error);
- if (!configs)
- return FALSE;
-
- g_hash_table_foreach (configs, migrate_config, config_store);
-
- return TRUE;
-}
-
-gboolean
-meta_migrate_old_user_monitors_config (MetaMonitorConfigStore *config_store,
- GError **error)
-{
- g_autofree char *backup_path = NULL;
- g_autoptr (GFile) backup_file = NULL;
- g_autofree char *user_file_path = NULL;
- g_autoptr (GFile) user_file = NULL;
-
- user_file_path = g_build_filename (g_get_user_config_dir (),
- "monitors.xml",
- NULL);
- user_file = g_file_new_for_path (user_file_path);
- backup_path = g_build_filename (g_get_user_config_dir (),
- "monitors-v1-backup.xml",
- NULL);
- backup_file = g_file_new_for_path (backup_path);
-
- if (!g_file_copy (user_file, backup_file,
- G_FILE_COPY_OVERWRITE | G_FILE_COPY_BACKUP,
- NULL, NULL, NULL,
- error))
- {
- g_warning ("Failed to make a backup of monitors.xml: %s",
- (*error)->message);
- g_clear_error (error);
- }
-
- return meta_migrate_old_monitors_config (config_store, user_file, error);
-}
-
-gboolean
-meta_finish_monitors_config_migration (MetaMonitorManager *monitor_manager,
- MetaMonitorsConfig *config,
- GError **error)
-{
- MetaMonitorConfigManager *config_manager = monitor_manager->config_manager;
- MetaMonitorConfigStore *config_store =
- meta_monitor_config_manager_get_store (config_manager);
- GList *l;
-
- for (l = config->logical_monitor_configs; l; l = l->next)
- {
- MetaLogicalMonitorConfig *logical_monitor_config = l->data;
- MetaMonitorConfig *monitor_config;
- MetaMonitorSpec *monitor_spec;
- MetaMonitor *monitor;
- MetaMonitorModeSpec *monitor_mode_spec;
- MetaMonitorMode *monitor_mode;
- float scale;
-
- monitor_config = logical_monitor_config->monitor_configs->data;
- monitor_spec = monitor_config->monitor_spec;
- monitor = meta_monitor_manager_get_monitor_from_spec (monitor_manager,
- monitor_spec);
- monitor_mode_spec = monitor_config->mode_spec;
- monitor_mode = meta_monitor_get_mode_from_spec (monitor,
- monitor_mode_spec);
- if (!monitor_mode)
- {
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- "Mode not available on monitor");
- return FALSE;
- }
-
- scale = meta_monitor_calculate_mode_scale (monitor, monitor_mode);
-
- logical_monitor_config->scale = scale;
- }
-
- config->layout_mode =
- meta_monitor_manager_get_default_layout_mode (monitor_manager);
- config->flags &= ~META_MONITORS_CONFIG_FLAG_MIGRATED;
-
- if (!meta_verify_monitors_config (config, monitor_manager, error))
- return FALSE;
-
- meta_monitor_config_store_add (config_store, config);
-
- return TRUE;
-}
diff --git a/src/backends/meta-monitor-config-migration.h b/src/backends/meta-monitor-config-migration.h
deleted file mode 100644
index 7b338ace2..000000000
--- a/src/backends/meta-monitor-config-migration.h
+++ /dev/null
@@ -1,41 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2017 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-
-#ifndef META_MONITOR_CONFIG_MIGRATION_H
-#define META_MONITOR_CONFIG_MIGRATION_H
-
-#include "backends/meta-monitor-manager-private.h"
-
-META_EXPORT_TEST
-gboolean meta_migrate_old_monitors_config (MetaMonitorConfigStore *config_store,
- GFile *in_file,
- GError **error);
-
-META_EXPORT_TEST
-gboolean meta_migrate_old_user_monitors_config (MetaMonitorConfigStore *config_store,
- GError **error);
-
-META_EXPORT_TEST
-gboolean meta_finish_monitors_config_migration (MetaMonitorManager *monitor_manager,
- MetaMonitorsConfig *config,
- GError **error);
-
-#endif /* META_MONITOR_CONFIG_MIGRATION_H */
diff --git a/src/backends/meta-monitor-config-store.c b/src/backends/meta-monitor-config-store.c
deleted file mode 100644
index 4dd357a15..000000000
--- a/src/backends/meta-monitor-config-store.c
+++ /dev/null
@@ -1,1683 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2017 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-
-#include "config.h"
-
-#include "backends/meta-monitor-config-store.h"
-
-#include <gio/gio.h>
-#include <string.h>
-
-#include "backends/meta-monitor-config-manager.h"
-#include "backends/meta-monitor-config-migration.h"
-
-#define MONITORS_CONFIG_XML_FORMAT_VERSION 2
-
-#define QUOTE1(a) #a
-#define QUOTE(a) QUOTE1(a)
-
-/*
- * Example configuration:
- *
- * <monitors version="2">
- * <configuration>
- * <logicalmonitor>
- * <x>0</x>
- * <y>0</y>
- * <scale>1</scale>
- * <monitor>
- * <monitorspec>
- * <connector>LVDS1</connector>
- * <vendor>Vendor A</vendor>
- * <product>Product A</product>
- * <serial>Serial A</serial>
- * </monitorspec>
- * <mode>
- * <width>1920</width>
- * <height>1080</height>
- * <rate>60.049972534179688</rate>
- * <flag>interlace</flag>
- * </mode>
- * </monitor>
- * <transform>
- * <rotation>right</rotation>
- * <flipped>no</flipped>
- * </transform>
- * <primary>yes</primary>
- * <presentation>no</presentation>
- * </logicalmonitor>
- * <logicalmonitor>
- * <x>1920</x>
- * <y>1080</y>
- * <monitor>
- * <monitorspec>
- * <connector>LVDS2</connector>
- * <vendor>Vendor B</vendor>
- * <product>Product B</product>
- * <serial>Serial B</serial>
- * </monitorspec>
- * <mode>
- * <width>1920</width>
- * <height>1080</height>
- * <rate>60.049972534179688</rate>
- * </mode>
- * <underscanning>yes</underscanning>
- * </monitor>
- * <presentation>yes</presentation>
- * </logicalmonitor>
- * <disabled>
- * <monitorspec>
- * <connector>LVDS3</connector>
- * <vendor>Vendor C</vendor>
- * <product>Product C</product>
- * <serial>Serial C</serial>
- * </monitorspec>
- * </disabled>
- * </configuration>
- * </monitors>
- *
- */
-
-enum
-{
- PROP_0,
-
- PROP_MONITOR_MANAGER,
-
- PROP_LAST
-};
-
-static GParamSpec *obj_props[PROP_LAST];
-
-struct _MetaMonitorConfigStore
-{
- GObject parent;
-
- MetaMonitorManager *monitor_manager;
-
- GHashTable *configs;
-
- GCancellable *save_cancellable;
-
- GFile *user_file;
- GFile *custom_read_file;
- GFile *custom_write_file;
-};
-
-#define META_MONITOR_CONFIG_STORE_ERROR (meta_monitor_config_store_error_quark ())
-static GQuark meta_monitor_config_store_error_quark (void);
-
-enum
-{
- META_MONITOR_CONFIG_STORE_ERROR_NEEDS_MIGRATION
-};
-
-G_DEFINE_QUARK (meta-monitor-config-store-error-quark,
- meta_monitor_config_store_error)
-
-typedef enum
-{
- STATE_INITIAL,
- STATE_MONITORS,
- STATE_CONFIGURATION,
- STATE_MIGRATED,
- STATE_LOGICAL_MONITOR,
- STATE_LOGICAL_MONITOR_X,
- STATE_LOGICAL_MONITOR_Y,
- STATE_LOGICAL_MONITOR_PRIMARY,
- STATE_LOGICAL_MONITOR_PRESENTATION,
- STATE_LOGICAL_MONITOR_SCALE,
- STATE_TRANSFORM,
- STATE_TRANSFORM_ROTATION,
- STATE_TRANSFORM_FLIPPED,
- STATE_MONITOR,
- STATE_MONITOR_SPEC,
- STATE_MONITOR_SPEC_CONNECTOR,
- STATE_MONITOR_SPEC_VENDOR,
- STATE_MONITOR_SPEC_PRODUCT,
- STATE_MONITOR_SPEC_SERIAL,
- STATE_MONITOR_MODE,
- STATE_MONITOR_MODE_WIDTH,
- STATE_MONITOR_MODE_HEIGHT,
- STATE_MONITOR_MODE_RATE,
- STATE_MONITOR_MODE_FLAG,
- STATE_MONITOR_UNDERSCANNING,
- STATE_DISABLED,
-} ParserState;
-
-typedef struct
-{
- ParserState state;
- MetaMonitorConfigStore *config_store;
-
- ParserState monitor_spec_parent_state;
-
- gboolean current_was_migrated;
- GList *current_logical_monitor_configs;
- MetaMonitorSpec *current_monitor_spec;
- gboolean current_transform_flipped;
- MetaMonitorTransform current_transform;
- MetaMonitorModeSpec *current_monitor_mode_spec;
- MetaMonitorConfig *current_monitor_config;
- MetaLogicalMonitorConfig *current_logical_monitor_config;
- GList *current_disabled_monitor_specs;
-
- MetaMonitorsConfigFlag extra_config_flags;
-} ConfigParser;
-
-G_DEFINE_TYPE (MetaMonitorConfigStore, meta_monitor_config_store,
- G_TYPE_OBJECT)
-
-static void
-handle_start_element (GMarkupParseContext *context,
- const char *element_name,
- const char **attribute_names,
- const char **attribute_values,
- gpointer user_data,
- GError **error)
-{
- ConfigParser *parser = user_data;
-
- switch (parser->state)
- {
- case STATE_INITIAL:
- {
- char *version;
-
- if (!g_str_equal (element_name, "monitors"))
- {
- g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_UNKNOWN_ELEMENT,
- "Invalid document element '%s'", element_name);
- return;
- }
-
- if (!g_markup_collect_attributes (element_name, attribute_names, attribute_values,
- error,
- G_MARKUP_COLLECT_STRING, "version", &version,
- G_MARKUP_COLLECT_INVALID))
- {
- g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
- "Missing config file format version");
- }
-
- if (g_str_equal (version, "1"))
- {
- g_set_error_literal (error,
- META_MONITOR_CONFIG_STORE_ERROR,
- META_MONITOR_CONFIG_STORE_ERROR_NEEDS_MIGRATION,
- "monitors.xml has the old format");
- return;
- }
-
- if (!g_str_equal (version, QUOTE (MONITORS_CONFIG_XML_FORMAT_VERSION)))
- {
- g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
- "Invalid or unsupported version '%s'", version);
- return;
- }
-
- parser->state = STATE_MONITORS;
- return;
- }
-
- case STATE_MONITORS:
- {
- if (!g_str_equal (element_name, "configuration"))
- {
- g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_UNKNOWN_ELEMENT,
- "Invalid toplevel element '%s'", element_name);
- return;
- }
-
- parser->state = STATE_CONFIGURATION;
- parser->current_was_migrated = FALSE;
-
- return;
- }
-
- case STATE_CONFIGURATION:
- {
- if (g_str_equal (element_name, "logicalmonitor"))
- {
- parser->current_logical_monitor_config =
- g_new0 (MetaLogicalMonitorConfig, 1);
-
- parser->state = STATE_LOGICAL_MONITOR;
- }
- else if (g_str_equal (element_name, "migrated"))
- {
- parser->current_was_migrated = TRUE;
-
- parser->state = STATE_MIGRATED;
- }
- else if (g_str_equal (element_name, "disabled"))
- {
- parser->state = STATE_DISABLED;
- }
- else
- {
- g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_UNKNOWN_ELEMENT,
- "Invalid configuration element '%s'", element_name);
- return;
- }
-
- return;
- }
-
- case STATE_MIGRATED:
- {
- g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_UNKNOWN_ELEMENT,
- "Unexpected element '%s'", element_name);
- return;
- }
-
- case STATE_LOGICAL_MONITOR:
- {
- if (g_str_equal (element_name, "x"))
- {
- parser->state = STATE_LOGICAL_MONITOR_X;
- }
- else if (g_str_equal (element_name, "y"))
- {
- parser->state = STATE_LOGICAL_MONITOR_Y;
- }
- else if (g_str_equal (element_name, "scale"))
- {
- parser->state = STATE_LOGICAL_MONITOR_SCALE;
- }
- else if (g_str_equal (element_name, "primary"))
- {
- parser->state = STATE_LOGICAL_MONITOR_PRIMARY;
- }
- else if (g_str_equal (element_name, "presentation"))
- {
- parser->state = STATE_LOGICAL_MONITOR_PRESENTATION;
- }
- else if (g_str_equal (element_name, "transform"))
- {
- parser->state = STATE_TRANSFORM;
- }
- else if (g_str_equal (element_name, "monitor"))
- {
- parser->current_monitor_config = g_new0 (MetaMonitorConfig, 1);
-
- parser->state = STATE_MONITOR;
- }
- else
- {
- g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_UNKNOWN_ELEMENT,
- "Invalid monitor logicalmonitor element '%s'", element_name);
- return;
- }
-
- return;
- }
-
- case STATE_LOGICAL_MONITOR_X:
- case STATE_LOGICAL_MONITOR_Y:
- case STATE_LOGICAL_MONITOR_SCALE:
- case STATE_LOGICAL_MONITOR_PRIMARY:
- case STATE_LOGICAL_MONITOR_PRESENTATION:
- {
- g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_UNKNOWN_ELEMENT,
- "Invalid logical monitor element '%s'", element_name);
- return;
- }
-
- case STATE_TRANSFORM:
- {
- if (g_str_equal (element_name, "rotation"))
- {
- parser->state = STATE_TRANSFORM_ROTATION;
- }
- else if (g_str_equal (element_name, "flipped"))
- {
- parser->state = STATE_TRANSFORM_FLIPPED;
- }
-
- return;
- }
-
- case STATE_TRANSFORM_ROTATION:
- case STATE_TRANSFORM_FLIPPED:
- {
- g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_UNKNOWN_ELEMENT,
- "Invalid transform element '%s'", element_name);
- return;
- }
-
- case STATE_MONITOR:
- {
- if (g_str_equal (element_name, "monitorspec"))
- {
- parser->current_monitor_spec = g_new0 (MetaMonitorSpec, 1);
- parser->monitor_spec_parent_state = STATE_MONITOR;
- parser->state = STATE_MONITOR_SPEC;
- }
- else if (g_str_equal (element_name, "mode"))
- {
- parser->current_monitor_mode_spec = g_new0 (MetaMonitorModeSpec, 1);
-
- parser->state = STATE_MONITOR_MODE;
- }
- else if (g_str_equal (element_name, "underscanning"))
- {
- parser->state = STATE_MONITOR_UNDERSCANNING;
- }
- else
- {
- g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_UNKNOWN_ELEMENT,
- "Invalid monitor element '%s'", element_name);
- return;
- }
-
- return;
- }
-
- case STATE_MONITOR_SPEC:
- {
- if (g_str_equal (element_name, "connector"))
- {
- parser->state = STATE_MONITOR_SPEC_CONNECTOR;
- }
- else if (g_str_equal (element_name, "vendor"))
- {
- parser->state = STATE_MONITOR_SPEC_VENDOR;
- }
- else if (g_str_equal (element_name, "product"))
- {
- parser->state = STATE_MONITOR_SPEC_PRODUCT;
- }
- else if (g_str_equal (element_name, "serial"))
- {
- parser->state = STATE_MONITOR_SPEC_SERIAL;
- }
- else
- {
- g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_UNKNOWN_ELEMENT,
- "Invalid monitor spec element '%s'", element_name);
- return;
- }
-
- return;
- }
-
- case STATE_MONITOR_SPEC_CONNECTOR:
- case STATE_MONITOR_SPEC_VENDOR:
- case STATE_MONITOR_SPEC_PRODUCT:
- case STATE_MONITOR_SPEC_SERIAL:
- {
- g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_UNKNOWN_ELEMENT,
- "Invalid monitor spec element '%s'", element_name);
- return;
- }
-
- case STATE_MONITOR_MODE:
- {
- if (g_str_equal (element_name, "width"))
- {
- parser->state = STATE_MONITOR_MODE_WIDTH;
- }
- else if (g_str_equal (element_name, "height"))
- {
- parser->state = STATE_MONITOR_MODE_HEIGHT;
- }
- else if (g_str_equal (element_name, "rate"))
- {
- parser->state = STATE_MONITOR_MODE_RATE;
- }
- else if (g_str_equal (element_name, "flag"))
- {
- parser->state = STATE_MONITOR_MODE_FLAG;
- }
- else
- {
- g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_UNKNOWN_ELEMENT,
- "Invalid mode element '%s'", element_name);
- return;
- }
-
- return;
- }
-
- case STATE_MONITOR_MODE_WIDTH:
- case STATE_MONITOR_MODE_HEIGHT:
- case STATE_MONITOR_MODE_RATE:
- case STATE_MONITOR_MODE_FLAG:
- {
- g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_UNKNOWN_ELEMENT,
- "Invalid mode sub element '%s'", element_name);
- return;
- }
-
- case STATE_MONITOR_UNDERSCANNING:
- {
- g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_UNKNOWN_ELEMENT,
- "Invalid element '%s' under underscanning", element_name);
- return;
- }
-
- case STATE_DISABLED:
- {
- if (!g_str_equal (element_name, "monitorspec"))
- {
- g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_UNKNOWN_ELEMENT,
- "Invalid element '%s' under disabled", element_name);
- return;
- }
-
- parser->current_monitor_spec = g_new0 (MetaMonitorSpec, 1);
- parser->monitor_spec_parent_state = STATE_DISABLED;
- parser->state = STATE_MONITOR_SPEC;
-
- return;
- }
- }
-}
-
-static gboolean
-derive_logical_monitor_layout (MetaLogicalMonitorConfig *logical_monitor_config,
- MetaLogicalMonitorLayoutMode layout_mode,
- GError **error)
-{
- MetaMonitorConfig *monitor_config;
- int mode_width, mode_height;
- int width = 0, height = 0;
- GList *l;
-
- monitor_config = logical_monitor_config->monitor_configs->data;
- mode_width = monitor_config->mode_spec->width;
- mode_height = monitor_config->mode_spec->height;
-
- for (l = logical_monitor_config->monitor_configs->next; l; l = l->next)
- {
- monitor_config = l->data;
-
- if (monitor_config->mode_spec->width != mode_width ||
- monitor_config->mode_spec->height != mode_height)
- {
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- "Monitors in logical monitor incompatible");
- return FALSE;
- }
- }
-
- if (meta_monitor_transform_is_rotated (logical_monitor_config->transform))
- {
- width = mode_height;
- height = mode_width;
- }
- else
- {
- width = mode_width;
- height = mode_height;
- }
-
- switch (layout_mode)
- {
- case META_LOGICAL_MONITOR_LAYOUT_MODE_LOGICAL:
- width = roundf (width / logical_monitor_config->scale);
- height = roundf (height / logical_monitor_config->scale);
- break;
- case META_LOGICAL_MONITOR_LAYOUT_MODE_PHYSICAL:
- break;
- }
-
- logical_monitor_config->layout.width = width;
- logical_monitor_config->layout.height = height;
-
- return TRUE;
-}
-
-static void
-finish_monitor_spec (ConfigParser *parser)
-{
- switch (parser->monitor_spec_parent_state)
- {
- case STATE_MONITOR:
- {
- parser->current_monitor_config->monitor_spec =
- parser->current_monitor_spec;
- parser->current_monitor_spec = NULL;
-
- return;
- }
- case STATE_DISABLED:
- {
- parser->current_disabled_monitor_specs =
- g_list_prepend (parser->current_disabled_monitor_specs,
- parser->current_monitor_spec);
- parser->current_monitor_spec = NULL;
-
- return;
- }
-
- default:
- g_assert_not_reached ();
- }
-}
-
-static void
-handle_end_element (GMarkupParseContext *context,
- const char *element_name,
- gpointer user_data,
- GError **error)
-{
- ConfigParser *parser = user_data;
-
- switch (parser->state)
- {
- case STATE_LOGICAL_MONITOR_X:
- case STATE_LOGICAL_MONITOR_Y:
- case STATE_LOGICAL_MONITOR_SCALE:
- case STATE_LOGICAL_MONITOR_PRIMARY:
- case STATE_LOGICAL_MONITOR_PRESENTATION:
- {
- parser->state = STATE_LOGICAL_MONITOR;
- return;
- }
-
- case STATE_TRANSFORM:
- {
- g_assert (g_str_equal (element_name, "transform"));
-
- parser->current_logical_monitor_config->transform =
- parser->current_transform;
- if (parser->current_transform_flipped)
- {
- parser->current_logical_monitor_config->transform +=
- META_MONITOR_TRANSFORM_FLIPPED;
- }
-
- parser->current_transform = META_MONITOR_TRANSFORM_NORMAL;
- parser->current_transform_flipped = FALSE;
-
- parser->state = STATE_LOGICAL_MONITOR;
- return;
- }
-
- case STATE_TRANSFORM_ROTATION:
- case STATE_TRANSFORM_FLIPPED:
- {
- parser->state = STATE_TRANSFORM;
- return;
- }
-
- case STATE_MONITOR_SPEC_CONNECTOR:
- case STATE_MONITOR_SPEC_VENDOR:
- case STATE_MONITOR_SPEC_PRODUCT:
- case STATE_MONITOR_SPEC_SERIAL:
- {
- parser->state = STATE_MONITOR_SPEC;
- return;
- }
-
- case STATE_MONITOR_SPEC:
- {
- g_assert (g_str_equal (element_name, "monitorspec"));
-
- if (!meta_verify_monitor_spec (parser->current_monitor_spec, error))
- return;
-
- finish_monitor_spec (parser);
-
- parser->state = parser->monitor_spec_parent_state;
- return;
- }
-
- case STATE_MONITOR_MODE_WIDTH:
- case STATE_MONITOR_MODE_HEIGHT:
- case STATE_MONITOR_MODE_RATE:
- case STATE_MONITOR_MODE_FLAG:
- {
- parser->state = STATE_MONITOR_MODE;
- return;
- }
-
- case STATE_MONITOR_MODE:
- {
- g_assert (g_str_equal (element_name, "mode"));
-
- if (!meta_verify_monitor_mode_spec (parser->current_monitor_mode_spec,
- error))
- return;
-
- parser->current_monitor_config->mode_spec =
- parser->current_monitor_mode_spec;
- parser->current_monitor_mode_spec = NULL;
-
- parser->state = STATE_MONITOR;
- return;
- }
-
- case STATE_MONITOR_UNDERSCANNING:
- {
- g_assert (g_str_equal (element_name, "underscanning"));
-
- parser->state = STATE_MONITOR;
- return;
- }
-
- case STATE_MONITOR:
- {
- MetaLogicalMonitorConfig *logical_monitor_config;
-
- g_assert (g_str_equal (element_name, "monitor"));
-
- if (!meta_verify_monitor_config (parser->current_monitor_config, error))
- return;
-
- logical_monitor_config = parser->current_logical_monitor_config;
-
- logical_monitor_config->monitor_configs =
- g_list_append (logical_monitor_config->monitor_configs,
- parser->current_monitor_config);
- parser->current_monitor_config = NULL;
-
- parser->state = STATE_LOGICAL_MONITOR;
- return;
- }
-
- case STATE_LOGICAL_MONITOR:
- {
- MetaLogicalMonitorConfig *logical_monitor_config =
- parser->current_logical_monitor_config;
-
- g_assert (g_str_equal (element_name, "logicalmonitor"));
-
- if (parser->current_was_migrated)
- logical_monitor_config->scale = -1;
- else if (logical_monitor_config->scale == 0)
- logical_monitor_config->scale = 1;
-
- parser->current_logical_monitor_configs =
- g_list_append (parser->current_logical_monitor_configs,
- logical_monitor_config);
- parser->current_logical_monitor_config = NULL;
-
- parser->state = STATE_CONFIGURATION;
- return;
- }
-
- case STATE_MIGRATED:
- {
- g_assert (g_str_equal (element_name, "migrated"));
-
- parser->state = STATE_CONFIGURATION;
- return;
- }
-
- case STATE_DISABLED:
- {
- g_assert (g_str_equal (element_name, "disabled"));
-
- parser->state = STATE_CONFIGURATION;
- return;
- }
-
- case STATE_CONFIGURATION:
- {
- MetaMonitorConfigStore *store = parser->config_store;
- MetaMonitorsConfig *config;
- GList *l;
- MetaLogicalMonitorLayoutMode layout_mode;
- MetaMonitorsConfigFlag config_flags = META_MONITORS_CONFIG_FLAG_NONE;
-
- g_assert (g_str_equal (element_name, "configuration"));
-
- if (parser->current_was_migrated)
- layout_mode = META_LOGICAL_MONITOR_LAYOUT_MODE_PHYSICAL;
- else
- layout_mode =
- meta_monitor_manager_get_default_layout_mode (store->monitor_manager);
-
- for (l = parser->current_logical_monitor_configs; l; l = l->next)
- {
- MetaLogicalMonitorConfig *logical_monitor_config = l->data;
-
- if (!derive_logical_monitor_layout (logical_monitor_config,
- layout_mode,
- error))
- return;
-
- if (!meta_verify_logical_monitor_config (logical_monitor_config,
- layout_mode,
- store->monitor_manager,
- error))
- return;
- }
-
- if (parser->current_was_migrated)
- config_flags |= META_MONITORS_CONFIG_FLAG_MIGRATED;
-
- config_flags |= parser->extra_config_flags;
-
- config =
- meta_monitors_config_new_full (parser->current_logical_monitor_configs,
- parser->current_disabled_monitor_specs,
- layout_mode,
- config_flags);
-
- parser->current_logical_monitor_configs = NULL;
- parser->current_disabled_monitor_specs = NULL;
-
- if (!meta_verify_monitors_config (config, store->monitor_manager,
- error))
- {
- g_object_unref (config);
- return;
- }
-
- g_hash_table_replace (parser->config_store->configs,
- config->key, config);
-
- parser->state = STATE_MONITORS;
- return;
- }
-
- case STATE_MONITORS:
- {
- g_assert (g_str_equal (element_name, "monitors"));
-
- parser->state = STATE_INITIAL;
- return;
- }
-
- case STATE_INITIAL:
- {
- g_assert_not_reached ();
- }
- }
-}
-
-static gboolean
-read_int (const char *text,
- gsize text_len,
- gint *out_value,
- GError **error)
-{
- char buf[64];
- int64_t value;
- char *end;
-
- strncpy (buf, text, text_len);
- buf[MIN (63, text_len)] = 0;
-
- value = g_ascii_strtoll (buf, &end, 10);
-
- if (*end || value < 0 || value > G_MAXINT16)
- {
- g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
- "Expected a number, got %s", buf);
- return FALSE;
- }
- else
- {
- *out_value = value;
- return TRUE;
- }
-}
-
-static gboolean
-read_float (const char *text,
- gsize text_len,
- float *out_value,
- GError **error)
-{
- char buf[64];
- float value;
- char *end;
-
- strncpy (buf, text, text_len);
- buf[MIN (63, text_len)] = 0;
-
- value = g_ascii_strtod (buf, &end);
-
- if (*end)
- {
- g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
- "Expected a number, got %s", buf);
- return FALSE;
- }
- else
- {
- *out_value = value;
- return TRUE;
- }
-}
-
-static gboolean
-read_bool (const char *text,
- gsize text_len,
- gboolean *out_value,
- GError **error)
-{
- if (strncmp (text, "no", text_len) == 0)
- {
- *out_value = FALSE;
- return TRUE;
- }
- else if (strncmp (text, "yes", text_len) == 0)
- {
- *out_value = TRUE;
- return TRUE;
- }
- else
- {
- g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
- "Invalid boolean value '%.*s'", (int) text_len, text);
- return FALSE;
- }
-}
-
-static gboolean
-is_all_whitespace (const char *text,
- gsize text_len)
-{
- gsize i;
-
- for (i = 0; i < text_len; i++)
- if (!g_ascii_isspace (text[i]))
- return FALSE;
-
- return TRUE;
-}
-
-static void
-handle_text (GMarkupParseContext *context,
- const gchar *text,
- gsize text_len,
- gpointer user_data,
- GError **error)
-{
- ConfigParser *parser = user_data;
-
- switch (parser->state)
- {
- case STATE_INITIAL:
- case STATE_MONITORS:
- case STATE_CONFIGURATION:
- case STATE_MIGRATED:
- case STATE_LOGICAL_MONITOR:
- case STATE_MONITOR:
- case STATE_MONITOR_SPEC:
- case STATE_MONITOR_MODE:
- case STATE_TRANSFORM:
- case STATE_DISABLED:
- {
- if (!is_all_whitespace (text, text_len))
- g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
- "Unexpected content at this point");
- return;
- }
-
- case STATE_MONITOR_SPEC_CONNECTOR:
- {
- parser->current_monitor_spec->connector = g_strndup (text, text_len);
- return;
- }
-
- case STATE_MONITOR_SPEC_VENDOR:
- {
- parser->current_monitor_spec->vendor = g_strndup (text, text_len);
- return;
- }
-
- case STATE_MONITOR_SPEC_PRODUCT:
- {
- parser->current_monitor_spec->product = g_strndup (text, text_len);
- return;
- }
-
- case STATE_MONITOR_SPEC_SERIAL:
- {
- parser->current_monitor_spec->serial = g_strndup (text, text_len);
- return;
- }
-
- case STATE_LOGICAL_MONITOR_X:
- {
- read_int (text, text_len,
- &parser->current_logical_monitor_config->layout.x, error);
- return;
- }
-
- case STATE_LOGICAL_MONITOR_Y:
- {
- read_int (text, text_len,
- &parser->current_logical_monitor_config->layout.y, error);
- return;
- }
-
- case STATE_LOGICAL_MONITOR_SCALE:
- {
- if (!read_float (text, text_len,
- &parser->current_logical_monitor_config->scale, error))
- return;
-
- if (parser->current_logical_monitor_config->scale <= 0.0)
- {
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- "Logical monitor scale '%g' invalid",
- parser->current_logical_monitor_config->scale);
- return;
- }
-
- return;
- }
-
- case STATE_LOGICAL_MONITOR_PRIMARY:
- {
- read_bool (text, text_len,
- &parser->current_logical_monitor_config->is_primary,
- error);
- return;
- }
-
- case STATE_LOGICAL_MONITOR_PRESENTATION:
- {
- read_bool (text, text_len,
- &parser->current_logical_monitor_config->is_presentation,
- error);
- return;
- }
-
- case STATE_TRANSFORM_ROTATION:
- {
- if (strncmp (text, "normal", text_len) == 0)
- parser->current_transform = META_MONITOR_TRANSFORM_NORMAL;
- else if (strncmp (text, "left", text_len) == 0)
- parser->current_transform = META_MONITOR_TRANSFORM_90;
- else if (strncmp (text, "upside_down", text_len) == 0)
- parser->current_transform = META_MONITOR_TRANSFORM_180;
- else if (strncmp (text, "right", text_len) == 0)
- parser->current_transform = META_MONITOR_TRANSFORM_270;
- else
- g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
- "Invalid rotation type %.*s", (int)text_len, text);
-
- return;
- }
-
- case STATE_TRANSFORM_FLIPPED:
- {
- read_bool (text, text_len,
- &parser->current_transform_flipped,
- error);
- return;
- }
-
- case STATE_MONITOR_MODE_WIDTH:
- {
- read_int (text, text_len,
- &parser->current_monitor_mode_spec->width,
- error);
- return;
- }
-
- case STATE_MONITOR_MODE_HEIGHT:
- {
- read_int (text, text_len,
- &parser->current_monitor_mode_spec->height,
- error);
- return;
- }
-
- case STATE_MONITOR_MODE_RATE:
- {
- read_float (text, text_len,
- &parser->current_monitor_mode_spec->refresh_rate,
- error);
- return;
- }
-
- case STATE_MONITOR_MODE_FLAG:
- {
- if (strncmp (text, "interlace", text_len) == 0)
- {
- parser->current_monitor_mode_spec->flags |=
- META_CRTC_MODE_FLAG_INTERLACE;
- }
- else
- {
- g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
- "Invalid mode flag %.*s", (int) text_len, text);
- }
-
- return;
- }
-
- case STATE_MONITOR_UNDERSCANNING:
- {
- read_bool (text, text_len,
- &parser->current_monitor_config->enable_underscanning,
- error);
- return;
- }
- }
-}
-
-static const GMarkupParser config_parser = {
- .start_element = handle_start_element,
- .end_element = handle_end_element,
- .text = handle_text
-};
-
-static gboolean
-read_config_file (MetaMonitorConfigStore *config_store,
- GFile *file,
- MetaMonitorsConfigFlag extra_config_flags,
- GError **error)
-{
- char *buffer;
- gsize size;
- ConfigParser parser;
- GMarkupParseContext *parse_context;
-
- if (!g_file_load_contents (file, NULL, &buffer, &size, NULL, error))
- return FALSE;
-
- parser = (ConfigParser) {
- .state = STATE_INITIAL,
- .config_store = config_store,
- .extra_config_flags = extra_config_flags,
- };
-
- parse_context = g_markup_parse_context_new (&config_parser,
- G_MARKUP_TREAT_CDATA_AS_TEXT |
- G_MARKUP_PREFIX_ERROR_POSITION,
- &parser, NULL);
- if (!g_markup_parse_context_parse (parse_context, buffer, size, error))
- {
- g_list_free_full (parser.current_logical_monitor_configs,
- (GDestroyNotify) meta_logical_monitor_config_free);
- g_clear_pointer (&parser.current_monitor_spec,
- meta_monitor_spec_free);
- g_free (parser.current_monitor_mode_spec);
- g_clear_pointer (&parser.current_monitor_config,
- meta_monitor_config_free);
- g_clear_pointer (&parser.current_logical_monitor_config,
- meta_logical_monitor_config_free);
- return FALSE;
- }
-
- g_markup_parse_context_free (parse_context);
- g_free (buffer);
-
- return TRUE;
-}
-
-MetaMonitorsConfig *
-meta_monitor_config_store_lookup (MetaMonitorConfigStore *config_store,
- MetaMonitorsConfigKey *key)
-{
- return META_MONITORS_CONFIG (g_hash_table_lookup (config_store->configs,
- key));
-}
-
-static void
-append_monitor_spec (GString *buffer,
- MetaMonitorSpec *monitor_spec,
- const char *indentation)
-{
- char *escaped;
-
- g_string_append_printf (buffer, "%s<monitorspec>\n", indentation);
-
- escaped = g_markup_escape_text (monitor_spec->connector, -1);
- g_string_append_printf (buffer, "%s <connector>%s</connector>\n",
- indentation,
- escaped);
- g_free (escaped);
-
- escaped = g_markup_escape_text (monitor_spec->vendor, -1);
- g_string_append_printf (buffer, "%s <vendor>%s</vendor>\n",
- indentation,
- escaped);
- g_free (escaped);
-
- escaped = g_markup_escape_text (monitor_spec->product, -1);
- g_string_append_printf (buffer, "%s <product>%s</product>\n",
- indentation,
- escaped);
- g_free (escaped);
-
- escaped = g_markup_escape_text (monitor_spec->serial, -1);
- g_string_append_printf (buffer, "%s <serial>%s</serial>\n",
- indentation,
- escaped);
- g_free (escaped);
-
- g_string_append_printf (buffer, "%s</monitorspec>\n", indentation);
-}
-
-static void
-append_monitors (GString *buffer,
- GList *monitor_configs)
-{
- GList *l;
-
- for (l = monitor_configs; l; l = l->next)
- {
- MetaMonitorConfig *monitor_config = l->data;
- char rate_str[G_ASCII_DTOSTR_BUF_SIZE];
-
- g_ascii_dtostr (rate_str, sizeof (rate_str),
- monitor_config->mode_spec->refresh_rate);
-
- g_string_append (buffer, " <monitor>\n");
- append_monitor_spec (buffer, monitor_config->monitor_spec, " ");
- g_string_append (buffer, " <mode>\n");
- g_string_append_printf (buffer, " <width>%d</width>\n",
- monitor_config->mode_spec->width);
- g_string_append_printf (buffer, " <height>%d</height>\n",
- monitor_config->mode_spec->height);
- g_string_append_printf (buffer, " <rate>%s</rate>\n",
- rate_str);
- if (monitor_config->mode_spec->flags & META_CRTC_MODE_FLAG_INTERLACE)
- g_string_append_printf (buffer, " <flag>interlace</flag>\n");
- g_string_append (buffer, " </mode>\n");
- if (monitor_config->enable_underscanning)
- g_string_append (buffer, " <underscanning>yes</underscanning>\n");
- g_string_append (buffer, " </monitor>\n");
- }
-}
-
-static const char *
-bool_to_string (gboolean value)
-{
- return value ? "yes" : "no";
-}
-
-static void
-append_transform (GString *buffer,
- MetaMonitorTransform transform)
-{
- const char *rotation = NULL;
- gboolean flipped = FALSE;
-
- switch (transform)
- {
- case META_MONITOR_TRANSFORM_NORMAL:
- return;
- case META_MONITOR_TRANSFORM_90:
- rotation = "left";
- break;
- case META_MONITOR_TRANSFORM_180:
- rotation = "upside_down";
- break;
- case META_MONITOR_TRANSFORM_270:
- rotation = "right";
- break;
- case META_MONITOR_TRANSFORM_FLIPPED:
- rotation = "normal";
- flipped = TRUE;
- break;
- case META_MONITOR_TRANSFORM_FLIPPED_90:
- rotation = "left";
- flipped = TRUE;
- break;
- case META_MONITOR_TRANSFORM_FLIPPED_180:
- rotation = "upside_down";
- flipped = TRUE;
- break;
- case META_MONITOR_TRANSFORM_FLIPPED_270:
- rotation = "right";
- flipped = TRUE;
- break;
- }
-
- g_string_append (buffer, " <transform>\n");
- g_string_append_printf (buffer, " <rotation>%s</rotation>\n",
- rotation);
- g_string_append_printf (buffer, " <flipped>%s</flipped>\n",
- bool_to_string (flipped));
- g_string_append (buffer, " </transform>\n");
-}
-
-static void
-append_logical_monitor_xml (GString *buffer,
- MetaMonitorsConfig *config,
- MetaLogicalMonitorConfig *logical_monitor_config)
-{
- char scale_str[G_ASCII_DTOSTR_BUF_SIZE];
-
- g_string_append (buffer, " <logicalmonitor>\n");
- g_string_append_printf (buffer, " <x>%d</x>\n",
- logical_monitor_config->layout.x);
- g_string_append_printf (buffer, " <y>%d</y>\n",
- logical_monitor_config->layout.y);
- g_ascii_dtostr (scale_str, G_ASCII_DTOSTR_BUF_SIZE,
- logical_monitor_config->scale);
- if ((config->flags & META_MONITORS_CONFIG_FLAG_MIGRATED) == 0)
- g_string_append_printf (buffer, " <scale>%s</scale>\n",
- scale_str);
- if (logical_monitor_config->is_primary)
- g_string_append (buffer, " <primary>yes</primary>\n");
- if (logical_monitor_config->is_presentation)
- g_string_append (buffer, " <presentation>yes</presentation>\n");
- append_transform (buffer, logical_monitor_config->transform);
- append_monitors (buffer, logical_monitor_config->monitor_configs);
- g_string_append (buffer, " </logicalmonitor>\n");
-}
-
-static GString *
-generate_config_xml (MetaMonitorConfigStore *config_store)
-{
- GString *buffer;
- GHashTableIter iter;
- MetaMonitorsConfig *config;
-
- buffer = g_string_new ("");
- g_string_append_printf (buffer, "<monitors version=\"%d\">\n",
- MONITORS_CONFIG_XML_FORMAT_VERSION);
-
- g_hash_table_iter_init (&iter, config_store->configs);
- while (g_hash_table_iter_next (&iter, NULL, (gpointer *) &config))
- {
- GList *l;
-
- if (config->flags & META_MONITORS_CONFIG_FLAG_SYSTEM_CONFIG)
- continue;
-
- g_string_append (buffer, " <configuration>\n");
-
- if (config->flags & META_MONITORS_CONFIG_FLAG_MIGRATED)
- g_string_append (buffer, " <migrated/>\n");
-
- for (l = config->logical_monitor_configs; l; l = l->next)
- {
- MetaLogicalMonitorConfig *logical_monitor_config = l->data;
-
- append_logical_monitor_xml (buffer, config, logical_monitor_config);
- }
-
- if (config->disabled_monitor_specs)
- {
- g_string_append (buffer, " <disabled>\n");
- for (l = config->disabled_monitor_specs; l; l = l->next)
- {
- MetaMonitorSpec *monitor_spec = l->data;
-
- append_monitor_spec (buffer, monitor_spec, " ");
- }
- g_string_append (buffer, " </disabled>\n");
- }
-
- g_string_append (buffer, " </configuration>\n");
- }
-
- g_string_append (buffer, "</monitors>\n");
-
- return buffer;
-}
-
-typedef struct _SaveData
-{
- MetaMonitorConfigStore *config_store;
- GString *buffer;
-} SaveData;
-
-static void
-saved_cb (GObject *object,
- GAsyncResult *result,
- gpointer user_data)
-{
- SaveData *data = user_data;
- GError *error = NULL;
-
- if (!g_file_replace_contents_finish (G_FILE (object), result, NULL, &error))
- {
- if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
- {
- g_warning ("Saving monitor configuration failed: %s", error->message);
- g_clear_object (&data->config_store->save_cancellable);
- }
-
- g_error_free (error);
- }
- else
- {
- g_clear_object (&data->config_store->save_cancellable);
- }
-
- g_clear_object (&data->config_store);
- g_string_free (data->buffer, TRUE);
- g_free (data);
-}
-
-static void
-meta_monitor_config_store_save_sync (MetaMonitorConfigStore *config_store)
-{
- GError *error = NULL;
- GFile *file;
- GString *buffer;
-
- if (config_store->custom_write_file)
- file = config_store->custom_write_file;
- else
- file = config_store->user_file;
-
- buffer = generate_config_xml (config_store);
-
- if (!g_file_replace_contents (file,
- buffer->str, buffer->len,
- NULL,
- FALSE,
- G_FILE_CREATE_REPLACE_DESTINATION,
- NULL,
- NULL,
- &error))
- {
- g_warning ("Saving monitor configuration failed: %s",
- error->message);
- g_error_free (error);
- }
-
- g_string_free (buffer, TRUE);
-}
-
-static void
-meta_monitor_config_store_save (MetaMonitorConfigStore *config_store)
-{
- GString *buffer;
- SaveData *data;
-
- if (config_store->save_cancellable)
- {
- g_cancellable_cancel (config_store->save_cancellable);
- g_clear_object (&config_store->save_cancellable);
- }
-
- /*
- * Custom write file is only ever used by the test suite, and the test suite
- * will want to have be able to read back the content immediately, so for
- * custom write files, do the content replacement synchronously.
- */
- if (config_store->custom_write_file)
- {
- meta_monitor_config_store_save_sync (config_store);
- return;
- }
-
- config_store->save_cancellable = g_cancellable_new ();
-
- buffer = generate_config_xml (config_store);
-
- data = g_new0 (SaveData, 1);
- *data = (SaveData) {
- .config_store = g_object_ref (config_store),
- .buffer = buffer
- };
-
- g_file_replace_contents_async (config_store->user_file,
- buffer->str, buffer->len,
- NULL,
- TRUE,
- G_FILE_CREATE_REPLACE_DESTINATION,
- config_store->save_cancellable,
- saved_cb, data);
-}
-
-static void
-maybe_save_configs (MetaMonitorConfigStore *config_store)
-{
- /*
- * If a custom file is used, it means we are run by the test suite. When this
- * is done, avoid replacing the user configuration file with test data,
- * except if a custom write file is set as well.
- */
- if (!config_store->custom_read_file || config_store->custom_write_file)
- meta_monitor_config_store_save (config_store);
-}
-
-static gboolean
-is_system_config (MetaMonitorsConfig *config)
-{
- return !!(config->flags & META_MONITORS_CONFIG_FLAG_SYSTEM_CONFIG);
-}
-
-void
-meta_monitor_config_store_add (MetaMonitorConfigStore *config_store,
- MetaMonitorsConfig *config)
-{
- g_hash_table_replace (config_store->configs,
- config->key, g_object_ref (config));
-
- if (!is_system_config (config))
- maybe_save_configs (config_store);
-}
-
-void
-meta_monitor_config_store_remove (MetaMonitorConfigStore *config_store,
- MetaMonitorsConfig *config)
-{
- g_hash_table_remove (config_store->configs, config->key);
-
- if (!is_system_config (config))
- maybe_save_configs (config_store);
-}
-
-gboolean
-meta_monitor_config_store_set_custom (MetaMonitorConfigStore *config_store,
- const char *read_path,
- const char *write_path,
- GError **error)
-{
- g_clear_object (&config_store->custom_read_file);
- g_clear_object (&config_store->custom_write_file);
- g_hash_table_remove_all (config_store->configs);
-
- config_store->custom_read_file = g_file_new_for_path (read_path);
- if (write_path)
- config_store->custom_write_file = g_file_new_for_path (write_path);
-
- return read_config_file (config_store,
- config_store->custom_read_file,
- META_MONITORS_CONFIG_FLAG_NONE,
- error);
-}
-
-int
-meta_monitor_config_store_get_config_count (MetaMonitorConfigStore *config_store)
-{
- return (int) g_hash_table_size (config_store->configs);
-}
-
-MetaMonitorManager *
-meta_monitor_config_store_get_monitor_manager (MetaMonitorConfigStore *config_store)
-{
- return config_store->monitor_manager;
-}
-
-MetaMonitorConfigStore *
-meta_monitor_config_store_new (MetaMonitorManager *monitor_manager)
-{
- return g_object_new (META_TYPE_MONITOR_CONFIG_STORE,
- "monitor-manager", monitor_manager,
- NULL);
-}
-
-static void
-meta_monitor_config_store_constructed (GObject *object)
-{
- MetaMonitorConfigStore *config_store = META_MONITOR_CONFIG_STORE (object);
- const char * const *system_dirs;
- char *user_file_path;
- GError *error = NULL;
-
- for (system_dirs = g_get_system_config_dirs ();
- system_dirs && *system_dirs;
- system_dirs++)
- {
- g_autofree char *system_file_path = NULL;
-
- system_file_path = g_build_filename (*system_dirs, "monitors.xml", NULL);
- if (g_file_test (system_file_path, G_FILE_TEST_EXISTS))
- {
- g_autoptr (GFile) system_file = NULL;
-
- system_file = g_file_new_for_path (system_file_path);
- if (!read_config_file (config_store,
- system_file,
- META_MONITORS_CONFIG_FLAG_SYSTEM_CONFIG,
- &error))
- {
- if (g_error_matches (error,
- META_MONITOR_CONFIG_STORE_ERROR,
- META_MONITOR_CONFIG_STORE_ERROR_NEEDS_MIGRATION))
- g_warning ("System monitor configuration file (%s) is "
- "incompatible; ask your administrator to migrate "
- "the system monitor configuration.",
- system_file_path);
- else
- g_warning ("Failed to read monitors config file '%s': %s",
- system_file_path, error->message);
- g_clear_error (&error);
- }
- }
- }
-
- user_file_path = g_build_filename (g_get_user_config_dir (),
- "monitors.xml",
- NULL);
- config_store->user_file = g_file_new_for_path (user_file_path);
-
- if (g_file_test (user_file_path, G_FILE_TEST_EXISTS))
- {
- if (!read_config_file (config_store,
- config_store->user_file,
- META_MONITORS_CONFIG_FLAG_NONE,
- &error))
- {
- if (error->domain == META_MONITOR_CONFIG_STORE_ERROR &&
- error->code == META_MONITOR_CONFIG_STORE_ERROR_NEEDS_MIGRATION)
- {
- g_clear_error (&error);
- if (!meta_migrate_old_user_monitors_config (config_store, &error))
- {
- g_warning ("Failed to migrate old monitors config file: %s",
- error->message);
- g_error_free (error);
- }
- }
- else
- {
- g_warning ("Failed to read monitors config file '%s': %s",
- user_file_path, error->message);
- g_error_free (error);
- }
- }
- }
-
- g_free (user_file_path);
-
- G_OBJECT_CLASS (meta_monitor_config_store_parent_class)->constructed (object);
-}
-
-static void
-meta_monitor_config_store_dispose (GObject *object)
-{
- MetaMonitorConfigStore *config_store = META_MONITOR_CONFIG_STORE (object);
-
- if (config_store->save_cancellable)
- {
- g_cancellable_cancel (config_store->save_cancellable);
- g_clear_object (&config_store->save_cancellable);
-
- meta_monitor_config_store_save_sync (config_store);
- }
-
- g_clear_pointer (&config_store->configs, g_hash_table_destroy);
-
- g_clear_object (&config_store->user_file);
- g_clear_object (&config_store->custom_read_file);
- g_clear_object (&config_store->custom_write_file);
-
- G_OBJECT_CLASS (meta_monitor_config_store_parent_class)->dispose (object);
-}
-
-static void
-meta_monitor_config_store_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- MetaMonitorConfigStore *config_store = META_MONITOR_CONFIG_STORE (object);
-
- switch (prop_id)
- {
- case PROP_MONITOR_MANAGER:
- g_value_set_object (value, &config_store->monitor_manager);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- }
-}
-
-static void
-meta_monitor_config_store_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- MetaMonitorConfigStore *config_store = META_MONITOR_CONFIG_STORE (object);
-
- switch (prop_id)
- {
- case PROP_MONITOR_MANAGER:
- config_store->monitor_manager = g_value_get_object (value);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- }
-}
-
-static void
-meta_monitor_config_store_init (MetaMonitorConfigStore *config_store)
-{
- config_store->configs = g_hash_table_new_full (meta_monitors_config_key_hash,
- meta_monitors_config_key_equal,
- NULL,
- g_object_unref);
-}
-
-static void
-meta_monitor_config_store_class_init (MetaMonitorConfigStoreClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- object_class->constructed = meta_monitor_config_store_constructed;
- object_class->dispose = meta_monitor_config_store_dispose;
- object_class->get_property = meta_monitor_config_store_get_property;
- object_class->set_property = meta_monitor_config_store_set_property;
-
- obj_props[PROP_MONITOR_MANAGER] =
- g_param_spec_object ("monitor-manager",
- "MetaMonitorManager",
- "MetaMonitorManager",
- META_TYPE_MONITOR_MANAGER,
- G_PARAM_READWRITE |
- G_PARAM_STATIC_STRINGS |
- G_PARAM_CONSTRUCT_ONLY);
-
- g_object_class_install_properties (object_class, PROP_LAST, obj_props);
-}
diff --git a/src/backends/meta-monitor-config-store.h b/src/backends/meta-monitor-config-store.h
deleted file mode 100644
index 92c24ecaa..000000000
--- a/src/backends/meta-monitor-config-store.h
+++ /dev/null
@@ -1,60 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2017 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-
-#ifndef META_MONITOR_CONFIG_STORE_H
-#define META_MONITOR_CONFIG_STORE_H
-
-#include <glib-object.h>
-
-#include "backends/meta-monitor-config-manager.h"
-
-#define META_TYPE_MONITOR_CONFIG_STORE (meta_monitor_config_store_get_type ())
-G_DECLARE_FINAL_TYPE (MetaMonitorConfigStore, meta_monitor_config_store,
- META, MONITOR_CONFIG_STORE, GObject)
-
-META_EXPORT_TEST
-MetaMonitorConfigStore * meta_monitor_config_store_new (MetaMonitorManager *monitor_manager);
-
-META_EXPORT_TEST
-MetaMonitorsConfig * meta_monitor_config_store_lookup (MetaMonitorConfigStore *config_store,
- MetaMonitorsConfigKey *key);
-
-META_EXPORT_TEST
-void meta_monitor_config_store_add (MetaMonitorConfigStore *config_store,
- MetaMonitorsConfig *config);
-
-META_EXPORT_TEST
-void meta_monitor_config_store_remove (MetaMonitorConfigStore *config_store,
- MetaMonitorsConfig *config);
-
-META_EXPORT_TEST
-gboolean meta_monitor_config_store_set_custom (MetaMonitorConfigStore *config_store,
- const char *read_path,
- const char *write_path,
- GError **error);
-
-META_EXPORT_TEST
-int meta_monitor_config_store_get_config_count (MetaMonitorConfigStore *config_store);
-
-META_EXPORT_TEST
-MetaMonitorManager * meta_monitor_config_store_get_monitor_manager (MetaMonitorConfigStore *config_store);
-
-#endif /* META_MONITOR_CONFIG_STORE_H */
diff --git a/src/backends/meta-monitor-manager-dummy.c b/src/backends/meta-monitor-manager-dummy.c
deleted file mode 100644
index d08fb022b..000000000
--- a/src/backends/meta-monitor-manager-dummy.c
+++ /dev/null
@@ -1,816 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2001, 2002 Havoc Pennington
- * Copyright (C) 2002, 2003 Red Hat Inc.
- * Some ICCCM manager selection code derived from fvwm2,
- * Copyright (C) 2001 Dominik Vogt, Matthias Clasen, and fvwm2 team
- * Copyright (C) 2003 Rob Adams
- * Copyright (C) 2004-2006 Elijah Newren
- * Copyright (C) 2013 Red Hat Inc.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "config.h"
-
-#include "backends/meta-monitor-manager-dummy.h"
-
-#include <stdlib.h>
-
-#include "backends/meta-backend-private.h"
-#include "backends/meta-crtc.h"
-#include "backends/meta-monitor.h"
-#include "backends/meta-monitor-config-manager.h"
-#include "backends/meta-output.h"
-#include "meta/main.h"
-#include "meta/util.h"
-
-#define MAX_MONITORS 5
-#define MAX_OUTPUTS (MAX_MONITORS * 2)
-#define MAX_CRTCS (MAX_MONITORS * 2)
-#define MAX_MODES (MAX_MONITORS * 4)
-
-struct _MetaMonitorManagerDummy
-{
- MetaMonitorManager parent_instance;
-
- gboolean is_transform_handled;
-};
-
-struct _MetaMonitorManagerDummyClass
-{
- MetaMonitorManagerClass parent_class;
-};
-
-struct _MetaOutputDummy
-{
- MetaOutput parent;
-
- float scale;
-};
-
-struct _MetaCrtcDummy
-{
- MetaCrtc parent;
-};
-
-G_DEFINE_TYPE (MetaOutputDummy, meta_output_dummy, META_TYPE_OUTPUT)
-G_DEFINE_TYPE (MetaCrtcDummy, meta_crtc_dummy, META_TYPE_CRTC)
-G_DEFINE_TYPE (MetaMonitorManagerDummy, meta_monitor_manager_dummy, META_TYPE_MONITOR_MANAGER);
-
-struct _MetaGpuDummy
-{
- MetaGpu parent;
-};
-
-G_DEFINE_TYPE (MetaGpuDummy, meta_gpu_dummy, META_TYPE_GPU)
-
-typedef struct _CrtcModeSpec
-{
- int width;
- int height;
- float refresh_rate;
-} CrtcModeSpec;
-G_DEFINE_AUTOPTR_CLEANUP_FUNC(CrtcModeSpec, g_free);
-
-static MetaCrtcMode *
-create_mode (CrtcModeSpec *spec,
- long mode_id)
-{
- g_autoptr (MetaCrtcModeInfo) crtc_mode_info = NULL;
-
- crtc_mode_info = meta_crtc_mode_info_new ();
- crtc_mode_info->width = spec->width;
- crtc_mode_info->height = spec->height;
- crtc_mode_info->refresh_rate = spec->refresh_rate;
-
- return g_object_new (META_TYPE_CRTC_MODE,
- "id", (uint64_t) mode_id,
- "info", crtc_mode_info,
- NULL);
-}
-
-static MetaGpu *
-get_gpu (MetaMonitorManager *manager)
-{
- MetaBackend *backend = meta_monitor_manager_get_backend (manager);
-
- return META_GPU (meta_backend_get_gpus (backend)->data);
-}
-
-static void
-append_monitor (MetaMonitorManager *manager,
- GList **modes,
- GList **crtcs,
- GList **outputs,
- float scale)
-{
- MetaGpu *gpu = get_gpu (manager);
- CrtcModeSpec default_specs[] = {
- {
- .width = 800,
- .height = 600,
- .refresh_rate = 60.0
- },
- {
- .width = 1024,
- .height = 768,
- .refresh_rate = 60.0
- },
- {
- .width = 1440,
- .height = 900,
- .refresh_rate = 60.0
- },
- {
- .width = 1600,
- .height = 920,
- .refresh_rate = 60.0
- },
- };
- g_autolist (CrtcModeSpec) mode_specs = NULL;
- unsigned int n_mode_specs = 0;
- GList *new_modes = NULL;
- MetaCrtc *crtc;
- MetaOutputDummy *output_dummy;
- MetaOutput *output;
- unsigned int i;
- unsigned int number;
- g_autoptr (MetaOutputInfo) output_info = NULL;
- const char *mode_specs_str;
- GList *l;
-
- mode_specs_str = getenv ("MUTTER_DEBUG_DUMMY_MODE_SPECS");
- if (mode_specs_str && *mode_specs_str != '\0')
- {
- g_auto (GStrv) specs = g_strsplit (mode_specs_str, ":", -1);
- for (i = 0; specs[i]; ++i)
- {
- int width, height;
- float refresh_rate = 60.0;
-
- if (sscanf (specs[i], "%dx%d@%f",
- &width, &height, &refresh_rate) == 3 ||
- sscanf (specs[i], "%dx%d",
- &width, &height) == 2)
- {
- CrtcModeSpec *spec;
-
- spec = g_new0 (CrtcModeSpec, 1);
- spec->width = width;
- spec->height = height;
- spec->refresh_rate = refresh_rate;
- mode_specs = g_list_prepend (mode_specs, spec);
- }
- }
- }
- else
- {
- for (i = 0; i < G_N_ELEMENTS (default_specs); i++)
- {
- CrtcModeSpec *spec;
-
- spec = g_memdup2 (&default_specs[i], sizeof (CrtcModeSpec));
- mode_specs = g_list_prepend (mode_specs, spec);
- }
- }
-
- if (!mode_specs)
- {
- g_warning ("Cannot create dummy output: No valid mode specs.");
- meta_exit (META_EXIT_ERROR);
- }
-
- for (l = mode_specs; l; l = l->next)
- {
- CrtcModeSpec *spec = l->data;
- long mode_id;
- MetaCrtcMode *mode;
-
- mode_id = g_list_length (*modes) + n_mode_specs + 1;
- mode = create_mode (spec, mode_id);
-
- new_modes = g_list_append (new_modes, mode);
- n_mode_specs++;
- }
- *modes = g_list_concat (*modes, new_modes);
-
- crtc = g_object_new (META_TYPE_CRTC_DUMMY,
- "id", (uint64_t) g_list_length (*crtcs) + 1,
- "gpu", gpu,
- NULL);
- *crtcs = g_list_append (*crtcs, crtc);
-
- number = g_list_length (*outputs) + 1;
-
- output_info = meta_output_info_new ();
- output_info->name = g_strdup_printf ("LVDS%d", number);
- output_info->vendor = g_strdup ("MetaProducts Inc.");
- output_info->product = g_strdup ("MetaMonitor");
- output_info->serial = g_strdup_printf ("0xC0FFEE-%d", number);
- output_info->width_mm = 222;
- output_info->height_mm = 125;
- output_info->subpixel_order = COGL_SUBPIXEL_ORDER_UNKNOWN;
- output_info->preferred_mode = g_list_last (*modes)->data;
- output_info->n_possible_clones = 0;
- output_info->connector_type = META_CONNECTOR_TYPE_LVDS;
-
- output_info->modes = g_new0 (MetaCrtcMode *, n_mode_specs);
- for (l = new_modes, i = 0; l; l = l->next, i++)
- {
- MetaCrtcMode *mode = l->data;
-
- output_info->modes[i] = mode;
- }
- output_info->n_modes = n_mode_specs;
- output_info->possible_crtcs = g_new0 (MetaCrtc *, 1);
- output_info->possible_crtcs[0] = g_list_last (*crtcs)->data;
- output_info->n_possible_crtcs = 1;
-
- output = g_object_new (META_TYPE_OUTPUT_DUMMY,
- "id", (uint64_t) number,
- "gpu", gpu,
- "info", output_info,
- NULL);
- output_dummy = META_OUTPUT_DUMMY (output);
- output_dummy->scale = scale;
-
- *outputs = g_list_append (*outputs, output);
-}
-
-static void
-append_tiled_monitor (MetaMonitorManager *manager,
- GList **modes,
- GList **crtcs,
- GList **outputs,
- int scale)
-{
- MetaGpu *gpu = get_gpu (manager);
- CrtcModeSpec mode_specs[] = {
- {
- .width = 800,
- .height = 600,
- .refresh_rate = 60.0
- },
- {
- .width = 512,
- .height = 768,
- .refresh_rate = 60.0
- }
- };
- unsigned int n_tiles = 2;
- GList *new_modes = NULL;
- GList *new_crtcs = NULL;
- MetaOutput *output;
- unsigned int i;
- uint32_t tile_group_id;
-
- for (i = 0; i < G_N_ELEMENTS (mode_specs); i++)
- {
- long mode_id;
- MetaCrtcMode *mode;
-
- mode_id = g_list_length (*modes) + i + 1;
- mode = create_mode (&mode_specs[i], mode_id);
-
- new_modes = g_list_append (new_modes, mode);
- }
- *modes = g_list_concat (*modes, new_modes);
-
- for (i = 0; i < n_tiles; i++)
- {
- MetaCrtc *crtc;
-
- crtc = g_object_new (META_TYPE_CRTC_DUMMY,
- "id", (uint64_t) g_list_length (*crtcs) + i + 1,
- "gpu", gpu,
- NULL);
- new_crtcs = g_list_append (new_crtcs, crtc);
- }
- *crtcs = g_list_concat (*crtcs, new_crtcs);
-
- tile_group_id = g_list_length (*outputs) + 1;
- for (i = 0; i < n_tiles; i++)
- {
- MetaOutputDummy *output_dummy;
- MetaCrtcMode *preferred_mode;
- const MetaCrtcModeInfo *preferred_mode_info;
- unsigned int j;
- unsigned int number;
- g_autoptr (MetaOutputInfo) output_info = NULL;
- GList *l;
-
- /* Arbitrary ID unique for this output */
- number = g_list_length (*outputs) + 1;
-
- preferred_mode = g_list_last (*modes)->data;
- preferred_mode_info = meta_crtc_mode_get_info (preferred_mode);
-
- output_info = meta_output_info_new ();
-
- output_info->name = g_strdup_printf ("LVDS%d", number);
- output_info->vendor = g_strdup ("MetaProducts Inc.");
- output_info->product = g_strdup ("MetaMonitor");
- output_info->serial = g_strdup_printf ("0xC0FFEE-%d", number);
- output_info->suggested_x = -1;
- output_info->suggested_y = -1;
- output_info->width_mm = 222;
- output_info->height_mm = 125;
- output_info->subpixel_order = COGL_SUBPIXEL_ORDER_UNKNOWN;
- output_info->preferred_mode = preferred_mode;
- output_info->n_possible_clones = 0;
- output_info->connector_type = META_CONNECTOR_TYPE_LVDS;
- output_info->tile_info = (MetaTileInfo) {
- .group_id = tile_group_id,
- .max_h_tiles = n_tiles,
- .max_v_tiles = 1,
- .loc_h_tile = i,
- .loc_v_tile = 0,
- .tile_w = preferred_mode_info->width,
- .tile_h = preferred_mode_info->height
- },
-
- output_info->modes = g_new0 (MetaCrtcMode *, G_N_ELEMENTS (mode_specs));
- for (l = new_modes, j = 0; l; l = l->next, j++)
- {
- MetaCrtcMode *mode = l->data;
-
- output_info->modes[j] = mode;
- }
- output_info->n_modes = G_N_ELEMENTS (mode_specs);
-
- output_info->possible_crtcs = g_new0 (MetaCrtc *, n_tiles);
- for (l = new_crtcs, j = 0; l; l = l->next, j++)
- {
- MetaCrtc *crtc = l->data;
-
- output_info->possible_crtcs[j] = crtc;
- }
- output_info->n_possible_crtcs = n_tiles;
-
- output = g_object_new (META_TYPE_OUTPUT_DUMMY,
- "id", (uint64_t) number,
- "gpu", gpu,
- "info", output_info,
- NULL);
- output_dummy = META_OUTPUT_DUMMY (output);
- output_dummy->scale = scale;
-
- *outputs = g_list_append (*outputs, output);
- }
-}
-
-static void
-meta_monitor_manager_dummy_read_current (MetaMonitorManager *manager)
-{
- MetaGpu *gpu = get_gpu (manager);
- unsigned int num_monitors = 1;
- float *monitor_scales = NULL;
- const char *num_monitors_str;
- const char *monitor_scales_str;
- const char *tiled_monitors_str;
- gboolean tiled_monitors;
- unsigned int i;
- GList *outputs;
- GList *crtcs;
- GList *modes;
-
- /* To control what monitor configuration is generated, there are two available
- * environmental variables that can be used:
- *
- * MUTTER_DEBUG_NUM_DUMMY_MONITORS
- *
- * Specifies the number of dummy monitors to include in the stage. Every
- * monitor is 1024x786 pixels and they are placed on a horizontal row.
- *
- * MUTTER_DEBUG_DUMMY_MODE_SPECS
- *
- * A colon separated list of mode specifications that can be used to
- * configure the monitor via dbus API. Setting this environment variable
- * overrides the default set of modes available.
- * Format should be WWxHH:WWxHH@RR
- *
- * MUTTER_DEBUG_DUMMY_MONITOR_SCALES
- *
- * A comma separated list that specifies the scales of the dummy monitors.
- *
- * MUTTER_DEBUG_TILED_DUMMY_MONITORS
- *
- * If set to "1" the dummy monitors will emulate being tiled, i.e. each have a
- * unique tile group id, made up of multiple outputs and CRTCs.
- *
- * For example the following configuration results in two monitors, where the
- * first one has the monitor scale 1, and the other the monitor scale 2.
- *
- * MUTTER_DEBUG_NUM_DUMMY_MONITORS=2
- * MUTTER_DEBUG_DUMMY_MONITOR_SCALES=1,2
- * MUTTER_DEBUG_TILED_DUMMY_MONITORS=1
- */
- num_monitors_str = getenv ("MUTTER_DEBUG_NUM_DUMMY_MONITORS");
- if (num_monitors_str)
- {
- num_monitors = g_ascii_strtoll (num_monitors_str, NULL, 10);
- if (num_monitors <= 0)
- {
- meta_warning ("Invalid number of dummy monitors");
- num_monitors = 1;
- }
-
- if (num_monitors > MAX_MONITORS)
- {
- meta_warning ("Clamping monitor count to max (%d)",
- MAX_MONITORS);
- num_monitors = MAX_MONITORS;
- }
- }
-
- monitor_scales = g_newa (typeof (*monitor_scales), num_monitors);
- for (i = 0; i < num_monitors; i++)
- monitor_scales[i] = 1.0;
-
- monitor_scales_str = getenv ("MUTTER_DEBUG_DUMMY_MONITOR_SCALES");
- if (monitor_scales_str)
- {
- gchar **scales_str_list;
-
- scales_str_list = g_strsplit (monitor_scales_str, ",", -1);
- if (g_strv_length (scales_str_list) != num_monitors)
- meta_warning ("Number of specified monitor scales differ from number "
- "of monitors (defaults to 1).");
- for (i = 0; i < num_monitors && scales_str_list[i]; i++)
- {
- float scale = g_ascii_strtod (scales_str_list[i], NULL);
-
- monitor_scales[i] = scale;
- }
- g_strfreev (scales_str_list);
- }
-
- tiled_monitors_str = g_getenv ("MUTTER_DEBUG_TILED_DUMMY_MONITORS");
- tiled_monitors = g_strcmp0 (tiled_monitors_str, "1") == 0;
-
- modes = NULL;
- crtcs = NULL;
- outputs = NULL;
-
- for (i = 0; i < num_monitors; i++)
- {
- if (tiled_monitors)
- append_tiled_monitor (manager,
- &modes, &crtcs, &outputs, monitor_scales[i]);
- else
- append_monitor (manager, &modes, &crtcs, &outputs, monitor_scales[i]);
- }
-
- meta_gpu_take_modes (gpu, modes);
- meta_gpu_take_crtcs (gpu, crtcs);
- meta_gpu_take_outputs (gpu, outputs);
-}
-
-static void
-meta_monitor_manager_dummy_ensure_initial_config (MetaMonitorManager *manager)
-{
- MetaMonitorsConfig *config;
-
- config = meta_monitor_manager_ensure_configured (manager);
-
- if (meta_is_stage_views_enabled ())
- meta_monitor_manager_update_logical_state (manager, config);
- else
- meta_monitor_manager_update_logical_state_derived (manager, NULL);
-}
-
-static void
-apply_crtc_assignments (MetaMonitorManager *manager,
- MetaCrtcAssignment **crtcs,
- unsigned int n_crtcs,
- MetaOutputAssignment **outputs,
- unsigned int n_outputs)
-{
- g_autoptr (GList) to_configure_outputs = NULL;
- g_autoptr (GList) to_configure_crtcs = NULL;
- unsigned i;
-
- to_configure_outputs = g_list_copy (meta_gpu_get_outputs (get_gpu (manager)));
- to_configure_crtcs = g_list_copy (meta_gpu_get_crtcs (get_gpu (manager)));
-
- for (i = 0; i < n_crtcs; i++)
- {
- MetaCrtcAssignment *crtc_assignment = crtcs[i];
- MetaCrtc *crtc = crtc_assignment->crtc;
-
- to_configure_crtcs = g_list_remove (to_configure_crtcs, crtc);
-
- if (crtc_assignment->mode == NULL)
- {
- meta_crtc_unset_config (crtc);
- }
- else
- {
- unsigned int j;
-
- meta_crtc_set_config (crtc,
- &crtc_assignment->layout,
- crtc_assignment->mode,
- crtc_assignment->transform);
-
- for (j = 0; j < crtc_assignment->outputs->len; j++)
- {
- MetaOutput *output;
- MetaOutputAssignment *output_assignment;
-
- output = ((MetaOutput**) crtc_assignment->outputs->pdata)[j];
-
- to_configure_outputs = g_list_remove (to_configure_outputs,
- output);
-
- output_assignment = meta_find_output_assignment (outputs,
- n_outputs,
- output);
- meta_output_assign_crtc (output, crtc, output_assignment);
- }
- }
- }
-
- g_list_foreach (to_configure_crtcs,
- (GFunc) meta_crtc_unset_config,
- NULL);
- g_list_foreach (to_configure_outputs,
- (GFunc) meta_output_unassign_crtc,
- NULL);
-}
-
-static void
-update_screen_size (MetaMonitorManager *manager,
- MetaMonitorsConfig *config)
-{
- GList *l;
- int screen_width = 0;
- int screen_height = 0;
-
- for (l = config->logical_monitor_configs; l; l = l->next)
- {
- MetaLogicalMonitorConfig *logical_monitor_config = l->data;
- int right_edge;
- int bottom_edge;
-
- right_edge = (logical_monitor_config->layout.width +
- logical_monitor_config->layout.x);
- if (right_edge > screen_width)
- screen_width = right_edge;
-
- bottom_edge = (logical_monitor_config->layout.height +
- logical_monitor_config->layout.y);
- if (bottom_edge > screen_height)
- screen_height = bottom_edge;
- }
-
- manager->screen_width = screen_width;
- manager->screen_height = screen_height;
-}
-
-static gboolean
-meta_monitor_manager_dummy_apply_monitors_config (MetaMonitorManager *manager,
- MetaMonitorsConfig *config,
- MetaMonitorsConfigMethod method,
- GError **error)
-{
- GPtrArray *crtc_assignments;
- GPtrArray *output_assignments;
-
- if (!config)
- {
- manager->screen_width = META_MONITOR_MANAGER_MIN_SCREEN_WIDTH;
- manager->screen_height = META_MONITOR_MANAGER_MIN_SCREEN_HEIGHT;
-
- meta_monitor_manager_rebuild (manager, NULL);
- return TRUE;
- }
-
- if (!meta_monitor_config_manager_assign (manager, config,
- &crtc_assignments,
- &output_assignments,
- error))
- return FALSE;
-
- if (method == META_MONITORS_CONFIG_METHOD_VERIFY)
- {
- g_ptr_array_free (crtc_assignments, TRUE);
- g_ptr_array_free (output_assignments, TRUE);
- return TRUE;
- }
-
- apply_crtc_assignments (manager,
- (MetaCrtcAssignment **) crtc_assignments->pdata,
- crtc_assignments->len,
- (MetaOutputAssignment **) output_assignments->pdata,
- output_assignments->len);
-
- g_ptr_array_free (crtc_assignments, TRUE);
- g_ptr_array_free (output_assignments, TRUE);
-
- update_screen_size (manager, config);
- meta_monitor_manager_rebuild (manager, config);
-
- return TRUE;
-}
-
-static gboolean
-meta_monitor_manager_dummy_is_transform_handled (MetaMonitorManager *manager,
- MetaCrtc *crtc,
- MetaMonitorTransform transform)
-{
- MetaMonitorManagerDummy *manager_dummy = META_MONITOR_MANAGER_DUMMY (manager);
-
- return manager_dummy->is_transform_handled;
-}
-
-static float
-meta_monitor_manager_dummy_calculate_monitor_mode_scale (MetaMonitorManager *manager,
- MetaMonitor *monitor,
- MetaMonitorMode *monitor_mode)
-{
- MetaOutput *output;
- MetaOutputDummy *output_dummy;
-
- output = meta_monitor_get_main_output (monitor);
- output_dummy = META_OUTPUT_DUMMY (output);
-
- return output_dummy->scale;
-}
-
-static float *
-meta_monitor_manager_dummy_calculate_supported_scales (MetaMonitorManager *manager,
- MetaLogicalMonitorLayoutMode layout_mode,
- MetaMonitor *monitor,
- MetaMonitorMode *monitor_mode,
- int *n_supported_scales)
-{
- MetaMonitorScalesConstraint constraints =
- META_MONITOR_SCALES_CONSTRAINT_NONE;
-
- switch (layout_mode)
- {
- case META_LOGICAL_MONITOR_LAYOUT_MODE_LOGICAL:
- break;
- case META_LOGICAL_MONITOR_LAYOUT_MODE_PHYSICAL:
- constraints |= META_MONITOR_SCALES_CONSTRAINT_NO_FRAC;
- break;
- }
-
- return meta_monitor_calculate_supported_scales (monitor, monitor_mode,
- constraints,
- n_supported_scales);
-}
-
-static gboolean
-is_monitor_framebuffers_scaled (void)
-{
- MetaBackend *backend = meta_get_backend ();
- MetaSettings *settings = meta_backend_get_settings (backend);
-
- return meta_settings_is_experimental_feature_enabled (
- settings,
- META_EXPERIMENTAL_FEATURE_SCALE_MONITOR_FRAMEBUFFER);
-}
-
-static MetaMonitorManagerCapability
-meta_monitor_manager_dummy_get_capabilities (MetaMonitorManager *manager)
-{
- MetaBackend *backend = meta_get_backend ();
- MetaSettings *settings = meta_backend_get_settings (backend);
- MetaMonitorManagerCapability capabilities =
- META_MONITOR_MANAGER_CAPABILITY_NONE;
-
- if (meta_settings_is_experimental_feature_enabled (
- settings,
- META_EXPERIMENTAL_FEATURE_SCALE_MONITOR_FRAMEBUFFER))
- capabilities |= META_MONITOR_MANAGER_CAPABILITY_LAYOUT_MODE;
-
- return capabilities;
-}
-
-static gboolean
-meta_monitor_manager_dummy_get_max_screen_size (MetaMonitorManager *manager,
- int *max_width,
- int *max_height)
-{
- if (meta_is_stage_views_enabled ())
- return FALSE;
-
- *max_width = 65535;
- *max_height = 65535;
-
- return TRUE;
-}
-
-static MetaLogicalMonitorLayoutMode
-meta_monitor_manager_dummy_get_default_layout_mode (MetaMonitorManager *manager)
-{
- if (!meta_is_stage_views_enabled ())
- return META_LOGICAL_MONITOR_LAYOUT_MODE_PHYSICAL;
-
- if (is_monitor_framebuffers_scaled ())
- return META_LOGICAL_MONITOR_LAYOUT_MODE_LOGICAL;
- else
- return META_LOGICAL_MONITOR_LAYOUT_MODE_PHYSICAL;
-}
-
-static void
-meta_monitor_manager_dummy_constructed (GObject *object)
-{
- MetaMonitorManagerDummy *manager_dummy = META_MONITOR_MANAGER_DUMMY (object);
- const char *nested_offscreen_transform;
- GObjectClass *parent_object_class =
- G_OBJECT_CLASS (meta_monitor_manager_dummy_parent_class);
-
- parent_object_class->constructed (object);
-
- nested_offscreen_transform =
- g_getenv ("MUTTER_DEBUG_NESTED_OFFSCREEN_TRANSFORM");
- if (g_strcmp0 (nested_offscreen_transform, "1") == 0)
- manager_dummy->is_transform_handled = FALSE;
- else
- manager_dummy->is_transform_handled = TRUE;
-}
-
-static void
-meta_monitor_manager_dummy_class_init (MetaMonitorManagerDummyClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
- MetaMonitorManagerClass *manager_class = META_MONITOR_MANAGER_CLASS (klass);
-
- object_class->constructed = meta_monitor_manager_dummy_constructed;
-
- manager_class->ensure_initial_config = meta_monitor_manager_dummy_ensure_initial_config;
- manager_class->apply_monitors_config = meta_monitor_manager_dummy_apply_monitors_config;
- manager_class->is_transform_handled = meta_monitor_manager_dummy_is_transform_handled;
- manager_class->calculate_monitor_mode_scale = meta_monitor_manager_dummy_calculate_monitor_mode_scale;
- manager_class->calculate_supported_scales = meta_monitor_manager_dummy_calculate_supported_scales;
- manager_class->get_capabilities = meta_monitor_manager_dummy_get_capabilities;
- manager_class->get_max_screen_size = meta_monitor_manager_dummy_get_max_screen_size;
- manager_class->get_default_layout_mode = meta_monitor_manager_dummy_get_default_layout_mode;
-}
-
-static void
-meta_monitor_manager_dummy_init (MetaMonitorManagerDummy *manager_dummy)
-{
-}
-
-static gboolean
-meta_gpu_dummy_read_current (MetaGpu *gpu,
- GError **error)
-{
- MetaBackend *backend = meta_gpu_get_backend (gpu);
- MetaMonitorManager *manager = meta_backend_get_monitor_manager (backend);
-
- meta_monitor_manager_dummy_read_current (manager);
-
- return TRUE;
-}
-
-static void
-meta_gpu_dummy_init (MetaGpuDummy *gpu_dummy)
-{
-}
-
-static void
-meta_gpu_dummy_class_init (MetaGpuDummyClass *klass)
-{
- MetaGpuClass *gpu_class = META_GPU_CLASS (klass);
-
- gpu_class->read_current = meta_gpu_dummy_read_current;
-}
-
-static void
-meta_output_dummy_init (MetaOutputDummy *output_dummy)
-{
- output_dummy->scale = 1;
-}
-
-static void
-meta_output_dummy_class_init (MetaOutputDummyClass *klass)
-{
-}
-
-static void
-meta_crtc_dummy_init (MetaCrtcDummy *crtc_dummy)
-{
-}
-
-static void
-meta_crtc_dummy_class_init (MetaCrtcDummyClass *klass)
-{
-}
diff --git a/src/backends/meta-monitor-manager-dummy.h b/src/backends/meta-monitor-manager-dummy.h
deleted file mode 100644
index 72244166e..000000000
--- a/src/backends/meta-monitor-manager-dummy.h
+++ /dev/null
@@ -1,48 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2001 Havoc Pennington
- * Copyright (C) 2003 Rob Adams
- * Copyright (C) 2004-2006 Elijah Newren
- * Copyright (C) 2013 Red Hat Inc.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef META_MONITOR_MANAGER_DUMMY_H
-#define META_MONITOR_MANAGER_DUMMY_H
-
-#include "backends/meta-crtc.h"
-#include "backends/meta-gpu.h"
-#include "backends/meta-monitor-manager-private.h"
-#include "backends/meta-output.h"
-
-#define META_TYPE_OUTPUT_DUMMY (meta_output_dummy_get_type ())
-G_DECLARE_FINAL_TYPE (MetaOutputDummy, meta_output_dummy,
- META, OUTPUT_DUMMY,
- MetaOutput)
-
-#define META_TYPE_CRTC_DUMMY (meta_crtc_dummy_get_type ())
-G_DECLARE_FINAL_TYPE (MetaCrtcDummy, meta_crtc_dummy,
- META, CRTC_DUMMY,
- MetaCrtc)
-
-#define META_TYPE_MONITOR_MANAGER_DUMMY (meta_monitor_manager_dummy_get_type ())
-G_DECLARE_FINAL_TYPE (MetaMonitorManagerDummy, meta_monitor_manager_dummy,
- META, MONITOR_MANAGER_DUMMY, MetaMonitorManager)
-
-#define META_TYPE_GPU_DUMMY (meta_gpu_dummy_get_type ())
-G_DECLARE_FINAL_TYPE (MetaGpuDummy, meta_gpu_dummy, META, GPU_DUMMY, MetaGpu)
-
-#endif /* META_MONITOR_MANAGER_DUMMY_H */
diff --git a/src/backends/meta-monitor-manager-private.h b/src/backends/meta-monitor-manager-private.h
deleted file mode 100644
index 60c1e9082..000000000
--- a/src/backends/meta-monitor-manager-private.h
+++ /dev/null
@@ -1,439 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2001 Havoc Pennington
- * Copyright (C) 2003 Rob Adams
- * Copyright (C) 2004-2006 Elijah Newren
- * Copyright (C) 2013 Red Hat Inc.
- * Copyright (C) 2020 NVIDIA CORPORATION
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef META_MONITOR_MANAGER_PRIVATE_H
-#define META_MONITOR_MANAGER_PRIVATE_H
-
-#include <cogl/cogl.h>
-#include <graphene.h>
-#include <libgnome-desktop/gnome-pnp-ids.h>
-
-#include "backends/meta-backend-private.h"
-#include "backends/meta-cursor.h"
-#include "backends/meta-display-config-shared.h"
-#include "backends/meta-monitor-transform.h"
-#include "backends/meta-viewport-info.h"
-#include "core/util-private.h"
-#include "meta/display.h"
-#include "meta/meta-monitor-manager.h"
-
-#define META_MONITOR_MANAGER_MIN_SCREEN_WIDTH 640
-#define META_MONITOR_MANAGER_MIN_SCREEN_HEIGHT 480
-
-typedef enum _MetaMonitorManagerCapability
-{
- META_MONITOR_MANAGER_CAPABILITY_NONE = 0,
- META_MONITOR_MANAGER_CAPABILITY_LAYOUT_MODE = (1 << 0),
- META_MONITOR_MANAGER_CAPABILITY_GLOBAL_SCALE_REQUIRED = (1 << 1)
-} MetaMonitorManagerCapability;
-
-/* Equivalent to the 'method' enum in org.gnome.Mutter.DisplayConfig */
-typedef enum _MetaMonitorsConfigMethod
-{
- META_MONITORS_CONFIG_METHOD_VERIFY = 0,
- META_MONITORS_CONFIG_METHOD_TEMPORARY = 1,
- META_MONITORS_CONFIG_METHOD_PERSISTENT = 2
-} MetaMonitorsConfigMethod;
-
-/* Equivalent to the 'layout-mode' enum in org.gnome.Mutter.DisplayConfig */
-typedef enum _MetaLogicalMonitorLayoutMode
-{
- META_LOGICAL_MONITOR_LAYOUT_MODE_LOGICAL = 1,
- META_LOGICAL_MONITOR_LAYOUT_MODE_PHYSICAL = 2
-} MetaLogicalMonitorLayoutMode;
-
-/*
- * MetaCrtcAssignment:
- *
- * A representation of a CRTC configuration, generated by
- * MetaMonitorConfigManager.
- */
-struct _MetaCrtcAssignment
-{
- MetaCrtc *crtc;
- MetaCrtcMode *mode;
- graphene_rect_t layout;
- MetaMonitorTransform transform;
- GPtrArray *outputs;
-};
-
-/*
- * MetaOutputAssignment:
- *
- * A representation of a connector configuration, generated by
- * MetaMonitorConfigManager.
- */
-struct _MetaOutputAssignment
-{
- MetaOutput *output;
- gboolean is_primary;
- gboolean is_presentation;
- gboolean is_underscanning;
-};
-
-/*
- * MetaOutputCtm:
- *
- * A 3x3 color transform matrix in the fixed-point S31.32 sign-magnitude format
- * used by DRM.
- */
-typedef struct _MetaOutputCtm
-{
- uint64_t matrix[9];
-} MetaOutputCtm;
-
-#define META_TYPE_MONITOR_MANAGER (meta_monitor_manager_get_type ())
-#define META_MONITOR_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), META_TYPE_MONITOR_MANAGER, MetaMonitorManager))
-#define META_MONITOR_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), META_TYPE_MONITOR_MANAGER, MetaMonitorManagerClass))
-#define META_IS_MONITOR_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), META_TYPE_MONITOR_MANAGER))
-#define META_IS_MONITOR_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), META_TYPE_MONITOR_MANAGER))
-#define META_MONITOR_MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), META_TYPE_MONITOR_MANAGER, MetaMonitorManagerClass))
-
-typedef struct _MetaDBusDisplayConfig MetaDBusDisplayConfig;
-
-G_DEFINE_AUTOPTR_CLEANUP_FUNC (MetaMonitorManager, g_object_unref)
-
-struct _MetaMonitorManager
-{
- GObject parent_instance;
-
- MetaDBusDisplayConfig *display_config;
-
- MetaBackend *backend;
-
- /* XXX: this structure is very badly
- packed, but I like the logical organization
- of fields */
-
- gboolean in_init;
- unsigned int serial;
-
- MetaLogicalMonitorLayoutMode layout_mode;
-
- int screen_width;
- int screen_height;
-
- GList *monitors;
-
- GList *logical_monitors;
- MetaLogicalMonitor *primary_logical_monitor;
-
- int dbus_name_id;
-
- int persistent_timeout_id;
-
- guint panel_orientation_managed : 1;
-
- MetaMonitorConfigManager *config_manager;
-
- GnomePnpIds *pnp_ids;
-
- gulong experimental_features_changed_handler_id;
-
- MetaMonitorSwitchConfigType current_switch_config;
-};
-
-/**
- * MetaMonitorManagerClass:
- *
- * @read_edid: Returns the raw Extended Display Identification Data (EDID)
- * for the given #MetaOutput object.
- *
- * @ensure_initial_config: Called on setup. Makes sure an initial config
- * is loaded.
- *
- * @apply_monitors_config: Tries to apply the given config using the given
- * method. Throws an error if something went wrong.
- *
- * @set_power_save_mode: Sets the #MetaPowerSave mode (for all displays).
- *
- * @change_backlight: Changes the backlight intensity to the given value (in
- * percent).
- *
- * @get_crtc_gamma: Queries and returns the gamma rampQueries and returns the
- * gamma ramp.
- *
- * @set_crtc_gamma: Sets custom display LUT (look up table) for each primary
- * color. Each table is indexed by a value that represents input intensity,
- * and yields a value that represents output intensity.
- *
- * @tiled_monitor_added: Should be called by a #MetaMonitor when it is created.
- *
- * @tiled_monitor_removed: Should be called by a #MetaMonitor when it is
- * destroyed.
- *
- * @is_transform_handled: vfunc for
- * meta_monitor_manager_is_transform_handled().
- * @calculate_monitor_mode_scale: vfunc for
- * meta_monitor_manager_calculate_monitor_mode_scale().
- * @calculate_supported_scales: vfunc for
- * meta_monitor_manager_calculate_supported_scales().
- * @get_capabilities: vfunc for meta_monitor_manager_get_capabilities().
- * @get_max_screen_size: vfunc for meta_monitor_manager_get_max_screen_size().
- * @get_default_layout_mode: vfunc for meta_monitor_manager_get_default_layout_mode().
- * @set_output_ctm: vfunc for meta_monitor_manager_output_set_ctm()
- *
- * The base class for a #MetaMonitorManager.
- */
-struct _MetaMonitorManagerClass
-{
- GObjectClass parent_class;
-
- GBytes * (* read_edid) (MetaMonitorManager *manager,
- MetaOutput *output);
-
- void (* read_current_state) (MetaMonitorManager *manager);
-
- void (* ensure_initial_config) (MetaMonitorManager *manager);
-
- gboolean (* apply_monitors_config) (MetaMonitorManager *manager,
- MetaMonitorsConfig *config,
- MetaMonitorsConfigMethod method,
- GError **error);
-
- void (* set_power_save_mode) (MetaMonitorManager *manager,
- MetaPowerSave power_save);
-
- void (* change_backlight) (MetaMonitorManager *manager,
- MetaOutput *output,
- int backlight);
-
- void (* get_crtc_gamma) (MetaMonitorManager *manager,
- MetaCrtc *crtc,
- size_t *size,
- unsigned short **red,
- unsigned short **green,
- unsigned short **blue);
- void (* set_crtc_gamma) (MetaMonitorManager *manager,
- MetaCrtc *crtc,
- size_t size,
- unsigned short *red,
- unsigned short *green,
- unsigned short *blue);
-
- void (* tiled_monitor_added) (MetaMonitorManager *manager,
- MetaMonitor *monitor);
-
- void (* tiled_monitor_removed) (MetaMonitorManager *manager,
- MetaMonitor *monitor);
-
- gboolean (* is_transform_handled) (MetaMonitorManager *manager,
- MetaCrtc *crtc,
- MetaMonitorTransform transform);
-
- float (* calculate_monitor_mode_scale) (MetaMonitorManager *manager,
- MetaMonitor *monitor,
- MetaMonitorMode *monitor_mode);
-
- float * (* calculate_supported_scales) (MetaMonitorManager *manager,
- MetaLogicalMonitorLayoutMode layout_mode,
- MetaMonitor *monitor,
- MetaMonitorMode *monitor_mode,
- int *n_supported_scales);
-
- MetaMonitorManagerCapability (* get_capabilities) (MetaMonitorManager *manager);
-
- gboolean (* get_max_screen_size) (MetaMonitorManager *manager,
- int *width,
- int *height);
-
- MetaLogicalMonitorLayoutMode (* get_default_layout_mode) (MetaMonitorManager *manager);
-
- void (* set_output_ctm) (MetaOutput *output,
- const MetaOutputCtm *ctm);
-
- MetaVirtualMonitor * (* create_virtual_monitor) (MetaMonitorManager *manager,
- const MetaVirtualMonitorInfo *info,
- GError **error);
-};
-
-META_EXPORT_TEST
-MetaBackend * meta_monitor_manager_get_backend (MetaMonitorManager *manager);
-
-void meta_monitor_manager_setup (MetaMonitorManager *manager);
-
-META_EXPORT_TEST
-void meta_monitor_manager_rebuild (MetaMonitorManager *manager,
- MetaMonitorsConfig *config);
-
-META_EXPORT_TEST
-void meta_monitor_manager_rebuild_derived (MetaMonitorManager *manager,
- MetaMonitorsConfig *config);
-
-META_EXPORT_TEST
-int meta_monitor_manager_get_num_logical_monitors (MetaMonitorManager *manager);
-
-META_EXPORT_TEST
-GList * meta_monitor_manager_get_logical_monitors (MetaMonitorManager *manager);
-
-MetaLogicalMonitor *meta_monitor_manager_get_logical_monitor_from_number (MetaMonitorManager *manager,
- int number);
-
-MetaLogicalMonitor *meta_monitor_manager_get_primary_logical_monitor (MetaMonitorManager *manager);
-
-MetaLogicalMonitor *meta_monitor_manager_get_logical_monitor_at (MetaMonitorManager *manager,
- float x,
- float y);
-
-MetaLogicalMonitor *meta_monitor_manager_get_logical_monitor_from_rect (MetaMonitorManager *manager,
- MetaRectangle *rect);
-
-MetaLogicalMonitor *meta_monitor_manager_get_logical_monitor_neighbor (MetaMonitorManager *manager,
- MetaLogicalMonitor *logical_monitor,
- MetaDisplayDirection direction);
-
-MetaMonitor * meta_monitor_manager_get_primary_monitor (MetaMonitorManager *manager);
-
-MetaMonitor * meta_monitor_manager_get_laptop_panel (MetaMonitorManager *manager);
-
-MetaMonitor * meta_monitor_manager_get_monitor_from_spec (MetaMonitorManager *manager,
- MetaMonitorSpec *monitor_spec);
-
-MetaMonitor * meta_monitor_manager_get_monitor_from_connector (MetaMonitorManager *manager,
- const char *connector);
-
-META_EXPORT_TEST
-GList * meta_monitor_manager_get_monitors (MetaMonitorManager *manager);
-
-void meta_monitor_manager_get_screen_size (MetaMonitorManager *manager,
- int *width,
- int *height);
-
-MetaPowerSave meta_monitor_manager_get_power_save_mode (MetaMonitorManager *manager);
-
-void meta_monitor_manager_power_save_mode_changed (MetaMonitorManager *manager,
- MetaPowerSave mode);
-
-void meta_monitor_manager_confirm_configuration (MetaMonitorManager *manager,
- gboolean ok);
-
-gboolean meta_monitor_manager_has_hotplug_mode_update (MetaMonitorManager *manager);
-
-void meta_monitor_manager_read_current_state (MetaMonitorManager *manager);
-
-void meta_monitor_manager_reconfigure (MetaMonitorManager *manager);
-
-META_EXPORT_TEST
-void meta_monitor_manager_reload (MetaMonitorManager *manager);
-
-gboolean meta_monitor_manager_get_monitor_matrix (MetaMonitorManager *manager,
- MetaMonitor *monitor,
- MetaLogicalMonitor *logical_monitor,
- gfloat matrix[6]);
-
-void meta_monitor_manager_tiled_monitor_added (MetaMonitorManager *manager,
- MetaMonitor *monitor);
-void meta_monitor_manager_tiled_monitor_removed (MetaMonitorManager *manager,
- MetaMonitor *monitor);
-
-gboolean meta_monitor_manager_is_transform_handled (MetaMonitorManager *manager,
- MetaCrtc *crtc,
- MetaMonitorTransform transform);
-
-META_EXPORT_TEST
-MetaMonitorsConfig * meta_monitor_manager_ensure_configured (MetaMonitorManager *manager);
-
-META_EXPORT_TEST
-void meta_monitor_manager_update_logical_state (MetaMonitorManager *manager,
- MetaMonitorsConfig *config);
-
-META_EXPORT_TEST
-void meta_monitor_manager_update_logical_state_derived (MetaMonitorManager *manager,
- MetaMonitorsConfig *config);
-
-META_EXPORT_TEST
-void meta_monitor_manager_lid_is_closed_changed (MetaMonitorManager *manager);
-
-gboolean meta_monitor_manager_is_headless (MetaMonitorManager *manager);
-
-float meta_monitor_manager_calculate_monitor_mode_scale (MetaMonitorManager *manager,
- MetaMonitor *monitor,
- MetaMonitorMode *monitor_mode);
-
-float * meta_monitor_manager_calculate_supported_scales (MetaMonitorManager *,
- MetaLogicalMonitorLayoutMode ,
- MetaMonitor *,
- MetaMonitorMode *,
- int *);
-
-gboolean meta_monitor_manager_is_scale_supported (MetaMonitorManager *manager,
- MetaLogicalMonitorLayoutMode layout_mode,
- MetaMonitor *monitor,
- MetaMonitorMode *monitor_mode,
- float scale);
-
-MetaMonitorManagerCapability
- meta_monitor_manager_get_capabilities (MetaMonitorManager *manager);
-
-gboolean meta_monitor_manager_get_max_screen_size (MetaMonitorManager *manager,
- int *max_width,
- int *max_height);
-
-MetaLogicalMonitorLayoutMode
- meta_monitor_manager_get_default_layout_mode (MetaMonitorManager *manager);
-
-META_EXPORT_TEST
-MetaVirtualMonitor * meta_monitor_manager_create_virtual_monitor (MetaMonitorManager *manager,
- const MetaVirtualMonitorInfo *info,
- GError **error);
-
-META_EXPORT_TEST
-MetaMonitorConfigManager *
- meta_monitor_manager_get_config_manager (MetaMonitorManager *manager);
-
-void meta_monitor_manager_rotate_monitor (MetaMonitorManager *manager);
-
-void meta_monitor_manager_clear_output (MetaOutput *output);
-void meta_monitor_manager_clear_mode (MetaCrtcMode *mode);
-void meta_monitor_manager_clear_crtc (MetaCrtc *crtc);
-
-gboolean meta_monitor_has_aspect_as_size (MetaMonitor *monitor);
-
-char * meta_monitor_manager_get_vendor_name (MetaMonitorManager *manager,
- const char *vendor);
-
-static inline MetaOutputAssignment *
-meta_find_output_assignment (MetaOutputAssignment **outputs,
- unsigned int n_outputs,
- MetaOutput *output)
-{
- unsigned int i;
-
- for (i = 0; i < n_outputs; i++)
- {
- MetaOutputAssignment *output_assignment = outputs[i];
-
- if (output == output_assignment->output)
- return output_assignment;
- }
-
- return NULL;
-}
-
-void meta_monitor_manager_post_init (MetaMonitorManager *manager);
-
-MetaViewportInfo * meta_monitor_manager_get_viewports (MetaMonitorManager *manager);
-
-GList * meta_monitor_manager_get_virtual_monitors (MetaMonitorManager *manager);
-
-#endif /* META_MONITOR_MANAGER_PRIVATE_H */
diff --git a/src/backends/meta-monitor-manager.c b/src/backends/meta-monitor-manager.c
deleted file mode 100644
index e6d50bd99..000000000
--- a/src/backends/meta-monitor-manager.c
+++ /dev/null
@@ -1,3471 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2001, 2002 Havoc Pennington
- * Copyright (C) 2002, 2003 Red Hat Inc.
- * Some ICCCM manager selection code derived from fvwm2,
- * Copyright (C) 2001 Dominik Vogt, Matthias Clasen, and fvwm2 team
- * Copyright (C) 2003 Rob Adams
- * Copyright (C) 2004-2006 Elijah Newren
- * Copyright (C) 2013 Red Hat Inc.
- * Copyright (C) 2020 NVIDIA CORPORATION
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, see <http://www.gnu.org/licenses/>.
- */
-
-/**
- * SECTION:meta-monitor-manager
- * @title: MetaMonitorManager
- * @short_description: A manager for multiple monitors
- *
- * #MetaMonitorManager is an abstract class which contains methods to handle
- * multiple monitors (both #MetaMonitor and #MetaLogicalMonitor) and GPU's
- * (#MetaGpu). Its functions include reading and/or changing the current
- * configuration and available capabiliies.
- *
- * The #MetaMonitorManager also provides the "org.gnome.Mutter.DisplayConfig"
- * DBus service, so apps like GNOME Settings can use this functionality.
- */
-
-#include "config.h"
-
-#include "backends/meta-monitor-manager-private.h"
-
-#include <string.h>
-#include <math.h>
-#include <stdlib.h>
-
-#include "backends/meta-backend-private.h"
-#include "backends/meta-crtc.h"
-#include "backends/meta-logical-monitor.h"
-#include "backends/meta-monitor.h"
-#include "backends/meta-monitor-config-manager.h"
-#include "backends/meta-orientation-manager.h"
-#include "backends/meta-output.h"
-#include "backends/meta-virtual-monitor.h"
-#include "backends/x11/meta-monitor-manager-xrandr.h"
-#include "clutter/clutter.h"
-#include "core/util-private.h"
-#include "meta/main.h"
-#include "meta/meta-x11-errors.h"
-
-#include "meta-dbus-display-config.h"
-
-#define DEFAULT_DISPLAY_CONFIGURATION_TIMEOUT 20
-
-enum
-{
- PROP_0,
-
- PROP_BACKEND,
- PROP_PANEL_ORIENTATION_MANAGED,
-
- PROP_LAST
-};
-
-static GParamSpec *obj_props[PROP_LAST];
-
-enum
-{
- MONITORS_CHANGED,
- MONITORS_CHANGED_INTERNAL,
- POWER_SAVE_MODE_CHANGED,
- CONFIRM_DISPLAY_CHANGE,
- SIGNALS_LAST
-};
-
-/* Array index matches MetaMonitorTransform */
-static gfloat transform_matrices[][6] = {
- { 1, 0, 0, 0, 1, 0 }, /* normal */
- { 0, -1, 1, 1, 0, 0 }, /* 90° */
- { -1, 0, 1, 0, -1, 1 }, /* 180° */
- { 0, 1, 0, -1, 0, 1 }, /* 270° */
- { -1, 0, 1, 0, 1, 0 }, /* normal flipped */
- { 0, 1, 0, 1, 0, 0 }, /* 90° flipped */
- { 1, 0, 0, 0, -1, 1 }, /* 180° flipped */
- { 0, -1, 1, -1, 0, 1 }, /* 270° flipped */
-};
-
-static int signals[SIGNALS_LAST];
-
-typedef struct _MetaMonitorManagerPrivate
-{
- MetaPowerSave power_save_mode;
- gboolean initial_orient_change_done;
-
- GList *virtual_monitors;
-
- gboolean shutting_down;
-} MetaMonitorManagerPrivate;
-
-G_DEFINE_TYPE_WITH_PRIVATE (MetaMonitorManager, meta_monitor_manager,
- G_TYPE_OBJECT)
-
-static void initialize_dbus_interface (MetaMonitorManager *manager);
-static void monitor_manager_setup_dbus_config_handlers (MetaMonitorManager *manager);
-
-static gboolean
-meta_monitor_manager_is_config_complete (MetaMonitorManager *manager,
- MetaMonitorsConfig *config);
-
-static MetaMonitor *
-meta_monitor_manager_get_active_monitor (MetaMonitorManager *manager);
-
-static void
-meta_monitor_manager_real_read_current_state (MetaMonitorManager *manager);
-
-MetaBackend *
-meta_monitor_manager_get_backend (MetaMonitorManager *manager)
-{
- return manager->backend;
-}
-
-static void
-meta_monitor_manager_init (MetaMonitorManager *manager)
-{
-}
-
-static void
-meta_monitor_manager_set_primary_logical_monitor (MetaMonitorManager *manager,
- MetaLogicalMonitor *logical_monitor)
-{
- manager->primary_logical_monitor = logical_monitor;
- if (logical_monitor)
- meta_logical_monitor_make_primary (logical_monitor);
-}
-
-static gboolean
-is_main_tiled_monitor_output (MetaOutput *output)
-{
- const MetaOutputInfo *output_info = meta_output_get_info (output);
-
- return (output_info->tile_info.loc_h_tile == 0 &&
- output_info->tile_info.loc_v_tile == 0);
-}
-
-static MetaLogicalMonitor *
-logical_monitor_from_layout (MetaMonitorManager *manager,
- GList *logical_monitors,
- MetaRectangle *layout)
-{
- GList *l;
-
- for (l = logical_monitors; l; l = l->next)
- {
- MetaLogicalMonitor *logical_monitor = l->data;
-
- if (meta_rectangle_equal (layout, &logical_monitor->rect))
- return logical_monitor;
- }
-
- return NULL;
-}
-
-static void
-meta_monitor_manager_rebuild_logical_monitors (MetaMonitorManager *manager,
- MetaMonitorsConfig *config)
-{
- GList *logical_monitor_configs;
- GList *logical_monitors = NULL;
- GList *l;
- int monitor_number = 0;
- MetaLogicalMonitor *primary_logical_monitor = NULL;
-
- logical_monitor_configs = config ? config->logical_monitor_configs : NULL;
- for (l = logical_monitor_configs; l; l = l->next)
- {
- MetaLogicalMonitorConfig *logical_monitor_config = l->data;
- MetaLogicalMonitor *logical_monitor;
-
- logical_monitor = meta_logical_monitor_new (manager,
- logical_monitor_config,
- monitor_number);
- monitor_number++;
-
- if (logical_monitor_config->is_primary)
- primary_logical_monitor = logical_monitor;
-
- logical_monitors = g_list_append (logical_monitors, logical_monitor);
- }
-
- /*
- * If no monitor was marked as primary, fall back on marking the first
- * logical monitor the primary one.
- */
- if (!primary_logical_monitor && logical_monitors)
- primary_logical_monitor = g_list_first (logical_monitors)->data;
-
- manager->logical_monitors = logical_monitors;
- meta_monitor_manager_set_primary_logical_monitor (manager,
- primary_logical_monitor);
-}
-
-static float
-derive_configured_global_scale (MetaMonitorManager *manager,
- MetaMonitorsConfig *config)
-{
- MetaLogicalMonitorConfig *logical_monitor_config;
-
- logical_monitor_config = config->logical_monitor_configs->data;
-
- return logical_monitor_config->scale;
-}
-
-static float
-calculate_monitor_scale (MetaMonitorManager *manager,
- MetaMonitor *monitor)
-{
- MetaMonitorMode *monitor_mode;
-
- monitor_mode = meta_monitor_get_current_mode (monitor);
- return meta_monitor_manager_calculate_monitor_mode_scale (manager,
- monitor,
- monitor_mode);
-}
-
-static float
-derive_calculated_global_scale (MetaMonitorManager *manager)
-{
- MetaMonitor *monitor = NULL;
-
- monitor = meta_monitor_manager_get_primary_monitor (manager);
-
- if (!monitor || !meta_monitor_is_active (monitor))
- monitor = meta_monitor_manager_get_active_monitor (manager);
-
- if (!monitor)
- return 1.0;
-
- return calculate_monitor_scale (manager, monitor);
-}
-
-static float
-derive_scale_from_config (MetaMonitorManager *manager,
- MetaMonitorsConfig *config,
- MetaRectangle *layout)
-{
- GList *l;
-
- for (l = config->logical_monitor_configs; l; l = l->next)
- {
- MetaLogicalMonitorConfig *logical_monitor_config = l->data;
-
- if (meta_rectangle_equal (layout, &logical_monitor_config->layout))
- return logical_monitor_config->scale;
- }
-
- g_warning ("Missing logical monitor, using scale 1");
- return 1.0;
-}
-
-static void
-meta_monitor_manager_rebuild_logical_monitors_derived (MetaMonitorManager *manager,
- MetaMonitorsConfig *config)
-{
- GList *logical_monitors = NULL;
- GList *l;
- int monitor_number;
- MetaLogicalMonitor *primary_logical_monitor = NULL;
- gboolean use_global_scale;
- float global_scale = 0.0;
- MetaMonitorManagerCapability capabilities;
-
- monitor_number = 0;
-
- capabilities = meta_monitor_manager_get_capabilities (manager);
- use_global_scale =
- !!(capabilities & META_MONITOR_MANAGER_CAPABILITY_GLOBAL_SCALE_REQUIRED);
-
- if (use_global_scale)
- {
- if (config)
- global_scale = derive_configured_global_scale (manager, config);
- else
- global_scale = derive_calculated_global_scale (manager);
- }
-
- for (l = manager->monitors; l; l = l->next)
- {
- MetaMonitor *monitor = l->data;
- MetaLogicalMonitor *logical_monitor;
- MetaRectangle layout;
-
- if (!meta_monitor_is_active (monitor))
- continue;
-
- meta_monitor_derive_layout (monitor, &layout);
- logical_monitor = logical_monitor_from_layout (manager, logical_monitors,
- &layout);
- if (logical_monitor)
- {
- meta_logical_monitor_add_monitor (logical_monitor, monitor);
- }
- else
- {
- float scale;
-
- if (use_global_scale)
- scale = global_scale;
- else if (config)
- scale = derive_scale_from_config (manager, config, &layout);
- else
- scale = calculate_monitor_scale (manager, monitor);
-
- g_assert (scale > 0);
-
- logical_monitor = meta_logical_monitor_new_derived (manager,
- monitor,
- &layout,
- scale,
- monitor_number);
- logical_monitors = g_list_append (logical_monitors, logical_monitor);
- monitor_number++;
- }
-
- if (meta_monitor_is_primary (monitor))
- primary_logical_monitor = logical_monitor;
- }
-
- manager->logical_monitors = logical_monitors;
-
- /*
- * If no monitor was marked as primary, fall back on marking the first
- * logical monitor the primary one.
- */
- if (!primary_logical_monitor && manager->logical_monitors)
- primary_logical_monitor = g_list_first (manager->logical_monitors)->data;
-
- meta_monitor_manager_set_primary_logical_monitor (manager,
- primary_logical_monitor);
-}
-
-void
-meta_monitor_manager_power_save_mode_changed (MetaMonitorManager *manager,
- MetaPowerSave mode)
-{
- MetaMonitorManagerPrivate *priv =
- meta_monitor_manager_get_instance_private (manager);
-
- if (priv->power_save_mode == mode)
- return;
-
- priv->power_save_mode = mode;
- g_signal_emit (manager, signals[POWER_SAVE_MODE_CHANGED], 0);
-}
-
-static void
-power_save_mode_changed (MetaMonitorManager *manager,
- GParamSpec *pspec,
- gpointer user_data)
-{
- MetaMonitorManagerPrivate *priv =
- meta_monitor_manager_get_instance_private (manager);
- MetaMonitorManagerClass *klass;
- int mode = meta_dbus_display_config_get_power_save_mode (manager->display_config);
-
- if (mode == META_POWER_SAVE_UNSUPPORTED)
- return;
-
- /* If DPMS is unsupported, force the property back. */
- if (priv->power_save_mode == META_POWER_SAVE_UNSUPPORTED)
- {
- meta_dbus_display_config_set_power_save_mode (manager->display_config, META_POWER_SAVE_UNSUPPORTED);
- return;
- }
-
- klass = META_MONITOR_MANAGER_GET_CLASS (manager);
- if (klass->set_power_save_mode)
- klass->set_power_save_mode (manager, mode);
-
- meta_monitor_manager_power_save_mode_changed (manager, mode);
-}
-
-void
-meta_monitor_manager_lid_is_closed_changed (MetaMonitorManager *manager)
-{
- meta_monitor_manager_ensure_configured (manager);
-}
-
-static void
-lid_is_closed_changed (MetaBackend *backend,
- gboolean lid_is_closed,
- gpointer user_data)
-{
- MetaMonitorManager *manager = user_data;
- meta_monitor_manager_lid_is_closed_changed (manager);
-}
-
-static void
-prepare_shutdown (MetaBackend *backend,
- MetaMonitorManager *manager)
-{
- MetaMonitorManagerPrivate *priv =
- meta_monitor_manager_get_instance_private (manager);
-
- priv->shutting_down = TRUE;
-}
-
-/**
- * meta_monitor_manager_is_headless:
- * @manager: A #MetaMonitorManager object
- *
- * Returns whether the monitor manager is headless, i.e. without
- * any #MetaLogicalMonitor<!-- -->s attached to it.
- *
- * Returns: %TRUE if no monitors are attached, %FALSE otherwise.
- */
-gboolean
-meta_monitor_manager_is_headless (MetaMonitorManager *manager)
-{
- return !manager->logical_monitors;
-}
-
-float
-meta_monitor_manager_calculate_monitor_mode_scale (MetaMonitorManager *manager,
- MetaMonitor *monitor,
- MetaMonitorMode *monitor_mode)
-{
- MetaMonitorManagerClass *manager_class =
- META_MONITOR_MANAGER_GET_CLASS (manager);
-
- return manager_class->calculate_monitor_mode_scale (manager,
- monitor,
- monitor_mode);
-}
-
-float *
-meta_monitor_manager_calculate_supported_scales (MetaMonitorManager *manager,
- MetaLogicalMonitorLayoutMode layout_mode,
- MetaMonitor *monitor,
- MetaMonitorMode *monitor_mode,
- int *n_supported_scales)
-{
- MetaMonitorManagerClass *manager_class =
- META_MONITOR_MANAGER_GET_CLASS (manager);
-
- return manager_class->calculate_supported_scales (manager,
- layout_mode,
- monitor,
- monitor_mode,
- n_supported_scales);
-}
-
-/**
- * meta_monitor_manager_get_capabilities:
- * @manager: A #MetaMonitorManager object
- *
- * Queries the capabilities of the monitor manager.
- *
- * Returns: #MetaMonitorManagerCapability flags representing the capabilities.
- */
-MetaMonitorManagerCapability
-meta_monitor_manager_get_capabilities (MetaMonitorManager *manager)
-{
- MetaMonitorManagerClass *manager_class =
- META_MONITOR_MANAGER_GET_CLASS (manager);
-
- return manager_class->get_capabilities (manager);
-}
-
-gboolean
-meta_monitor_manager_get_max_screen_size (MetaMonitorManager *manager,
- int *max_width,
- int *max_height)
-{
- MetaMonitorManagerClass *manager_class =
- META_MONITOR_MANAGER_GET_CLASS (manager);
-
- return manager_class->get_max_screen_size (manager, max_width, max_height);
-}
-
-
-MetaLogicalMonitorLayoutMode
-meta_monitor_manager_get_default_layout_mode (MetaMonitorManager *manager)
-{
- MetaMonitorManagerClass *manager_class =
- META_MONITOR_MANAGER_GET_CLASS (manager);
-
- return manager_class->get_default_layout_mode (manager);
-}
-
-static void
-on_virtual_monitor_destroyed (MetaVirtualMonitor *virtual_monitor,
- MetaMonitorManager *manager)
-{
- MetaMonitorManagerPrivate *priv =
- meta_monitor_manager_get_instance_private (manager);
- MetaOutput *output;
-
- output = meta_virtual_monitor_get_output (virtual_monitor);
- g_message ("Removed virtual monitor %s", meta_output_get_name (output));
- priv->virtual_monitors = g_list_remove (priv->virtual_monitors,
- virtual_monitor);
-
- if (!priv->shutting_down)
- meta_monitor_manager_reload (manager);
-}
-
-MetaVirtualMonitor *
-meta_monitor_manager_create_virtual_monitor (MetaMonitorManager *manager,
- const MetaVirtualMonitorInfo *info,
- GError **error)
-{
- MetaMonitorManagerPrivate *priv =
- meta_monitor_manager_get_instance_private (manager);
- MetaMonitorManagerClass *manager_class =
- META_MONITOR_MANAGER_GET_CLASS (manager);
- MetaVirtualMonitor *virtual_monitor;
- MetaOutput *output;
-
- if (!manager_class->create_virtual_monitor)
- {
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
- "Backend doesn't support creating virtual monitors");
- return NULL;
- }
-
- virtual_monitor = manager_class->create_virtual_monitor (manager, info,
- error);
- if (!virtual_monitor)
- return NULL;
-
- g_signal_connect (virtual_monitor, "destroy",
- G_CALLBACK (on_virtual_monitor_destroyed),
- manager);
-
- priv->virtual_monitors = g_list_append (priv->virtual_monitors,
- virtual_monitor);
-
- output = meta_virtual_monitor_get_output (virtual_monitor);
- g_message ("Added virtual monitor %s", meta_output_get_name (output));
-
- return virtual_monitor;
-}
-
-static void
-meta_monitor_manager_ensure_initial_config (MetaMonitorManager *manager)
-{
- META_MONITOR_MANAGER_GET_CLASS (manager)->ensure_initial_config (manager);
-}
-
-static gboolean
-meta_monitor_manager_apply_monitors_config (MetaMonitorManager *manager,
- MetaMonitorsConfig *config,
- MetaMonitorsConfigMethod method,
- GError **error)
-{
- MetaMonitorManagerClass *manager_class =
- META_MONITOR_MANAGER_GET_CLASS (manager);
-
- g_assert (!config ||
- !(config->flags & META_MONITORS_CONFIG_FLAG_MIGRATED));
-
- if (!manager_class->apply_monitors_config (manager, config, method, error))
- return FALSE;
-
- switch (method)
- {
- case META_MONITORS_CONFIG_METHOD_TEMPORARY:
- case META_MONITORS_CONFIG_METHOD_PERSISTENT:
- meta_monitor_config_manager_set_current (manager->config_manager, config);
- break;
- case META_MONITORS_CONFIG_METHOD_VERIFY:
- break;
- }
-
- return TRUE;
-}
-
-gboolean
-meta_monitor_manager_has_hotplug_mode_update (MetaMonitorManager *manager)
-{
- GList *gpus;
- GList *l;
-
- gpus = meta_backend_get_gpus (manager->backend);
- for (l = gpus; l; l = l->next)
- {
- MetaGpu *gpu = l->data;
-
- if (meta_gpu_has_hotplug_mode_update (gpu))
- return TRUE;
- }
-
- return FALSE;
-}
-
-static gboolean
-should_use_stored_config (MetaMonitorManager *manager)
-{
- return (manager->in_init ||
- !meta_monitor_manager_has_hotplug_mode_update (manager));
-}
-
-MetaMonitorsConfig *
-meta_monitor_manager_ensure_configured (MetaMonitorManager *manager)
-{
- MetaMonitorsConfig *config = NULL;
- GError *error = NULL;
- gboolean use_stored_config;
- MetaMonitorsConfigMethod method;
- MetaMonitorsConfigMethod fallback_method =
- META_MONITORS_CONFIG_METHOD_TEMPORARY;
-
- use_stored_config = should_use_stored_config (manager);
- if (use_stored_config)
- method = META_MONITORS_CONFIG_METHOD_PERSISTENT;
- else
- method = META_MONITORS_CONFIG_METHOD_TEMPORARY;
-
- if (use_stored_config)
- {
- config = meta_monitor_config_manager_get_stored (manager->config_manager);
- if (config)
- {
- if (!meta_monitor_manager_apply_monitors_config (manager,
- config,
- method,
- &error))
- {
- config = NULL;
- g_warning ("Failed to use stored monitor configuration: %s",
- error->message);
- g_clear_error (&error);
- }
- else
- {
- g_object_ref (config);
- goto done;
- }
- }
- }
-
- config = meta_monitor_config_manager_create_suggested (manager->config_manager);
- if (config)
- {
- if (!meta_monitor_manager_apply_monitors_config (manager,
- config,
- method,
- &error))
- {
- g_clear_object (&config);
- g_warning ("Failed to use suggested monitor configuration: %s",
- error->message);
- g_clear_error (&error);
- }
- else
- {
- goto done;
- }
- }
-
- config = meta_monitor_config_manager_get_previous (manager->config_manager);
- if (config)
- {
- config = g_object_ref (config);
-
- if (meta_monitor_manager_is_config_complete (manager, config))
- {
- if (!meta_monitor_manager_apply_monitors_config (manager,
- config,
- method,
- &error))
- {
- g_warning ("Failed to use suggested monitor configuration: %s",
- error->message);
- g_clear_error (&error);
- }
- else
- {
- goto done;
- }
- }
-
- g_clear_object (&config);
- }
-
- config = meta_monitor_config_manager_create_linear (manager->config_manager);
- if (config)
- {
- if (!meta_monitor_manager_apply_monitors_config (manager,
- config,
- method,
- &error))
- {
- g_clear_object (&config);
- g_warning ("Failed to use linear monitor configuration: %s",
- error->message);
- g_clear_error (&error);
- }
- else
- {
- goto done;
- }
- }
-
- config = meta_monitor_config_manager_create_fallback (manager->config_manager);
- if (config)
- {
- if (!meta_monitor_manager_apply_monitors_config (manager,
- config,
- fallback_method,
- &error))
- {
- g_clear_object (&config);
- g_warning ("Failed to use fallback monitor configuration: %s",
- error->message);
- g_clear_error (&error);
- }
- else
- {
- goto done;
- }
- }
-
-done:
- if (!config)
- {
- meta_monitor_manager_apply_monitors_config (manager,
- NULL,
- fallback_method,
- &error);
- return NULL;
- }
-
- g_object_unref (config);
-
- return config;
-}
-
-static void
-handle_orientation_change (MetaOrientationManager *orientation_manager,
- MetaMonitorManager *manager)
-{
- MetaMonitorTransform transform;
- GError *error = NULL;
- MetaMonitorsConfig *config;
-
- switch (meta_orientation_manager_get_orientation (orientation_manager))
- {
- case META_ORIENTATION_NORMAL:
- transform = META_MONITOR_TRANSFORM_NORMAL;
- break;
- case META_ORIENTATION_BOTTOM_UP:
- transform = META_MONITOR_TRANSFORM_180;
- break;
- case META_ORIENTATION_LEFT_UP:
- transform = META_MONITOR_TRANSFORM_90;
- break;
- case META_ORIENTATION_RIGHT_UP:
- transform = META_MONITOR_TRANSFORM_270;
- break;
-
- case META_ORIENTATION_UNDEFINED:
- default:
- return;
- }
-
- config =
- meta_monitor_config_manager_create_for_orientation (manager->config_manager,
- transform);
- if (!config)
- return;
-
- if (!meta_monitor_manager_apply_monitors_config (manager,
- config,
- META_MONITORS_CONFIG_METHOD_TEMPORARY,
- &error))
- {
- g_warning ("Failed to use orientation monitor configuration: %s",
- error->message);
- g_error_free (error);
- }
- g_object_unref (config);
-}
-
-/*
- * Special case for tablets with a native portrait mode and a keyboard dock,
- * where the device gets docked in landscape mode. For this combo to work
- * properly with mutter starting while the tablet is docked, we need to take
- * the accelerometer reported orientation into account (at mutter startup)
- * even if there is a tablet-mode-switch which indicates that the device is
- * NOT in tablet-mode (because it is docked).
- */
-static gboolean
-handle_initial_orientation_change (MetaOrientationManager *orientation_manager,
- MetaMonitorManager *manager)
-{
- ClutterBackend *clutter_backend;
- ClutterSeat *seat;
- MetaMonitor *monitor;
- MetaMonitorMode *mode;
- int width, height;
-
- clutter_backend = meta_backend_get_clutter_backend (manager->backend);
- seat = clutter_backend_get_default_seat (clutter_backend);
-
- /*
- * This is a workaround to ignore the tablet mode switch on the initial config
- * of devices with a native portrait mode panel. The touchscreen and
- * accelerometer requirements for applying the orientation must still be met.
- */
- if (!clutter_seat_has_touchscreen (seat) ||
- !meta_orientation_manager_has_accelerometer (orientation_manager))
- return FALSE;
-
- /* Check for a portrait mode panel */
- monitor = meta_monitor_manager_get_laptop_panel (manager);
- if (!monitor)
- return FALSE;
-
- mode = meta_monitor_get_preferred_mode (monitor);
- meta_monitor_mode_get_resolution (mode, &width, &height);
- if (width > height)
- return FALSE;
-
- handle_orientation_change (orientation_manager, manager);
- return TRUE;
-}
-
-static void
-orientation_changed (MetaOrientationManager *orientation_manager,
- MetaMonitorManager *manager)
-{
- MetaMonitorManagerPrivate *priv =
- meta_monitor_manager_get_instance_private (manager);
-
- if (!priv->initial_orient_change_done)
- {
- priv->initial_orient_change_done = TRUE;
- if (handle_initial_orientation_change (orientation_manager, manager))
- return;
- }
-
- if (!manager->panel_orientation_managed)
- return;
-
- handle_orientation_change (orientation_manager, manager);
-}
-
-static void
-experimental_features_changed (MetaSettings *settings,
- MetaExperimentalFeature old_experimental_features,
- MetaMonitorManager *manager)
-{
- gboolean was_stage_views_scaled;
- gboolean is_stage_views_scaled;
- gboolean should_reconfigure = FALSE;
-
- was_stage_views_scaled =
- !!(old_experimental_features &
- META_EXPERIMENTAL_FEATURE_SCALE_MONITOR_FRAMEBUFFER);
- is_stage_views_scaled =
- meta_settings_is_experimental_feature_enabled (
- settings,
- META_EXPERIMENTAL_FEATURE_SCALE_MONITOR_FRAMEBUFFER);
-
- if (is_stage_views_scaled != was_stage_views_scaled)
- should_reconfigure = TRUE;
-
- if (should_reconfigure)
- meta_monitor_manager_reconfigure (manager);
-
- meta_settings_update_ui_scaling_factor (settings);
-}
-
-static void
-update_panel_orientation_managed (MetaMonitorManager *manager)
-{
- MetaOrientationManager *orientation_manager;
- ClutterBackend *clutter_backend;
- ClutterSeat *seat;
- gboolean panel_orientation_managed;
-
- clutter_backend = meta_backend_get_clutter_backend (manager->backend);
- seat = clutter_backend_get_default_seat (clutter_backend);
-
- orientation_manager = meta_backend_get_orientation_manager (manager->backend);
-
- panel_orientation_managed =
- (clutter_seat_get_touch_mode (seat) &&
- meta_orientation_manager_has_accelerometer (orientation_manager));
-
- if (manager->panel_orientation_managed == panel_orientation_managed)
- return;
-
- manager->panel_orientation_managed = panel_orientation_managed;
- g_object_notify_by_pspec (G_OBJECT (manager),
- obj_props[PROP_PANEL_ORIENTATION_MANAGED]);
-
- meta_dbus_display_config_set_panel_orientation_managed (manager->display_config,
- manager->panel_orientation_managed);
-
- /* The orientation may have changed while it was unmanaged */
- if (panel_orientation_managed)
- handle_orientation_change (orientation_manager, manager);
-}
-
-void
-meta_monitor_manager_setup (MetaMonitorManager *manager)
-{
- manager->in_init = TRUE;
-
- manager->config_manager = meta_monitor_config_manager_new (manager);
-
- meta_monitor_manager_read_current_state (manager);
-
- meta_monitor_manager_ensure_initial_config (manager);
-
- manager->in_init = FALSE;
-}
-
-static void
-meta_monitor_manager_constructed (GObject *object)
-{
- MetaMonitorManager *manager = META_MONITOR_MANAGER (object);
- MetaBackend *backend = manager->backend;
- MetaSettings *settings = meta_backend_get_settings (backend);
-
- manager->display_config = meta_dbus_display_config_skeleton_new ();
-
- manager->experimental_features_changed_handler_id =
- g_signal_connect (settings,
- "experimental-features-changed",
- G_CALLBACK (experimental_features_changed),
- manager);
-
- monitor_manager_setup_dbus_config_handlers (manager);
-
- g_signal_connect_object (manager->display_config, "notify::power-save-mode",
- G_CALLBACK (power_save_mode_changed), manager,
- G_CONNECT_SWAPPED);
-
- g_signal_connect_object (meta_backend_get_orientation_manager (backend),
- "orientation-changed",
- G_CALLBACK (orientation_changed),
- manager, 0);
-
- g_signal_connect_object (meta_backend_get_orientation_manager (backend),
- "notify::has-accelerometer",
- G_CALLBACK (update_panel_orientation_managed), manager,
- G_CONNECT_SWAPPED);
-
- g_signal_connect_object (backend,
- "lid-is-closed-changed",
- G_CALLBACK (lid_is_closed_changed),
- manager, 0);
-
- g_signal_connect (backend, "prepare-shutdown",
- G_CALLBACK (prepare_shutdown),
- manager);
-
- manager->current_switch_config = META_MONITOR_SWITCH_CONFIG_UNKNOWN;
-
- initialize_dbus_interface (manager);
-}
-
-static void
-meta_monitor_manager_finalize (GObject *object)
-{
- MetaMonitorManager *manager = META_MONITOR_MANAGER (object);
- MetaMonitorManagerPrivate *priv =
- meta_monitor_manager_get_instance_private (manager);
-
- g_list_free_full (manager->logical_monitors, g_object_unref);
-
- g_warn_if_fail (!priv->virtual_monitors);
-
- g_clear_signal_handler (&manager->experimental_features_changed_handler_id,
- manager->backend);
-
- G_OBJECT_CLASS (meta_monitor_manager_parent_class)->finalize (object);
-}
-
-static void
-meta_monitor_manager_dispose (GObject *object)
-{
- MetaMonitorManager *manager = META_MONITOR_MANAGER (object);
-
- if (manager->dbus_name_id != 0)
- {
- g_bus_unown_name (manager->dbus_name_id);
- manager->dbus_name_id = 0;
- }
-
- g_clear_object (&manager->display_config);
- g_clear_object (&manager->config_manager);
-
- G_OBJECT_CLASS (meta_monitor_manager_parent_class)->dispose (object);
-}
-
-static GBytes *
-meta_monitor_manager_real_read_edid (MetaMonitorManager *manager,
- MetaOutput *output)
-{
- return NULL;
-}
-
-static void
-meta_monitor_manager_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- MetaMonitorManager *manager = META_MONITOR_MANAGER (object);
-
- switch (prop_id)
- {
- case PROP_BACKEND:
- manager->backend = g_value_get_object (value);
- break;
- case PROP_PANEL_ORIENTATION_MANAGED:
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- }
-}
-
-static void
-meta_monitor_manager_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- MetaMonitorManager *manager = META_MONITOR_MANAGER (object);
-
- switch (prop_id)
- {
- case PROP_BACKEND:
- g_value_set_object (value, manager->backend);
- break;
- case PROP_PANEL_ORIENTATION_MANAGED:
- g_value_set_boolean (value, manager->panel_orientation_managed);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- }
-}
-
-static void
-meta_monitor_manager_class_init (MetaMonitorManagerClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- object_class->constructed = meta_monitor_manager_constructed;
- object_class->dispose = meta_monitor_manager_dispose;
- object_class->finalize = meta_monitor_manager_finalize;
- object_class->get_property = meta_monitor_manager_get_property;
- object_class->set_property = meta_monitor_manager_set_property;
-
- klass->read_edid = meta_monitor_manager_real_read_edid;
- klass->read_current_state = meta_monitor_manager_real_read_current_state;
-
- signals[MONITORS_CHANGED] =
- g_signal_new ("monitors-changed",
- G_TYPE_FROM_CLASS (object_class),
- G_SIGNAL_RUN_LAST,
- 0,
- NULL, NULL, NULL,
- G_TYPE_NONE, 0);
-
- signals[MONITORS_CHANGED_INTERNAL] =
- g_signal_new ("monitors-changed-internal",
- G_TYPE_FROM_CLASS (object_class),
- G_SIGNAL_RUN_LAST,
- 0,
- NULL, NULL, NULL,
- G_TYPE_NONE, 0);
-
- signals[POWER_SAVE_MODE_CHANGED] =
- g_signal_new ("power-save-mode-changed",
- G_TYPE_FROM_CLASS (object_class),
- G_SIGNAL_RUN_LAST,
- 0,
- NULL, NULL, NULL,
- G_TYPE_NONE, 0);
-
- signals[CONFIRM_DISPLAY_CHANGE] =
- g_signal_new ("confirm-display-change",
- G_TYPE_FROM_CLASS (object_class),
- G_SIGNAL_RUN_LAST,
- 0,
- NULL, NULL, NULL,
- G_TYPE_NONE, 0);
-
- obj_props[PROP_BACKEND] =
- g_param_spec_object ("backend",
- "backend",
- "MetaBackend",
- META_TYPE_BACKEND,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT_ONLY |
- G_PARAM_STATIC_STRINGS);
-
- obj_props[PROP_PANEL_ORIENTATION_MANAGED] =
- g_param_spec_boolean ("panel-orientation-managed",
- "Panel orientation managed",
- "Panel orientation is managed",
- FALSE,
- G_PARAM_READABLE |
- G_PARAM_EXPLICIT_NOTIFY |
- G_PARAM_STATIC_STRINGS);
- g_object_class_install_properties (object_class, PROP_LAST, obj_props);
-}
-
-gboolean
-meta_monitor_has_aspect_as_size (MetaMonitor *monitor)
-{
- int width_mm;
- int height_mm;
-
- meta_monitor_get_physical_dimensions (monitor, &width_mm, &height_mm);
-
- return (width_mm == 1600 && height_mm == 900) ||
- (width_mm == 1600 && height_mm == 1000) ||
- (width_mm == 160 && height_mm == 90) ||
- (width_mm == 160 && height_mm == 100) ||
- (width_mm == 16 && height_mm == 9) ||
- (width_mm == 16 && height_mm == 10);
-}
-
-static const char *
-get_connector_type_name (MetaConnectorType connector_type)
-{
- switch (connector_type)
- {
- case META_CONNECTOR_TYPE_Unknown: return "Unknown";
- case META_CONNECTOR_TYPE_VGA: return "VGA";
- case META_CONNECTOR_TYPE_DVII: return "DVII";
- case META_CONNECTOR_TYPE_DVID: return "DVID";
- case META_CONNECTOR_TYPE_DVIA: return "DVIA";
- case META_CONNECTOR_TYPE_Composite: return "Composite";
- case META_CONNECTOR_TYPE_SVIDEO: return "SVIDEO";
- case META_CONNECTOR_TYPE_LVDS: return "LVDS";
- case META_CONNECTOR_TYPE_Component: return "Component";
- case META_CONNECTOR_TYPE_9PinDIN: return "9PinDIN";
- case META_CONNECTOR_TYPE_DisplayPort: return "DisplayPort";
- case META_CONNECTOR_TYPE_HDMIA: return "HDMIA";
- case META_CONNECTOR_TYPE_HDMIB: return "HDMIB";
- case META_CONNECTOR_TYPE_TV: return "TV";
- case META_CONNECTOR_TYPE_eDP: return "eDP";
- case META_CONNECTOR_TYPE_VIRTUAL: return "VIRTUAL";
- case META_CONNECTOR_TYPE_DSI: return "DSI";
- default: g_assert_not_reached ();
- }
- return NULL;
-}
-
-static GList *
-combine_gpu_lists (MetaMonitorManager *manager,
- GList * (*list_getter) (MetaGpu *gpu))
-{
- GList *gpus;
- GList *list = NULL;
- GList *l;
-
- gpus = meta_backend_get_gpus (manager->backend);
- for (l = gpus; l; l = l->next)
- {
- MetaGpu *gpu = l->data;
-
- list = g_list_concat (list, g_list_copy (list_getter (gpu)));
- }
-
- return list;
-}
-
-static gboolean
-meta_monitor_manager_handle_get_resources (MetaDBusDisplayConfig *skeleton,
- GDBusMethodInvocation *invocation,
- MetaMonitorManager *manager)
-{
- MetaMonitorManagerClass *manager_class = META_MONITOR_MANAGER_GET_CLASS (manager);
- GList *combined_modes;
- GList *combined_outputs;
- GList *combined_crtcs;
- GVariantBuilder crtc_builder, output_builder, mode_builder;
- GList *l;
- unsigned int i, j;
- int max_screen_width;
- int max_screen_height;
-
- combined_modes = combine_gpu_lists (manager, meta_gpu_get_modes);
- combined_outputs = combine_gpu_lists (manager, meta_gpu_get_outputs);
- combined_crtcs = combine_gpu_lists (manager, meta_gpu_get_crtcs);
-
- g_variant_builder_init (&crtc_builder, G_VARIANT_TYPE ("a(uxiiiiiuaua{sv})"));
- g_variant_builder_init (&output_builder, G_VARIANT_TYPE ("a(uxiausauaua{sv})"));
- g_variant_builder_init (&mode_builder, G_VARIANT_TYPE ("a(uxuudu)"));
-
- for (l = combined_crtcs, i = 0; l; l = l->next, i++)
- {
- MetaCrtc *crtc = l->data;
- GVariantBuilder transforms;
- const MetaCrtcConfig *crtc_config;
-
- g_variant_builder_init (&transforms, G_VARIANT_TYPE ("au"));
- for (j = 0; j <= META_MONITOR_TRANSFORM_FLIPPED_270; j++)
- {
- if (meta_crtc_get_all_transforms (crtc) & (1 << j))
- g_variant_builder_add (&transforms, "u", j);
- }
-
- crtc_config = meta_crtc_get_config (crtc);
- if (crtc_config)
- {
- int current_mode_index;
-
- current_mode_index = g_list_index (combined_modes, crtc_config->mode);
- g_variant_builder_add (&crtc_builder, "(uxiiiiiuaua{sv})",
- i, /* ID */
- (int64_t) meta_crtc_get_id (crtc),
- (int) roundf (crtc_config->layout.origin.x),
- (int) roundf (crtc_config->layout.origin.y),
- (int) roundf (crtc_config->layout.size.width),
- (int) roundf (crtc_config->layout.size.height),
- current_mode_index,
- (uint32_t) crtc_config->transform,
- &transforms,
- NULL /* properties */);
- }
- else
- {
- g_variant_builder_add (&crtc_builder, "(uxiiiiiuaua{sv})",
- i, /* ID */
- (int64_t) meta_crtc_get_id (crtc),
- 0,
- 0,
- 0,
- 0,
- -1,
- (uint32_t) META_MONITOR_TRANSFORM_NORMAL,
- &transforms,
- NULL /* properties */);
- }
- }
-
- for (l = combined_outputs, i = 0; l; l = l->next, i++)
- {
- MetaOutput *output = l->data;
- const MetaOutputInfo *output_info = meta_output_get_info (output);
- GVariantBuilder crtcs, modes, clones, properties;
- GBytes *edid;
- MetaCrtc *crtc;
- int crtc_index;
- int backlight;
- int min_backlight_step;
- gboolean is_primary;
- gboolean is_presentation;
- const char * connector_type_name;
- gboolean is_underscanning;
- gboolean supports_underscanning;
- gboolean supports_color_transform;
-
- g_variant_builder_init (&crtcs, G_VARIANT_TYPE ("au"));
- for (j = 0; j < output_info->n_possible_crtcs; j++)
- {
- MetaCrtc *possible_crtc = output_info->possible_crtcs[j];
- unsigned possible_crtc_index;
-
- possible_crtc_index = g_list_index (combined_crtcs, possible_crtc);
- g_variant_builder_add (&crtcs, "u", possible_crtc_index);
- }
-
- g_variant_builder_init (&modes, G_VARIANT_TYPE ("au"));
- for (j = 0; j < output_info->n_modes; j++)
- {
- unsigned mode_index;
-
- mode_index = g_list_index (combined_modes, output_info->modes[j]);
- g_variant_builder_add (&modes, "u", mode_index);
- }
-
- g_variant_builder_init (&clones, G_VARIANT_TYPE ("au"));
- for (j = 0; j < output_info->n_possible_clones; j++)
- {
- unsigned int possible_clone_index;
-
- possible_clone_index = g_list_index (combined_outputs,
- output_info->possible_clones[j]);
- g_variant_builder_add (&clones, "u", possible_clone_index);
- }
-
- backlight = meta_output_get_backlight (output);
- min_backlight_step =
- output_info->backlight_max - output_info->backlight_min
- ? 100 / (output_info->backlight_max - output_info->backlight_min)
- : -1;
- is_primary = meta_output_is_primary (output);
- is_presentation = meta_output_is_presentation (output);
- is_underscanning = meta_output_is_underscanning (output);
- connector_type_name = get_connector_type_name (output_info->connector_type);
- supports_underscanning = output_info->supports_underscanning;
- supports_color_transform = output_info->supports_color_transform;
-
- g_variant_builder_init (&properties, G_VARIANT_TYPE ("a{sv}"));
- g_variant_builder_add (&properties, "{sv}", "vendor",
- g_variant_new_string (output_info->vendor));
- g_variant_builder_add (&properties, "{sv}", "product",
- g_variant_new_string (output_info->product));
- g_variant_builder_add (&properties, "{sv}", "serial",
- g_variant_new_string (output_info->serial));
- g_variant_builder_add (&properties, "{sv}", "width-mm",
- g_variant_new_int32 (output_info->width_mm));
- g_variant_builder_add (&properties, "{sv}", "height-mm",
- g_variant_new_int32 (output_info->height_mm));
- g_variant_builder_add (&properties, "{sv}", "display-name",
- g_variant_new_string (output_info->name));
- g_variant_builder_add (&properties, "{sv}", "backlight",
- g_variant_new_int32 (backlight));
- g_variant_builder_add (&properties, "{sv}", "min-backlight-step",
- g_variant_new_int32 (min_backlight_step));
- g_variant_builder_add (&properties, "{sv}", "primary",
- g_variant_new_boolean (is_primary));
- g_variant_builder_add (&properties, "{sv}", "presentation",
- g_variant_new_boolean (is_presentation));
- g_variant_builder_add (&properties, "{sv}", "connector-type",
- g_variant_new_string (connector_type_name));
- g_variant_builder_add (&properties, "{sv}", "underscanning",
- g_variant_new_boolean (is_underscanning));
- g_variant_builder_add (&properties, "{sv}", "supports-underscanning",
- g_variant_new_boolean (supports_underscanning));
- g_variant_builder_add (&properties, "{sv}", "supports-color-transform",
- g_variant_new_boolean (supports_color_transform));
-
- edid = manager_class->read_edid (manager, output);
- if (edid)
- {
- g_variant_builder_add (&properties, "{sv}", "edid",
- g_variant_new_from_bytes (G_VARIANT_TYPE ("ay"),
- edid, TRUE));
- g_bytes_unref (edid);
- }
-
- if (output_info->tile_info.group_id)
- {
- GVariant *tile_variant;
-
- tile_variant = g_variant_new ("(uuuuuuuu)",
- output_info->tile_info.group_id,
- output_info->tile_info.flags,
- output_info->tile_info.max_h_tiles,
- output_info->tile_info.max_v_tiles,
- output_info->tile_info.loc_h_tile,
- output_info->tile_info.loc_v_tile,
- output_info->tile_info.tile_w,
- output_info->tile_info.tile_h);
- g_variant_builder_add (&properties, "{sv}", "tile", tile_variant);
- }
-
- crtc = meta_output_get_assigned_crtc (output);
- crtc_index = crtc ? g_list_index (combined_crtcs, crtc) : -1;
- g_variant_builder_add (&output_builder, "(uxiausauaua{sv})",
- i, /* ID */
- meta_output_get_id (output),
- crtc_index,
- &crtcs,
- meta_output_get_name (output),
- &modes,
- &clones,
- &properties);
- }
-
- for (l = combined_modes, i = 0; l; l = l->next, i++)
- {
- MetaCrtcMode *mode = l->data;
- const MetaCrtcModeInfo *crtc_mode_info =
- meta_crtc_mode_get_info (mode);
-
- g_variant_builder_add (&mode_builder, "(uxuudu)",
- i, /* ID */
- (int64_t) meta_crtc_mode_get_id (mode),
- (uint32_t) crtc_mode_info->width,
- (uint32_t) crtc_mode_info->height,
- (double) crtc_mode_info->refresh_rate,
- (uint32_t) crtc_mode_info->flags);
- }
-
- if (!meta_monitor_manager_get_max_screen_size (manager,
- &max_screen_width,
- &max_screen_height))
- {
- /* No max screen size, just send something large */
- max_screen_width = 65535;
- max_screen_height = 65535;
- }
-
- meta_dbus_display_config_complete_get_resources (skeleton,
- invocation,
- manager->serial,
- g_variant_builder_end (&crtc_builder),
- g_variant_builder_end (&output_builder),
- g_variant_builder_end (&mode_builder),
- max_screen_width,
- max_screen_height);
-
- g_list_free (combined_modes);
- g_list_free (combined_outputs);
- g_list_free (combined_crtcs);
-
- return TRUE;
-}
-
-static void
-restore_previous_config (MetaMonitorManager *manager)
-{
- MetaMonitorsConfig *previous_config;
- GError *error = NULL;
-
- previous_config =
- meta_monitor_config_manager_pop_previous (manager->config_manager);
-
- if (previous_config)
- {
- MetaMonitorsConfigMethod method;
-
- method = META_MONITORS_CONFIG_METHOD_TEMPORARY;
- if (meta_monitor_manager_apply_monitors_config (manager,
- previous_config,
- method,
- &error))
- {
- g_object_unref (previous_config);
- return;
- }
- else
- {
- g_object_unref (previous_config);
- g_warning ("Failed to restore previous configuration: %s",
- error->message);
- g_error_free (error);
- }
- }
-
- meta_monitor_manager_ensure_configured (manager);
-}
-
-gint
-meta_monitor_manager_get_display_configuration_timeout (void)
-{
- return DEFAULT_DISPLAY_CONFIGURATION_TIMEOUT;
-}
-
-static gboolean
-save_config_timeout (gpointer user_data)
-{
- MetaMonitorManager *manager = user_data;
-
- restore_previous_config (manager);
- manager->persistent_timeout_id = 0;
-
- return G_SOURCE_REMOVE;
-}
-
-static void
-cancel_persistent_confirmation (MetaMonitorManager *manager)
-{
- g_clear_handle_id (&manager->persistent_timeout_id, g_source_remove);
-}
-
-static void
-request_persistent_confirmation (MetaMonitorManager *manager)
-{
- manager->persistent_timeout_id = g_timeout_add_seconds (meta_monitor_manager_get_display_configuration_timeout (),
- save_config_timeout,
- manager);
- g_source_set_name_by_id (manager->persistent_timeout_id,
- "[mutter] save_config_timeout");
-
- g_signal_emit (manager, signals[CONFIRM_DISPLAY_CHANGE], 0);
-}
-
-#define META_DISPLAY_CONFIG_MODE_FLAGS_PREFERRED (1 << 0)
-#define META_DISPLAY_CONFIG_MODE_FLAGS_CURRENT (1 << 1)
-
-#define MODE_FORMAT "(siiddada{sv})"
-#define MODES_FORMAT "a" MODE_FORMAT
-#define MONITOR_SPEC_FORMAT "(ssss)"
-#define MONITOR_FORMAT "(" MONITOR_SPEC_FORMAT MODES_FORMAT "a{sv})"
-#define MONITORS_FORMAT "a" MONITOR_FORMAT
-
-#define LOGICAL_MONITOR_MONITORS_FORMAT "a" MONITOR_SPEC_FORMAT
-#define LOGICAL_MONITOR_FORMAT "(iidub" LOGICAL_MONITOR_MONITORS_FORMAT "a{sv})"
-#define LOGICAL_MONITORS_FORMAT "a" LOGICAL_MONITOR_FORMAT
-
-static gboolean
-meta_monitor_manager_handle_get_current_state (MetaDBusDisplayConfig *skeleton,
- GDBusMethodInvocation *invocation,
- MetaMonitorManager *manager)
-{
- MetaSettings *settings = meta_backend_get_settings (manager->backend);
- GVariantBuilder monitors_builder;
- GVariantBuilder logical_monitors_builder;
- GVariantBuilder properties_builder;
- GList *l;
- int i;
- MetaMonitorManagerCapability capabilities;
- int ui_scaling_factor;
- int max_screen_width, max_screen_height;
-
- g_variant_builder_init (&monitors_builder,
- G_VARIANT_TYPE (MONITORS_FORMAT));
- g_variant_builder_init (&logical_monitors_builder,
- G_VARIANT_TYPE (LOGICAL_MONITORS_FORMAT));
-
- for (l = manager->monitors; l; l = l->next)
- {
- MetaMonitor *monitor = l->data;
- MetaMonitorSpec *monitor_spec = meta_monitor_get_spec (monitor);
- MetaMonitorMode *current_mode;
- MetaMonitorMode *preferred_mode;
- GVariantBuilder modes_builder;
- GVariantBuilder monitor_properties_builder;
- GList *k;
- gboolean is_builtin;
- const char *display_name;
-
- current_mode = meta_monitor_get_current_mode (monitor);
- preferred_mode = meta_monitor_get_preferred_mode (monitor);
-
- g_variant_builder_init (&modes_builder, G_VARIANT_TYPE (MODES_FORMAT));
- for (k = meta_monitor_get_modes (monitor); k; k = k->next)
- {
- MetaMonitorMode *monitor_mode = k->data;
- GVariantBuilder supported_scales_builder;
- const char *mode_id;
- int mode_width, mode_height;
- float refresh_rate;
- float preferred_scale;
- float *supported_scales;
- int n_supported_scales;
- GVariantBuilder mode_properties_builder;
- MetaCrtcModeFlag mode_flags;
-
- if (!meta_monitor_mode_should_be_advertised (monitor_mode))
- continue;
-
- mode_id = meta_monitor_mode_get_id (monitor_mode);
- meta_monitor_mode_get_resolution (monitor_mode,
- &mode_width, &mode_height);
-
- refresh_rate = meta_monitor_mode_get_refresh_rate (monitor_mode);
-
- preferred_scale =
- meta_monitor_manager_calculate_monitor_mode_scale (manager,
- monitor,
- monitor_mode);
-
- g_variant_builder_init (&supported_scales_builder,
- G_VARIANT_TYPE ("ad"));
- supported_scales =
- meta_monitor_manager_calculate_supported_scales (manager,
- manager->layout_mode,
- monitor,
- monitor_mode,
- &n_supported_scales);
- for (i = 0; i < n_supported_scales; i++)
- g_variant_builder_add (&supported_scales_builder, "d",
- (double) supported_scales[i]);
- g_free (supported_scales);
-
- mode_flags = meta_monitor_mode_get_flags (monitor_mode);
-
- g_variant_builder_init (&mode_properties_builder,
- G_VARIANT_TYPE ("a{sv}"));
- if (monitor_mode == current_mode)
- g_variant_builder_add (&mode_properties_builder, "{sv}",
- "is-current",
- g_variant_new_boolean (TRUE));
- if (monitor_mode == preferred_mode)
- g_variant_builder_add (&mode_properties_builder, "{sv}",
- "is-preferred",
- g_variant_new_boolean (TRUE));
- if (mode_flags & META_CRTC_MODE_FLAG_INTERLACE)
- g_variant_builder_add (&mode_properties_builder, "{sv}",
- "is-interlaced",
- g_variant_new_boolean (TRUE));
-
- g_variant_builder_add (&modes_builder, MODE_FORMAT,
- mode_id,
- mode_width,
- mode_height,
- refresh_rate,
- (double) preferred_scale,
- &supported_scales_builder,
- &mode_properties_builder);
- }
-
- g_variant_builder_init (&monitor_properties_builder,
- G_VARIANT_TYPE ("a{sv}"));
- if (meta_monitor_supports_underscanning (monitor))
- {
- gboolean is_underscanning = meta_monitor_is_underscanning (monitor);
-
- g_variant_builder_add (&monitor_properties_builder, "{sv}",
- "is-underscanning",
- g_variant_new_boolean (is_underscanning));
- }
-
- is_builtin = meta_monitor_is_laptop_panel (monitor);
- g_variant_builder_add (&monitor_properties_builder, "{sv}",
- "is-builtin",
- g_variant_new_boolean (is_builtin));
-
- display_name = meta_monitor_get_display_name (monitor);
- g_variant_builder_add (&monitor_properties_builder, "{sv}",
- "display-name",
- g_variant_new_string (display_name));
-
- g_variant_builder_add (&monitors_builder, MONITOR_FORMAT,
- monitor_spec->connector,
- monitor_spec->vendor,
- monitor_spec->product,
- monitor_spec->serial,
- &modes_builder,
- &monitor_properties_builder);
- }
-
- for (l = manager->logical_monitors; l; l = l->next)
- {
- MetaLogicalMonitor *logical_monitor = l->data;
- GVariantBuilder logical_monitor_monitors_builder;
- GList *k;
-
- g_variant_builder_init (&logical_monitor_monitors_builder,
- G_VARIANT_TYPE (LOGICAL_MONITOR_MONITORS_FORMAT));
-
- for (k = logical_monitor->monitors; k; k = k->next)
- {
- MetaMonitor *monitor = k->data;
- MetaMonitorSpec *monitor_spec = meta_monitor_get_spec (monitor);
-
- g_variant_builder_add (&logical_monitor_monitors_builder,
- MONITOR_SPEC_FORMAT,
- monitor_spec->connector,
- monitor_spec->vendor,
- monitor_spec->product,
- monitor_spec->serial);
- }
-
- g_variant_builder_add (&logical_monitors_builder,
- LOGICAL_MONITOR_FORMAT,
- logical_monitor->rect.x,
- logical_monitor->rect.y,
- (double) logical_monitor->scale,
- logical_monitor->transform,
- logical_monitor->is_primary,
- &logical_monitor_monitors_builder,
- NULL);
- }
-
- g_variant_builder_init (&properties_builder, G_VARIANT_TYPE ("a{sv}"));
- capabilities = meta_monitor_manager_get_capabilities (manager);
-
- g_variant_builder_add (&properties_builder, "{sv}",
- "layout-mode",
- g_variant_new_uint32 (manager->layout_mode));
- if (capabilities & META_MONITOR_MANAGER_CAPABILITY_LAYOUT_MODE)
- {
- g_variant_builder_add (&properties_builder, "{sv}",
- "supports-changing-layout-mode",
- g_variant_new_boolean (TRUE));
- }
-
- if (capabilities & META_MONITOR_MANAGER_CAPABILITY_GLOBAL_SCALE_REQUIRED)
- {
- g_variant_builder_add (&properties_builder, "{sv}",
- "global-scale-required",
- g_variant_new_boolean (TRUE));
- }
-
- ui_scaling_factor = meta_settings_get_ui_scaling_factor (settings);
- g_variant_builder_add (&properties_builder, "{sv}",
- "legacy-ui-scaling-factor",
- g_variant_new_int32 (ui_scaling_factor));
-
- if (meta_monitor_manager_get_max_screen_size (manager,
- &max_screen_width,
- &max_screen_height))
- {
- GVariantBuilder max_screen_size_builder;
-
- g_variant_builder_init (&max_screen_size_builder,
- G_VARIANT_TYPE ("(ii)"));
- g_variant_builder_add (&max_screen_size_builder, "i",
- max_screen_width);
- g_variant_builder_add (&max_screen_size_builder, "i",
- max_screen_height);
-
- g_variant_builder_add (&properties_builder, "{sv}",
- "max-screen-size",
- g_variant_builder_end (&max_screen_size_builder));
- }
-
- meta_dbus_display_config_complete_get_current_state (
- skeleton,
- invocation,
- manager->serial,
- g_variant_builder_end (&monitors_builder),
- g_variant_builder_end (&logical_monitors_builder),
- g_variant_builder_end (&properties_builder));
-
- return TRUE;
-}
-
-#undef MODE_FORMAT
-#undef MODES_FORMAT
-#undef MONITOR_SPEC_FORMAT
-#undef MONITOR_FORMAT
-#undef MONITORS_FORMAT
-#undef LOGICAL_MONITOR_MONITORS_FORMAT
-#undef LOGICAL_MONITOR_FORMAT
-#undef LOGICAL_MONITORS_FORMAT
-
-gboolean
-meta_monitor_manager_is_scale_supported (MetaMonitorManager *manager,
- MetaLogicalMonitorLayoutMode layout_mode,
- MetaMonitor *monitor,
- MetaMonitorMode *monitor_mode,
- float scale)
-{
- g_autofree float *supported_scales = NULL;
- int n_supported_scales;
- int i;
-
- supported_scales =
- meta_monitor_manager_calculate_supported_scales (manager,
- layout_mode,
- monitor,
- monitor_mode,
- &n_supported_scales);
- for (i = 0; i < n_supported_scales; i++)
- {
- if (supported_scales[i] == scale)
- return TRUE;
- }
-
- return FALSE;
-}
-
-static gboolean
-meta_monitor_manager_is_config_applicable (MetaMonitorManager *manager,
- MetaMonitorsConfig *config,
- GError **error)
-{
- GList *l;
-
- for (l = config->logical_monitor_configs; l; l = l->next)
- {
- MetaLogicalMonitorConfig *logical_monitor_config = l->data;
- float scale = logical_monitor_config->scale;
- GList *k;
-
- for (k = logical_monitor_config->monitor_configs; k; k = k->next)
- {
- MetaMonitorConfig *monitor_config = k->data;
- MetaMonitorSpec *monitor_spec = monitor_config->monitor_spec;
- MetaMonitorModeSpec *mode_spec = monitor_config->mode_spec;
- MetaMonitor *monitor;
- MetaMonitorMode *monitor_mode;
-
- monitor = meta_monitor_manager_get_monitor_from_spec (manager,
- monitor_spec);
- if (!monitor)
- {
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- "Specified monitor not found");
- return FALSE;
- }
-
- monitor_mode = meta_monitor_get_mode_from_spec (monitor, mode_spec);
- if (!monitor_mode)
- {
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- "Specified monitor mode not available");
- return FALSE;
- }
-
- if (!meta_monitor_manager_is_scale_supported (manager,
- config->layout_mode,
- monitor,
- monitor_mode,
- scale))
- {
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- "Scale not supported by backend");
- return FALSE;
- }
-
- if (meta_monitor_is_laptop_panel (monitor) &&
- meta_backend_is_lid_closed (manager->backend))
- {
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- "Refusing to activate a closed laptop panel");
- return FALSE;
- }
- }
- }
-
- return TRUE;
-}
-
-static gboolean
-meta_monitor_manager_is_config_complete (MetaMonitorManager *manager,
- MetaMonitorsConfig *config)
-{
- MetaMonitorsConfigKey *current_state_key;
- gboolean is_config_complete;
-
- current_state_key =
- meta_create_monitors_config_key_for_current_state (manager);
- if (!current_state_key)
- return FALSE;
-
- is_config_complete = meta_monitors_config_key_equal (current_state_key,
- config->key);
- meta_monitors_config_key_free (current_state_key);
-
- if (!is_config_complete)
- return FALSE;
-
- return meta_monitor_manager_is_config_applicable (manager, config, NULL);
-}
-
-static MetaMonitor *
-find_monitor_from_connector (MetaMonitorManager *manager,
- char *connector)
-{
- GList *monitors;
- GList *l;
-
- if (!connector)
- return NULL;
-
- monitors = meta_monitor_manager_get_monitors (manager);
- for (l = monitors; l; l = l->next)
- {
- MetaMonitor *monitor = l->data;
- MetaMonitorSpec *monitor_spec = meta_monitor_get_spec (monitor);
-
- if (g_str_equal (connector, monitor_spec->connector))
- return monitor;
- }
-
- return NULL;
-}
-
-#define MONITOR_CONFIG_FORMAT "(ssa{sv})"
-#define MONITOR_CONFIGS_FORMAT "a" MONITOR_CONFIG_FORMAT
-
-#define LOGICAL_MONITOR_CONFIG_FORMAT "(iidub" MONITOR_CONFIGS_FORMAT ")"
-
-static MetaMonitorConfig *
-create_monitor_config_from_variant (MetaMonitorManager *manager,
- GVariant *monitor_config_variant,
- GError **error)
-{
-
- MetaMonitorConfig *monitor_config = NULL;
- g_autofree char *connector = NULL;
- g_autofree char *mode_id = NULL;
- MetaMonitorMode *monitor_mode;
- MetaMonitor *monitor;
- MetaMonitorSpec *monitor_spec;
- MetaMonitorModeSpec *monitor_mode_spec;
- g_autoptr (GVariant) properties_variant = NULL;
- gboolean enable_underscanning = FALSE;
- gboolean set_underscanning = FALSE;
-
- g_variant_get (monitor_config_variant, "(ss@a{sv})",
- &connector,
- &mode_id,
- &properties_variant);
-
- monitor = find_monitor_from_connector (manager, connector);
- if (!monitor)
- {
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- "Invalid connector '%s' specified", connector);
- return NULL;
- }
-
- monitor_mode = meta_monitor_get_mode_from_id (monitor, mode_id);
- if (!monitor_mode)
- {
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- "Invalid mode '%s' specified", mode_id);
- return NULL;
- }
-
- set_underscanning =
- g_variant_lookup (properties_variant, "underscanning", "b",
- &enable_underscanning);
- if (set_underscanning)
- {
- if (enable_underscanning && !meta_monitor_supports_underscanning (monitor))
- {
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- "Underscanning requested but unsupported");
- return NULL;
- }
- }
-
- monitor_spec = meta_monitor_spec_clone (meta_monitor_get_spec (monitor));
-
- monitor_mode_spec = g_new0 (MetaMonitorModeSpec, 1);
- *monitor_mode_spec = *meta_monitor_mode_get_spec (monitor_mode);
-
- monitor_config = g_new0 (MetaMonitorConfig, 1);
- *monitor_config = (MetaMonitorConfig) {
- .monitor_spec = monitor_spec,
- .mode_spec = monitor_mode_spec,
- .enable_underscanning = enable_underscanning
- };
-
- return monitor_config;
-}
-
-static gboolean
-find_monitor_mode_scale (MetaMonitorManager *manager,
- MetaLogicalMonitorLayoutMode layout_mode,
- MetaMonitorConfig *monitor_config,
- float scale,
- float *out_scale,
- GError **error)
-{
- MetaMonitorSpec *monitor_spec;
- MetaMonitor *monitor;
- MetaMonitorModeSpec *monitor_mode_spec;
- MetaMonitorMode *monitor_mode;
- g_autofree float *supported_scales = NULL;
- int n_supported_scales;
- int i;
-
- monitor_spec = monitor_config->monitor_spec;
- monitor = meta_monitor_manager_get_monitor_from_spec (manager,
- monitor_spec);
- if (!monitor)
- {
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- "Monitor not found");
- return FALSE;
- }
-
- monitor_mode_spec = monitor_config->mode_spec;
- monitor_mode = meta_monitor_get_mode_from_spec (monitor,
- monitor_mode_spec);
- if (!monitor_mode)
- {
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- "Monitor mode not found");
- return FALSE;
- }
-
- supported_scales =
- meta_monitor_manager_calculate_supported_scales (manager, layout_mode,
- monitor, monitor_mode,
- &n_supported_scales);
-
- for (i = 0; i < n_supported_scales; i++)
- {
- float supported_scale = supported_scales[i];
-
- if (fabsf (supported_scale - scale) < FLT_EPSILON)
- {
- *out_scale = supported_scale;
- return TRUE;
- }
- }
-
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- "Scale %g not valid for resolution %dx%d",
- scale,
- monitor_mode_spec->width,
- monitor_mode_spec->height);
- return FALSE;
-}
-
-static gboolean
-derive_logical_monitor_size (MetaMonitorConfig *monitor_config,
- int *out_width,
- int *out_height,
- float scale,
- MetaMonitorTransform transform,
- MetaLogicalMonitorLayoutMode layout_mode,
- GError **error)
-{
- int width, height;
-
- if (meta_monitor_transform_is_rotated (transform))
- {
- width = monitor_config->mode_spec->height;
- height = monitor_config->mode_spec->width;
- }
- else
- {
- width = monitor_config->mode_spec->width;
- height = monitor_config->mode_spec->height;
- }
-
- switch (layout_mode)
- {
- case META_LOGICAL_MONITOR_LAYOUT_MODE_LOGICAL:
- width = roundf (width / scale);
- height = roundf (height / scale);
- break;
- case META_LOGICAL_MONITOR_LAYOUT_MODE_PHYSICAL:
- break;
- }
-
- *out_width = width;
- *out_height = height;
-
- return TRUE;
-}
-
-static MetaLogicalMonitorConfig *
-create_logical_monitor_config_from_variant (MetaMonitorManager *manager,
- GVariant *logical_monitor_config_variant,
- MetaLogicalMonitorLayoutMode layout_mode,
- GError **error)
-{
- MetaLogicalMonitorConfig *logical_monitor_config;
- int x, y, width, height;
- double scale_d;
- float scale;
- MetaMonitorTransform transform;
- gboolean is_primary;
- GVariantIter *monitor_configs_iter;
- GList *monitor_configs = NULL;
- MetaMonitorConfig *monitor_config;
-
- g_variant_get (logical_monitor_config_variant, LOGICAL_MONITOR_CONFIG_FORMAT,
- &x,
- &y,
- &scale_d,
- &transform,
- &is_primary,
- &monitor_configs_iter);
- scale = (float) scale_d;
-
- while (TRUE)
- {
- GVariant *monitor_config_variant =
- g_variant_iter_next_value (monitor_configs_iter);
- MetaMonitorConfig *monitor_config;
-
- if (!monitor_config_variant)
- break;
-
- monitor_config =
- create_monitor_config_from_variant (manager,
- monitor_config_variant, error);
- g_variant_unref (monitor_config_variant);
-
- if (!monitor_config)
- goto err;
-
- if (!meta_verify_monitor_config (monitor_config, error))
- {
- meta_monitor_config_free (monitor_config);
- goto err;
- }
-
- monitor_configs = g_list_append (monitor_configs, monitor_config);
- }
- g_variant_iter_free (monitor_configs_iter);
-
- if (!monitor_configs)
- {
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- "Empty logical monitor");
- goto err;
- }
-
- monitor_config = monitor_configs->data;
- if (!find_monitor_mode_scale (manager,
- layout_mode,
- monitor_config,
- scale,
- &scale,
- error))
- goto err;
-
- if (!derive_logical_monitor_size (monitor_config, &width, &height,
- scale, transform, layout_mode, error))
- goto err;
-
- logical_monitor_config = g_new0 (MetaLogicalMonitorConfig, 1);
- *logical_monitor_config = (MetaLogicalMonitorConfig) {
- .layout = {
- .x = x,
- .y = y,
- .width = width,
- .height = height
- },
- .transform = transform,
- .scale = scale,
- .is_primary = is_primary,
- .monitor_configs = monitor_configs
- };
-
- if (!meta_verify_logical_monitor_config (logical_monitor_config,
- layout_mode,
- manager,
- error))
- {
- meta_logical_monitor_config_free (logical_monitor_config);
- return NULL;
- }
-
- return logical_monitor_config;
-
-err:
- g_list_free_full (monitor_configs, (GDestroyNotify) meta_monitor_config_free);
- return NULL;
-}
-
-static gboolean
-is_valid_layout_mode (MetaLogicalMonitorLayoutMode layout_mode)
-{
- switch (layout_mode)
- {
- case META_LOGICAL_MONITOR_LAYOUT_MODE_LOGICAL:
- case META_LOGICAL_MONITOR_LAYOUT_MODE_PHYSICAL:
- return TRUE;
- }
-
- return FALSE;
-}
-
-static gboolean
-meta_monitor_manager_handle_apply_monitors_config (MetaDBusDisplayConfig *skeleton,
- GDBusMethodInvocation *invocation,
- guint serial,
- guint method,
- GVariant *logical_monitor_configs_variant,
- GVariant *properties_variant,
- MetaMonitorManager *manager)
-{
- MetaMonitorManagerCapability capabilities;
- GVariant *layout_mode_variant = NULL;
- MetaLogicalMonitorLayoutMode layout_mode;
- GVariantIter logical_monitor_configs_iter;
- MetaMonitorsConfig *config;
- GList *logical_monitor_configs = NULL;
- GError *error = NULL;
-
- if (serial != manager->serial)
- {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_ACCESS_DENIED,
- "The requested configuration is based on stale information");
- return TRUE;
- }
-
- capabilities = meta_monitor_manager_get_capabilities (manager);
-
- if (properties_variant)
- layout_mode_variant = g_variant_lookup_value (properties_variant,
- "layout-mode",
- G_VARIANT_TYPE ("u"));
-
- if (layout_mode_variant &&
- capabilities & META_MONITOR_MANAGER_CAPABILITY_LAYOUT_MODE)
- {
- g_variant_get (layout_mode_variant, "u", &layout_mode);
- }
- else if (!layout_mode_variant)
- {
- layout_mode =
- meta_monitor_manager_get_default_layout_mode (manager);
- }
- else
- {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_INVALID_ARGS,
- "Can't set layout mode");
- return TRUE;
- }
-
- if (!is_valid_layout_mode (layout_mode))
- {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_ACCESS_DENIED,
- "Invalid layout mode specified");
- return TRUE;
- }
-
- g_variant_iter_init (&logical_monitor_configs_iter,
- logical_monitor_configs_variant);
- while (TRUE)
- {
- GVariant *logical_monitor_config_variant =
- g_variant_iter_next_value (&logical_monitor_configs_iter);
- MetaLogicalMonitorConfig *logical_monitor_config;
-
- if (!logical_monitor_config_variant)
- break;
-
- logical_monitor_config =
- create_logical_monitor_config_from_variant (manager,
- logical_monitor_config_variant,
- layout_mode,
- &error);
- g_variant_unref (logical_monitor_config_variant);
-
- if (!logical_monitor_config)
- {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_INVALID_ARGS,
- "%s", error->message);
- g_error_free (error);
- g_list_free_full (logical_monitor_configs,
- (GDestroyNotify) meta_logical_monitor_config_free);
- return TRUE;
- }
-
- logical_monitor_configs = g_list_append (logical_monitor_configs,
- logical_monitor_config);
- }
-
- config = meta_monitors_config_new (manager,
- logical_monitor_configs,
- layout_mode,
- META_MONITORS_CONFIG_FLAG_NONE);
- if (!meta_verify_monitors_config (config, manager, &error))
- {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_INVALID_ARGS,
- "%s", error->message);
- g_error_free (error);
- g_object_unref (config);
- return TRUE;
- }
-
- if (!meta_monitor_manager_is_config_applicable (manager, config, &error))
- {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_INVALID_ARGS,
- "%s", error->message);
- g_error_free (error);
- g_object_unref (config);
- return TRUE;
- }
-
- if (manager->persistent_timeout_id &&
- method != META_MONITORS_CONFIG_METHOD_VERIFY)
- cancel_persistent_confirmation (manager);
-
- if (!meta_monitor_manager_apply_monitors_config (manager,
- config,
- method,
- &error))
- {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_INVALID_ARGS,
- "%s", error->message);
- g_error_free (error);
- g_object_unref (config);
- return TRUE;
- }
-
- if (method == META_MONITORS_CONFIG_METHOD_PERSISTENT)
- request_persistent_confirmation (manager);
-
- meta_dbus_display_config_complete_apply_monitors_config (skeleton, invocation);
-
- return TRUE;
-}
-
-#undef MONITOR_MODE_SPEC_FORMAT
-#undef MONITOR_CONFIG_FORMAT
-#undef MONITOR_CONFIGS_FORMAT
-#undef LOGICAL_MONITOR_CONFIG_FORMAT
-
-static void
-confirm_configuration (MetaMonitorManager *manager,
- gboolean confirmed)
-{
- if (confirmed)
- meta_monitor_config_manager_save_current (manager->config_manager);
- else
- restore_previous_config (manager);
-}
-
-void
-meta_monitor_manager_confirm_configuration (MetaMonitorManager *manager,
- gboolean ok)
-{
- if (!manager->persistent_timeout_id)
- {
- /* too late */
- return;
- }
-
- cancel_persistent_confirmation (manager);
- confirm_configuration (manager, ok);
-}
-
-static gboolean
-meta_monitor_manager_handle_change_backlight (MetaDBusDisplayConfig *skeleton,
- GDBusMethodInvocation *invocation,
- guint serial,
- guint output_index,
- gint value,
- MetaMonitorManager *manager)
-{
- GList *combined_outputs;
- MetaOutput *output;
- const MetaOutputInfo *output_info;
- int new_backlight;
-
- if (serial != manager->serial)
- {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_ACCESS_DENIED,
- "The requested configuration is based on stale information");
- return TRUE;
- }
-
- combined_outputs = combine_gpu_lists (manager, meta_gpu_get_outputs);
-
- if (output_index >= g_list_length (combined_outputs))
- {
- g_list_free (combined_outputs);
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_INVALID_ARGS,
- "Invalid output id");
- return TRUE;
- }
- output = g_list_nth_data (combined_outputs, output_index);
- g_list_free (combined_outputs);
-
- if (value < 0 || value > 100)
- {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_INVALID_ARGS,
- "Invalid backlight value");
- return TRUE;
- }
-
- output_info = meta_output_get_info (output);
- if (meta_output_get_backlight (output) == -1 ||
- (output_info->backlight_min == 0 &&
- output_info->backlight_max == 0))
- {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_INVALID_ARGS,
- "Output does not support changing backlight");
- return TRUE;
- }
-
- META_MONITOR_MANAGER_GET_CLASS (manager)->change_backlight (manager, output, value);
-
- new_backlight = meta_output_get_backlight (output);
- meta_dbus_display_config_complete_change_backlight (skeleton,
- invocation,
- new_backlight);
- return TRUE;
-}
-
-static gboolean
-meta_monitor_manager_handle_get_crtc_gamma (MetaDBusDisplayConfig *skeleton,
- GDBusMethodInvocation *invocation,
- guint serial,
- guint crtc_id,
- MetaMonitorManager *manager)
-{
- MetaMonitorManagerClass *klass;
- GList *combined_crtcs;
- MetaCrtc *crtc;
- gsize size;
- unsigned short *red;
- unsigned short *green;
- unsigned short *blue;
- GBytes *red_bytes, *green_bytes, *blue_bytes;
- GVariant *red_v, *green_v, *blue_v;
-
- if (serial != manager->serial)
- {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_ACCESS_DENIED,
- "The requested configuration is based on stale information");
- return TRUE;
- }
-
- combined_crtcs = combine_gpu_lists (manager, meta_gpu_get_crtcs);
- if (crtc_id >= g_list_length (combined_crtcs))
- {
- g_list_free (combined_crtcs);
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_INVALID_ARGS,
- "Invalid crtc id");
- return TRUE;
- }
-
- crtc = g_list_nth_data (combined_crtcs, crtc_id);
- g_list_free (combined_crtcs);
-
- klass = META_MONITOR_MANAGER_GET_CLASS (manager);
- if (klass->get_crtc_gamma)
- klass->get_crtc_gamma (manager, crtc, &size, &red, &green, &blue);
- else
- {
- size = 0;
- red = green = blue = NULL;
- }
-
- red_bytes = g_bytes_new_take (red, size * sizeof (unsigned short));
- green_bytes = g_bytes_new_take (green, size * sizeof (unsigned short));
- blue_bytes = g_bytes_new_take (blue, size * sizeof (unsigned short));
-
- red_v = g_variant_new_from_bytes (G_VARIANT_TYPE ("aq"), red_bytes, TRUE);
- green_v = g_variant_new_from_bytes (G_VARIANT_TYPE ("aq"), green_bytes, TRUE);
- blue_v = g_variant_new_from_bytes (G_VARIANT_TYPE ("aq"), blue_bytes, TRUE);
-
- meta_dbus_display_config_complete_get_crtc_gamma (skeleton, invocation,
- red_v, green_v, blue_v);
-
- g_bytes_unref (red_bytes);
- g_bytes_unref (green_bytes);
- g_bytes_unref (blue_bytes);
-
- return TRUE;
-}
-
-static gboolean
-meta_monitor_manager_handle_set_crtc_gamma (MetaDBusDisplayConfig *skeleton,
- GDBusMethodInvocation *invocation,
- guint serial,
- guint crtc_id,
- GVariant *red_v,
- GVariant *green_v,
- GVariant *blue_v,
- MetaMonitorManager *manager)
-{
- MetaMonitorManagerClass *klass;
- GList *combined_crtcs;
- MetaCrtc *crtc;
- gsize size, dummy;
- unsigned short *red;
- unsigned short *green;
- unsigned short *blue;
- GBytes *red_bytes, *green_bytes, *blue_bytes;
-
- if (serial != manager->serial)
- {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_ACCESS_DENIED,
- "The requested configuration is based on stale information");
- return TRUE;
- }
-
- combined_crtcs = combine_gpu_lists (manager, meta_gpu_get_crtcs);
-
- if (crtc_id >= g_list_length (combined_crtcs))
- {
- g_list_free (combined_crtcs);
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_INVALID_ARGS,
- "Invalid crtc id");
- return TRUE;
- }
-
- crtc = g_list_nth_data (combined_crtcs, crtc_id);
- g_list_free (combined_crtcs);
-
- red_bytes = g_variant_get_data_as_bytes (red_v);
- green_bytes = g_variant_get_data_as_bytes (green_v);
- blue_bytes = g_variant_get_data_as_bytes (blue_v);
-
- size = g_bytes_get_size (red_bytes) / sizeof (unsigned short);
- red = (unsigned short*) g_bytes_get_data (red_bytes, &dummy);
- green = (unsigned short*) g_bytes_get_data (green_bytes, &dummy);
- blue = (unsigned short*) g_bytes_get_data (blue_bytes, &dummy);
-
- klass = META_MONITOR_MANAGER_GET_CLASS (manager);
- if (klass->set_crtc_gamma)
- klass->set_crtc_gamma (manager, crtc, size, red, green, blue);
- meta_dbus_display_config_complete_set_crtc_gamma (skeleton, invocation);
-
- g_bytes_unref (red_bytes);
- g_bytes_unref (green_bytes);
- g_bytes_unref (blue_bytes);
-
- return TRUE;
-}
-
-static gboolean
-meta_monitor_manager_handle_set_output_ctm (MetaDBusDisplayConfig *skeleton,
- GDBusMethodInvocation *invocation,
- guint serial,
- guint output_id,
- GVariant *ctm_var,
- MetaMonitorManager *manager)
-{
- MetaMonitorManagerClass *klass;
- GList *combined_outputs;
- MetaOutput *output;
- MetaOutputCtm ctm;
- int i;
-
- if (serial != manager->serial)
- {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_ACCESS_DENIED,
- "The requested configuration is based on stale information");
- return TRUE;
- }
-
- combined_outputs = combine_gpu_lists (manager, meta_gpu_get_outputs);
-
- if (output_id >= g_list_length (combined_outputs))
- {
- g_list_free (combined_outputs);
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_INVALID_ARGS,
- "Invalid output id");
- return TRUE;
- }
-
- output = g_list_nth_data (combined_outputs, output_id);
- g_list_free (combined_outputs);
-
- if (g_variant_n_children (ctm_var) != 9)
- {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_INVALID_ARGS,
- "Unexpected color transform matrix variant length");
- return TRUE;
- }
-
- for (i = 0; i < 9; i++)
- {
- GVariant *tmp = g_variant_get_child_value (ctm_var, i);
- ctm.matrix[i] = g_variant_get_uint64 (tmp);
- g_variant_unref (tmp);
- }
-
- klass = META_MONITOR_MANAGER_GET_CLASS (manager);
- if (klass->set_output_ctm)
- klass->set_output_ctm (output, &ctm);
- meta_dbus_display_config_complete_set_output_ctm (skeleton, invocation);
-
- return TRUE;
-}
-
-static void
-monitor_manager_setup_dbus_config_handlers (MetaMonitorManager *manager)
-{
- g_signal_connect_object (manager->display_config, "handle-get-resources",
- G_CALLBACK (meta_monitor_manager_handle_get_resources),
- manager, 0);
- g_signal_connect_object (manager->display_config, "handle-change-backlight",
- G_CALLBACK (meta_monitor_manager_handle_change_backlight),
- manager, 0);
- g_signal_connect_object (manager->display_config, "handle-get-crtc-gamma",
- G_CALLBACK (meta_monitor_manager_handle_get_crtc_gamma),
- manager, 0);
- g_signal_connect_object (manager->display_config, "handle-set-crtc-gamma",
- G_CALLBACK (meta_monitor_manager_handle_set_crtc_gamma),
- manager, 0);
- g_signal_connect_object (manager->display_config, "handle-get-current-state",
- G_CALLBACK (meta_monitor_manager_handle_get_current_state),
- manager, 0);
- g_signal_connect_object (manager->display_config, "handle-apply-monitors-config",
- G_CALLBACK (meta_monitor_manager_handle_apply_monitors_config),
- manager, 0);
- g_signal_connect_object (manager->display_config, "handle-set-output-ctm",
- G_CALLBACK (meta_monitor_manager_handle_set_output_ctm),
- manager, 0);
-}
-
-static void
-on_bus_acquired (GDBusConnection *connection,
- const char *name,
- gpointer user_data)
-{
- MetaMonitorManager *manager = user_data;
-
- g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (manager->display_config),
- connection,
- "/org/gnome/Mutter/DisplayConfig",
- NULL);
-}
-
-static void
-on_name_acquired (GDBusConnection *connection,
- const char *name,
- gpointer user_data)
-{
- meta_topic (META_DEBUG_DBUS, "Acquired name %s", name);
-}
-
-static void
-on_name_lost (GDBusConnection *connection,
- const char *name,
- gpointer user_data)
-{
- meta_topic (META_DEBUG_DBUS, "Lost or failed to acquire name %s", name);
-}
-
-static void
-initialize_dbus_interface (MetaMonitorManager *manager)
-{
- MetaContext *context = meta_backend_get_context (manager->backend);
-
- manager->dbus_name_id =
- g_bus_own_name (G_BUS_TYPE_SESSION,
- "org.gnome.Mutter.DisplayConfig",
- G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT |
- (meta_context_is_replacing (context) ?
- G_BUS_NAME_OWNER_FLAGS_REPLACE :
- G_BUS_NAME_OWNER_FLAGS_NONE),
- on_bus_acquired,
- on_name_acquired,
- on_name_lost,
- g_object_ref (manager),
- g_object_unref);
-}
-
-/**
- * meta_monitor_manager_get:
- *
- * Accessor for the singleton MetaMonitorManager.
- *
- * Returns: (transfer none): The only #MetaMonitorManager there is.
- */
-MetaMonitorManager *
-meta_monitor_manager_get (void)
-{
- MetaBackend *backend = meta_get_backend ();
-
- return meta_backend_get_monitor_manager (backend);
-}
-
-/**
- * meta_monitor_manager_get_num_logical_monitors:
- * @manager: A #MetaMonitorManager object
- *
- * Returns the number of #MetaLogicalMonitor<!-- -->s (can be 0 in case of a
- * headless setup).
- *
- * Returns: the total number of #MetaLogicalMonitor<!-- -->s.
- */
-int
-meta_monitor_manager_get_num_logical_monitors (MetaMonitorManager *manager)
-{
- return g_list_length (manager->logical_monitors);
-}
-
-/**
- * meta_monitor_manager_get_logical_monitors:
- * @manager: A #MetaMonitorManager object
- *
- * Returns the list of #MetaLogicalMonitor<!-- -->s that is handled. See also
- * meta_monitor_manager_get_num_logical_monitors() if you only need the size of
- * the list.
- *
- * Returns: (transfer none) (nullable): the list of logical monitors.
- */
-GList *
-meta_monitor_manager_get_logical_monitors (MetaMonitorManager *manager)
-{
- return manager->logical_monitors;
-}
-
-MetaLogicalMonitor *
-meta_monitor_manager_get_logical_monitor_from_number (MetaMonitorManager *manager,
- int number)
-{
- g_return_val_if_fail ((unsigned int) number < g_list_length (manager->logical_monitors), NULL);
-
- return g_list_nth (manager->logical_monitors, number)->data;
-}
-
-MetaLogicalMonitor *
-meta_monitor_manager_get_primary_logical_monitor (MetaMonitorManager *manager)
-{
- return manager->primary_logical_monitor;
-}
-
-static MetaMonitor *
-find_monitor (MetaMonitorManager *monitor_manager,
- gboolean (*match_func) (MetaMonitor *monitor))
-{
- GList *monitors;
- GList *l;
-
- monitors = meta_monitor_manager_get_monitors (monitor_manager);
- for (l = monitors; l; l = l->next)
- {
- MetaMonitor *monitor = l->data;
-
- if (match_func (monitor))
- return monitor;
- }
-
- return NULL;
-}
-
-/**
- * meta_monitor_manager_get_primary_monitor:
- * @manager: A #MetaMonitorManager object
- *
- * Returns the primary monitor. This can be %NULL (e.g. when running headless).
- *
- * Returns: (transfer none) (nullable): The primary #MetaMonitor, or %NULL if
- * none.
- */
-MetaMonitor *
-meta_monitor_manager_get_primary_monitor (MetaMonitorManager *manager)
-{
- return find_monitor (manager, meta_monitor_is_primary);
-}
-
-/**
- * meta_monitor_manager_get_laptop_panel:
- * @manager: A #MetaMonitorManager object
- *
- * Returns the #MetaMonitor that represents the built-in laptop panel (if
- * applicable).
- *
- * Returns: (transfer none) (nullable): The laptop panel, or %NULL if none.
- */
-MetaMonitor *
-meta_monitor_manager_get_laptop_panel (MetaMonitorManager *manager)
-{
- return find_monitor (manager, meta_monitor_is_laptop_panel);
-}
-
-static MetaMonitor *
-meta_monitor_manager_get_active_monitor (MetaMonitorManager *manager)
-{
- return find_monitor (manager, meta_monitor_is_active);
-}
-
-MetaMonitor *
-meta_monitor_manager_get_monitor_from_connector (MetaMonitorManager *manager,
- const char *connector)
-{
- GList *l;
-
- for (l = manager->monitors; l; l = l->next)
- {
- MetaMonitor *monitor = l->data;
-
- if (g_str_equal (meta_monitor_get_connector (monitor),
- connector))
- return monitor;
- }
-
- return NULL;
-}
-
-MetaMonitor *
-meta_monitor_manager_get_monitor_from_spec (MetaMonitorManager *manager,
- MetaMonitorSpec *monitor_spec)
-{
- GList *l;
-
- for (l = manager->monitors; l; l = l->next)
- {
- MetaMonitor *monitor = l->data;
-
- if (meta_monitor_spec_equals (meta_monitor_get_spec (monitor),
- monitor_spec))
- return monitor;
- }
-
- return NULL;
-}
-
-/**
- * meta_monitor_manager_get_logical_monitor_at:
- * @manager: A #MetaMonitorManager object
- * @x: The x-coordinate
- * @y: The y-coordinate
- *
- * Finds the #MetaLogicalMonitor at the given @x and @y coordinates in the
- * total layout.
- *
- * Returns: (transfer none) (nullable): The #MetaLogicalMonitor at the given
- * point, or %NULL if none.
- */
-MetaLogicalMonitor *
-meta_monitor_manager_get_logical_monitor_at (MetaMonitorManager *manager,
- float x,
- float y)
-{
- GList *l;
-
- for (l = manager->logical_monitors; l; l = l->next)
- {
- MetaLogicalMonitor *logical_monitor = l->data;
-
- if (META_POINT_IN_RECT (x, y, logical_monitor->rect))
- return logical_monitor;
- }
-
- return NULL;
-}
-
-/**
- * meta_monitor_manager_get_logical_monitor_from_rect:
- * @manager: A #MetaMonitorManager object
- * @rect: The rectangle
- *
- * Finds the #MetaLogicalMonitor which has the largest area in common with the
- * given @rect in the total layout.
- *
- * Returns: (transfer none) (nullable): The #MetaLogicalMonitor which
- * corresponds the most to the given @rect, or %NULL if none.
- */
-MetaLogicalMonitor *
-meta_monitor_manager_get_logical_monitor_from_rect (MetaMonitorManager *manager,
- MetaRectangle *rect)
-{
- MetaLogicalMonitor *best_logical_monitor;
- int best_logical_monitor_area;
- GList *l;
-
- best_logical_monitor = NULL;
- best_logical_monitor_area = 0;
-
- for (l = manager->logical_monitors; l; l = l->next)
- {
- MetaLogicalMonitor *logical_monitor = l->data;
- MetaRectangle intersection;
- int intersection_area;
-
- if (!meta_rectangle_intersect (&logical_monitor->rect,
- rect,
- &intersection))
- continue;
-
- intersection_area = meta_rectangle_area (&intersection);
-
- if (intersection_area > best_logical_monitor_area)
- {
- best_logical_monitor = logical_monitor;
- best_logical_monitor_area = intersection_area;
- }
- }
-
- if (!best_logical_monitor && (rect->width == 0 || rect->height == 0))
- best_logical_monitor =
- meta_monitor_manager_get_logical_monitor_at (manager, rect->x, rect->y);
-
- if (!best_logical_monitor)
- best_logical_monitor = manager->primary_logical_monitor;
-
- return best_logical_monitor;
-}
-
-MetaLogicalMonitor *
-meta_monitor_manager_get_logical_monitor_neighbor (MetaMonitorManager *manager,
- MetaLogicalMonitor *logical_monitor,
- MetaDisplayDirection direction)
-{
- GList *l;
-
- for (l = manager->logical_monitors; l; l = l->next)
- {
- MetaLogicalMonitor *other = l->data;
-
- if (meta_logical_monitor_has_neighbor (logical_monitor, other, direction))
- return other;
- }
-
- return NULL;
-}
-
-/**
- * meta_monitor_manager_get_monitors:
- * @manager: A #MetaMonitorManager object
- *
- * Returns the list of #MetaMonitor<!-- -->s. See also
- * meta_monitor_manager_get_logical_monitors() for a list of
- * #MetaLogicalMonitor<!-- -->s.
- *
- * Returns: (transfer none) (nullable): the list of #MetaMonitor<!-- -->s.
- */
-GList *
-meta_monitor_manager_get_monitors (MetaMonitorManager *manager)
-{
- return manager->monitors;
-}
-
-void
-meta_monitor_manager_get_screen_size (MetaMonitorManager *manager,
- int *width,
- int *height)
-{
- *width = manager->screen_width;
- *height = manager->screen_height;
-}
-
-MetaPowerSave
-meta_monitor_manager_get_power_save_mode (MetaMonitorManager *manager)
-{
- MetaMonitorManagerPrivate *priv =
- meta_monitor_manager_get_instance_private (manager);
-
- return priv->power_save_mode;
-}
-
-static void
-destroy_monitor (MetaMonitor *monitor)
-{
- g_object_run_dispose (G_OBJECT (monitor));
- g_object_unref (monitor);
-}
-
-static void
-rebuild_monitors (MetaMonitorManager *manager)
-{
- GList *gpus;
- GList *l;
-
- if (manager->monitors)
- {
- g_list_free_full (manager->monitors, (GDestroyNotify) destroy_monitor);
- manager->monitors = NULL;
- }
-
- gpus = meta_backend_get_gpus (manager->backend);
- for (l = gpus; l; l = l->next)
- {
- MetaGpu *gpu = l->data;
- GList *k;
-
- for (k = meta_gpu_get_outputs (gpu); k; k = k->next)
- {
- MetaOutput *output = k->data;
- const MetaOutputInfo *output_info = meta_output_get_info (output);
-
- if (output_info->tile_info.group_id)
- {
- if (is_main_tiled_monitor_output (output))
- {
- MetaMonitorTiled *monitor_tiled;
-
- monitor_tiled = meta_monitor_tiled_new (manager, output);
- manager->monitors = g_list_append (manager->monitors,
- monitor_tiled);
- }
- }
- else
- {
- MetaMonitorNormal *monitor_normal;
-
- monitor_normal = meta_monitor_normal_new (manager, output);
- manager->monitors = g_list_append (manager->monitors,
- monitor_normal);
- }
- }
- }
-
- for (l = meta_monitor_manager_get_virtual_monitors (manager); l; l = l->next)
- {
- MetaVirtualMonitor *virtual_monitor = l->data;
- MetaOutput *output = meta_virtual_monitor_get_output (virtual_monitor);
- MetaMonitorNormal *monitor_normal;
-
- monitor_normal = meta_monitor_normal_new (manager, output);
- manager->monitors = g_list_append (manager->monitors,
- monitor_normal);
-
- }
-}
-
-void
-meta_monitor_manager_tiled_monitor_added (MetaMonitorManager *manager,
- MetaMonitor *monitor)
-{
- MetaMonitorManagerClass *manager_class =
- META_MONITOR_MANAGER_GET_CLASS (manager);
-
- if (manager_class->tiled_monitor_added)
- manager_class->tiled_monitor_added (manager, monitor);
-}
-
-void
-meta_monitor_manager_tiled_monitor_removed (MetaMonitorManager *manager,
- MetaMonitor *monitor)
-{
- MetaMonitorManagerClass *manager_class =
- META_MONITOR_MANAGER_GET_CLASS (manager);
-
- if (manager_class->tiled_monitor_removed)
- manager_class->tiled_monitor_removed (manager, monitor);
-}
-
-gboolean
-meta_monitor_manager_is_transform_handled (MetaMonitorManager *manager,
- MetaCrtc *crtc,
- MetaMonitorTransform transform)
-{
- MetaMonitorManagerClass *manager_class =
- META_MONITOR_MANAGER_GET_CLASS (manager);
-
- return manager_class->is_transform_handled (manager, crtc, transform);
-}
-
-static void
-meta_monitor_manager_real_read_current_state (MetaMonitorManager *manager)
-{
- GList *l;
-
- manager->serial++;
-
- for (l = meta_backend_get_gpus (manager->backend); l; l = l->next)
- {
- MetaGpu *gpu = l->data;
- GError *error = NULL;
-
- if (!meta_gpu_read_current (gpu, &error))
- {
- g_warning ("Failed to read current KMS state: %s", error->message);
- g_clear_error (&error);
- }
- }
-
- rebuild_monitors (manager);
-}
-
-void
-meta_monitor_manager_read_current_state (MetaMonitorManager *manager)
-{
- MetaMonitorManagerClass *manager_class =
- META_MONITOR_MANAGER_GET_CLASS (manager);
-
- manager_class->read_current_state (manager);
-}
-
-static void
-meta_monitor_manager_notify_monitors_changed (MetaMonitorManager *manager)
-{
- meta_backend_monitors_changed (manager->backend);
-
- g_signal_emit (manager, signals[MONITORS_CHANGED_INTERNAL], 0);
- g_signal_emit (manager, signals[MONITORS_CHANGED], 0);
-
- meta_dbus_display_config_emit_monitors_changed (manager->display_config);
-}
-
-static void
-set_logical_monitor_modes (MetaMonitorManager *manager,
- MetaLogicalMonitorConfig *logical_monitor_config)
-{
- GList *l;
-
- for (l = logical_monitor_config->monitor_configs; l; l = l->next)
- {
- MetaMonitorConfig *monitor_config = l->data;
- MetaMonitorSpec *monitor_spec;
- MetaMonitor *monitor;
- MetaMonitorModeSpec *monitor_mode_spec;
- MetaMonitorMode *monitor_mode;
-
- monitor_spec = monitor_config->monitor_spec;
- monitor = meta_monitor_manager_get_monitor_from_spec (manager,
- monitor_spec);
- monitor_mode_spec = monitor_config->mode_spec;
- monitor_mode = meta_monitor_get_mode_from_spec (monitor,
- monitor_mode_spec);
-
- meta_monitor_set_current_mode (monitor, monitor_mode);
- }
-}
-
-static void
-meta_monitor_manager_update_monitor_modes (MetaMonitorManager *manager,
- MetaMonitorsConfig *config)
-{
- GList *logical_monitor_configs;
- GList *l;
-
- g_list_foreach (manager->monitors,
- (GFunc) meta_monitor_set_current_mode,
- NULL);
-
- logical_monitor_configs = config ? config->logical_monitor_configs : NULL;
- for (l = logical_monitor_configs; l; l = l->next)
- {
- MetaLogicalMonitorConfig *logical_monitor_config = l->data;
-
- set_logical_monitor_modes (manager, logical_monitor_config);
- }
-}
-
-void
-meta_monitor_manager_update_logical_state (MetaMonitorManager *manager,
- MetaMonitorsConfig *config)
-{
- if (config)
- {
- manager->layout_mode = config->layout_mode;
- manager->current_switch_config =
- meta_monitors_config_get_switch_config (config);
- }
- else
- {
- manager->layout_mode =
- meta_monitor_manager_get_default_layout_mode (manager);
- manager->current_switch_config = META_MONITOR_SWITCH_CONFIG_UNKNOWN;
- }
-
- meta_monitor_manager_rebuild_logical_monitors (manager, config);
-}
-
-void
-meta_monitor_manager_rebuild (MetaMonitorManager *manager,
- MetaMonitorsConfig *config)
-{
- GList *old_logical_monitors;
-
- meta_monitor_manager_update_monitor_modes (manager, config);
-
- if (manager->in_init)
- return;
-
- old_logical_monitors = manager->logical_monitors;
-
- meta_monitor_manager_update_logical_state (manager, config);
-
- meta_monitor_manager_notify_monitors_changed (manager);
-
- g_list_free_full (old_logical_monitors, g_object_unref);
-}
-
-static void
-meta_monitor_manager_update_monitor_modes_derived (MetaMonitorManager *manager)
-{
- GList *l;
-
- for (l = manager->monitors; l; l = l->next)
- {
- MetaMonitor *monitor = l->data;
-
- meta_monitor_derive_current_mode (monitor);
- }
-}
-
-void
-meta_monitor_manager_update_logical_state_derived (MetaMonitorManager *manager,
- MetaMonitorsConfig *config)
-{
- if (config)
- manager->current_switch_config =
- meta_monitors_config_get_switch_config (config);
- else
- manager->current_switch_config = META_MONITOR_SWITCH_CONFIG_UNKNOWN;
-
- manager->layout_mode = META_LOGICAL_MONITOR_LAYOUT_MODE_PHYSICAL;
-
- meta_monitor_manager_rebuild_logical_monitors_derived (manager, config);
-}
-
-void
-meta_monitor_manager_rebuild_derived (MetaMonitorManager *manager,
- MetaMonitorsConfig *config)
-{
- GList *old_logical_monitors;
-
- meta_monitor_manager_update_monitor_modes_derived (manager);
-
- if (manager->in_init)
- return;
-
- old_logical_monitors = manager->logical_monitors;
-
- meta_monitor_manager_update_logical_state_derived (manager, config);
-
- meta_monitor_manager_notify_monitors_changed (manager);
-
- g_list_free_full (old_logical_monitors, g_object_unref);
-}
-
-void
-meta_monitor_manager_reconfigure (MetaMonitorManager *manager)
-{
- meta_monitor_manager_ensure_configured (manager);
-}
-
-void
-meta_monitor_manager_reload (MetaMonitorManager *manager)
-{
- meta_monitor_manager_read_current_state (manager);
- meta_monitor_manager_reconfigure (manager);
-}
-
-static gboolean
-calculate_viewport_matrix (MetaMonitorManager *manager,
- MetaLogicalMonitor *logical_monitor,
- gfloat viewport[6])
-{
- gfloat x, y, width, height;
-
- x = (float) logical_monitor->rect.x / manager->screen_width;
- y = (float) logical_monitor->rect.y / manager->screen_height;
- width = (float) logical_monitor->rect.width / manager->screen_width;
- height = (float) logical_monitor->rect.height / manager->screen_height;
-
- viewport[0] = width;
- viewport[1] = 0.0f;
- viewport[2] = x;
- viewport[3] = 0.0f;
- viewport[4] = height;
- viewport[5] = y;
-
- return TRUE;
-}
-
-static inline void
-multiply_matrix (float a[6],
- float b[6],
- float res[6])
-{
- res[0] = a[0] * b[0] + a[1] * b[3];
- res[1] = a[0] * b[1] + a[1] * b[4];
- res[2] = a[0] * b[2] + a[1] * b[5] + a[2];
- res[3] = a[3] * b[0] + a[4] * b[3];
- res[4] = a[3] * b[1] + a[4] * b[4];
- res[5] = a[3] * b[2] + a[4] * b[5] + a[5];
-}
-
-gboolean
-meta_monitor_manager_get_monitor_matrix (MetaMonitorManager *manager,
- MetaMonitor *monitor,
- MetaLogicalMonitor *logical_monitor,
- gfloat matrix[6])
-{
- MetaMonitorTransform transform;
- gfloat viewport[9];
-
- if (!calculate_viewport_matrix (manager, logical_monitor, viewport))
- return FALSE;
-
- /* Get transform corrected for LCD panel-orientation. */
- transform = logical_monitor->transform;
- transform = meta_monitor_logical_to_crtc_transform (monitor, transform);
- multiply_matrix (viewport, transform_matrices[transform],
- matrix);
- return TRUE;
-}
-
-/**
- * meta_monitor_manager_get_monitor_for_connector:
- * @manager: A #MetaMonitorManager
- * @connector: A valid connector name
- *
- * Returns: The monitor index or -1 if @id isn't valid or the connector
- * isn't associated with a logical monitor.
- */
-gint
-meta_monitor_manager_get_monitor_for_connector (MetaMonitorManager *manager,
- const char *connector)
-{
- GList *l;
-
- for (l = manager->monitors; l; l = l->next)
- {
- MetaMonitor *monitor = l->data;
-
- if (meta_monitor_is_active (monitor) &&
- g_str_equal (connector, meta_monitor_get_connector (monitor)))
- return meta_monitor_get_logical_monitor (monitor)->number;
- }
-
- return -1;
-}
-
-/**
- * meta_monitor_manager_get_is_builtin_display_on:
- * @manager: A #MetaMonitorManager object
- *
- * Returns whether the built-in display (i.e. a laptop panel) is turned on.
- */
-gboolean
-meta_monitor_manager_get_is_builtin_display_on (MetaMonitorManager *manager)
-{
- MetaMonitor *laptop_panel;
-
- g_return_val_if_fail (META_IS_MONITOR_MANAGER (manager), FALSE);
-
- laptop_panel = meta_monitor_manager_get_laptop_panel (manager);
- if (!laptop_panel)
- return FALSE;
-
- return meta_monitor_is_active (laptop_panel);
-}
-
-void
-meta_monitor_manager_rotate_monitor (MetaMonitorManager *manager)
-{
- GError *error = NULL;
- MetaMonitorsConfig *config =
- meta_monitor_config_manager_create_for_rotate_monitor (manager->config_manager);
-
- if (!config)
- return;
-
- if (!meta_monitor_manager_apply_monitors_config (manager,
- config,
- META_MONITORS_CONFIG_METHOD_TEMPORARY,
- &error))
- {
- g_warning ("Failed to use rotate monitor configuration: %s",
- error->message);
- g_error_free (error);
- }
- g_object_unref (config);
-}
-
-void
-meta_monitor_manager_switch_config (MetaMonitorManager *manager,
- MetaMonitorSwitchConfigType config_type)
-{
- GError *error = NULL;
- MetaMonitorsConfig *config;
-
- g_return_if_fail (config_type != META_MONITOR_SWITCH_CONFIG_UNKNOWN);
-
- config =
- meta_monitor_config_manager_create_for_switch_config (manager->config_manager,
- config_type);
- if (!config)
- return;
-
- if (!meta_monitor_manager_apply_monitors_config (manager,
- config,
- META_MONITORS_CONFIG_METHOD_TEMPORARY,
- &error))
- {
- g_warning ("Failed to use switch monitor configuration: %s",
- error->message);
- g_error_free (error);
- }
- else
- {
- manager->current_switch_config = config_type;
- }
- g_object_unref (config);
-}
-
-gboolean
-meta_monitor_manager_can_switch_config (MetaMonitorManager *manager)
-{
- return (!meta_backend_is_lid_closed (manager->backend) &&
- g_list_length (manager->monitors) > 1);
-}
-
-MetaMonitorSwitchConfigType
-meta_monitor_manager_get_switch_config (MetaMonitorManager *manager)
-{
- return manager->current_switch_config;
-}
-
-MetaMonitorConfigManager *
-meta_monitor_manager_get_config_manager (MetaMonitorManager *manager)
-{
- return manager->config_manager;
-}
-
-/**
- * meta_monitor_manager_get_vendor_name:
- * @manager: A #MetaMonitorManager object
- * @vendor: the PNP ID of the monitor
- *
- * Find the full vendor name from the given monitor PNP ID.
- *
- * Returns: (transfer full): A string containing the vendor name,
- * or NULL when not found.
- */
-char *
-meta_monitor_manager_get_vendor_name (MetaMonitorManager *manager,
- const char *vendor)
-{
- if (!manager->pnp_ids)
- manager->pnp_ids = gnome_pnp_ids_new ();
-
- return gnome_pnp_ids_get_pnp_id (manager->pnp_ids, vendor);
-}
-
-gboolean
-meta_monitor_manager_get_panel_orientation_managed (MetaMonitorManager *manager)
-{
- g_return_val_if_fail (META_IS_MONITOR_MANAGER (manager), FALSE);
-
- return manager->panel_orientation_managed;
-}
-
-void
-meta_monitor_manager_post_init (MetaMonitorManager *manager)
-{
- ClutterBackend *clutter_backend;
- ClutterSeat *seat;
-
- clutter_backend = meta_backend_get_clutter_backend (manager->backend);
- seat = clutter_backend_get_default_seat (clutter_backend);
-
- g_signal_connect_object (seat, "notify::touch-mode",
- G_CALLBACK (update_panel_orientation_managed), manager,
- G_CONNECT_SWAPPED);
-}
-
-MetaViewportInfo *
-meta_monitor_manager_get_viewports (MetaMonitorManager *manager)
-{
- MetaViewportInfo *info;
- GArray *views, *scales;
- GList *logical_monitors, *l;
-
- views = g_array_new (FALSE, FALSE, sizeof (cairo_rectangle_int_t));
- scales = g_array_new (FALSE, FALSE, sizeof (float));
-
- logical_monitors = meta_monitor_manager_get_logical_monitors (manager);
-
- for (l = logical_monitors; l; l = l->next)
- {
- MetaLogicalMonitor *logical_monitor = l->data;
- cairo_rectangle_int_t rect;
- float scale;
-
- rect = logical_monitor->rect;
- g_array_append_val (views, rect);
-
- scale = logical_monitor->scale;
- g_array_append_val (scales, scale);
- }
-
- info = meta_viewport_info_new ((cairo_rectangle_int_t *) views->data,
- (float *) scales->data,
- views->len,
- meta_is_stage_views_scaled ());
- g_array_unref (views);
- g_array_unref (scales);
-
- return info;
-}
-
-GList *
-meta_monitor_manager_get_virtual_monitors (MetaMonitorManager *manager)
-{
- MetaMonitorManagerPrivate *priv =
- meta_monitor_manager_get_instance_private (manager);
-
- return priv->virtual_monitors;
-}
diff --git a/src/backends/meta-monitor-transform.c b/src/backends/meta-monitor-transform.c
deleted file mode 100644
index d6b1f8b45..000000000
--- a/src/backends/meta-monitor-transform.c
+++ /dev/null
@@ -1,128 +0,0 @@
-/*
- * Copyright (C) 2018 Robert Mader
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "config.h"
-
-#include "backends/meta-monitor-transform.h"
-
-MetaMonitorTransform
-meta_monitor_transform_invert (MetaMonitorTransform transform)
-{
- switch (transform)
- {
- case META_MONITOR_TRANSFORM_90:
- return META_MONITOR_TRANSFORM_270;
- case META_MONITOR_TRANSFORM_270:
- return META_MONITOR_TRANSFORM_90;
- case META_MONITOR_TRANSFORM_NORMAL:
- case META_MONITOR_TRANSFORM_180:
- case META_MONITOR_TRANSFORM_FLIPPED:
- case META_MONITOR_TRANSFORM_FLIPPED_90:
- case META_MONITOR_TRANSFORM_FLIPPED_180:
- case META_MONITOR_TRANSFORM_FLIPPED_270:
- return transform;
- }
- g_assert_not_reached ();
- return 0;
-}
-
-MetaMonitorTransform
-meta_monitor_transform_transform (MetaMonitorTransform transform,
- MetaMonitorTransform other)
-{
- MetaMonitorTransform new_transform;
-
- new_transform = (transform + other) % META_MONITOR_TRANSFORM_FLIPPED;
- if (meta_monitor_transform_is_flipped (transform) !=
- meta_monitor_transform_is_flipped (other))
- new_transform += META_MONITOR_TRANSFORM_FLIPPED;
-
- return new_transform;
-}
-
-/**
- * meta_monitor_transform_relative_transform:
- * @transform: The transform to start from
- * @other: The transform to go to
- *
- * Return value: a transform to get from @transform to @other
- */
-MetaMonitorTransform
-meta_monitor_transform_relative_transform (MetaMonitorTransform transform,
- MetaMonitorTransform other)
-{
- MetaMonitorTransform relative_transform;
-
- relative_transform = ((other % META_MONITOR_TRANSFORM_FLIPPED -
- transform % META_MONITOR_TRANSFORM_FLIPPED) %
- META_MONITOR_TRANSFORM_FLIPPED);
-
- if (meta_monitor_transform_is_flipped (transform) !=
- meta_monitor_transform_is_flipped (other))
- {
- relative_transform = (meta_monitor_transform_invert (relative_transform) +
- META_MONITOR_TRANSFORM_FLIPPED);
- }
-
- return relative_transform;
-}
-
-void
-meta_monitor_transform_transform_point (MetaMonitorTransform transform,
- int area_width,
- int area_height,
- int x,
- int y,
- int *out_x,
- int *out_y)
-{
- switch (transform)
- {
- case META_MONITOR_TRANSFORM_NORMAL:
- *out_x = x;
- *out_y = y;
- break;
- case META_MONITOR_TRANSFORM_90:
- *out_x = area_width - y;
- *out_y = x;
- break;
- case META_MONITOR_TRANSFORM_180:
- *out_x = area_width - x;
- *out_y = area_height - y;
- break;
- case META_MONITOR_TRANSFORM_270:
- *out_x = y,
- *out_y = area_height - x;
- break;
- case META_MONITOR_TRANSFORM_FLIPPED:
- *out_x = area_width - x;
- *out_y = y;
- break;
- case META_MONITOR_TRANSFORM_FLIPPED_90:
- *out_x = area_width - y;
- *out_y = area_height - x;
- break;
- case META_MONITOR_TRANSFORM_FLIPPED_180:
- *out_x = x;
- *out_y = area_height - y;
- break;
- case META_MONITOR_TRANSFORM_FLIPPED_270:
- *out_x = y;
- *out_y = x;
- break;
- }
-}
diff --git a/src/backends/meta-monitor-transform.h b/src/backends/meta-monitor-transform.h
deleted file mode 100644
index 6113f3a5a..000000000
--- a/src/backends/meta-monitor-transform.h
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Copyright (C) 2013 Red Hat Inc.
- * Copyright (C) 2018 Robert Mader
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef META_MONITOR_TRANSFORM_H
-#define META_MONITOR_TRANSFORM_H
-
-#include <glib-object.h>
-
-#include "backends/meta-backend-types.h"
-#include "core/util-private.h"
-
-enum _MetaMonitorTransform
-{
- META_MONITOR_TRANSFORM_NORMAL,
- META_MONITOR_TRANSFORM_90,
- META_MONITOR_TRANSFORM_180,
- META_MONITOR_TRANSFORM_270,
- META_MONITOR_TRANSFORM_FLIPPED,
- META_MONITOR_TRANSFORM_FLIPPED_90,
- META_MONITOR_TRANSFORM_FLIPPED_180,
- META_MONITOR_TRANSFORM_FLIPPED_270,
-};
-#define META_MONITOR_N_TRANSFORMS (META_MONITOR_TRANSFORM_FLIPPED_270 + 1)
-#define META_MONITOR_ALL_TRANSFORMS ((1 << META_MONITOR_N_TRANSFORMS) - 1)
-
-/* Returns true if transform causes width and height to be inverted
- This is true for the odd transforms in the enum */
-static inline gboolean
-meta_monitor_transform_is_rotated (MetaMonitorTransform transform)
-{
- return (transform % 2);
-}
-
-/* Returns true if transform involves flipping */
-static inline gboolean
-meta_monitor_transform_is_flipped (MetaMonitorTransform transform)
-{
- return (transform >= META_MONITOR_TRANSFORM_FLIPPED);
-}
-
-META_EXPORT_TEST
-MetaMonitorTransform meta_monitor_transform_invert (MetaMonitorTransform transform);
-
-META_EXPORT_TEST
-MetaMonitorTransform meta_monitor_transform_transform (MetaMonitorTransform transform,
- MetaMonitorTransform other);
-
-MetaMonitorTransform meta_monitor_transform_relative_transform (MetaMonitorTransform transform,
- MetaMonitorTransform other);
-
-void meta_monitor_transform_transform_point (MetaMonitorTransform transform,
- int area_width,
- int area_height,
- int x,
- int y,
- int *out_x,
- int *out_y);
-
-#endif /* META_MONITOR_TRANSFORM_H */
diff --git a/src/backends/meta-monitor.c b/src/backends/meta-monitor.c
deleted file mode 100644
index e02f8ed45..000000000
--- a/src/backends/meta-monitor.c
+++ /dev/null
@@ -1,1988 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2016 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-
-#include "config.h"
-
-#include "backends/meta-monitor.h"
-
-#include "backends/meta-backend-private.h"
-#include "backends/meta-crtc.h"
-#include "backends/meta-gpu.h"
-#include "backends/meta-monitor-manager-private.h"
-#include "backends/meta-settings-private.h"
-#include "backends/meta-output.h"
-#include "core/boxes-private.h"
-
-#define SCALE_FACTORS_PER_INTEGER 4
-#define SCALE_FACTORS_STEPS (1.0 / (float) SCALE_FACTORS_PER_INTEGER)
-#define MINIMUM_SCALE_FACTOR 1.0f
-#define MAXIMUM_SCALE_FACTOR 4.0f
-#define MINIMUM_LOGICAL_AREA (800 * 480)
-#define MAXIMUM_REFRESH_RATE_DIFF 0.001
-
-typedef struct _MetaMonitorMode
-{
- MetaMonitor *monitor;
- char *id;
- MetaMonitorModeSpec spec;
- MetaMonitorCrtcMode *crtc_modes;
-} MetaMonitorMode;
-
-typedef struct _MetaMonitorModeTiled
-{
- MetaMonitorMode parent;
-
- gboolean is_tiled;
-} MetaMonitorModeTiled;
-
-typedef struct _MetaMonitorPrivate
-{
- MetaBackend *backend;
-
- GList *outputs;
- GList *modes;
- GHashTable *mode_ids;
-
- MetaMonitorMode *preferred_mode;
- MetaMonitorMode *current_mode;
-
- MetaMonitorSpec *spec;
-
- MetaLogicalMonitor *logical_monitor;
-
- /*
- * The primary or first output for this monitor, 0 if we can't figure out.
- * It can be matched to a winsys_id of a MetaOutput.
- *
- * This is used as an opaque token on reconfiguration when switching from
- * clone to extended, to decide on what output the windows should go next
- * (it's an attempt to keep windows on the same monitor, and preferably on
- * the primary one).
- */
- uint64_t winsys_id;
-
- char *display_name;
-} MetaMonitorPrivate;
-
-G_DEFINE_TYPE_WITH_PRIVATE (MetaMonitor, meta_monitor, G_TYPE_OBJECT)
-
-struct _MetaMonitorNormal
-{
- MetaMonitor parent;
-};
-
-G_DEFINE_TYPE (MetaMonitorNormal, meta_monitor_normal, META_TYPE_MONITOR)
-
-struct _MetaMonitorTiled
-{
- MetaMonitor parent;
-
- MetaMonitorManager *monitor_manager;
-
- uint32_t tile_group_id;
-
- /* The tile (0, 0) output. */
- MetaOutput *origin_output;
-
- /* The output enabled even when a non-tiled mode is used. */
- MetaOutput *main_output;
-};
-
-G_DEFINE_TYPE (MetaMonitorTiled, meta_monitor_tiled, META_TYPE_MONITOR)
-
-static void
-meta_monitor_mode_free (MetaMonitorMode *mode);
-
-MetaMonitorSpec *
-meta_monitor_spec_clone (MetaMonitorSpec *monitor_spec)
-{
- MetaMonitorSpec *new_monitor_spec;
-
- new_monitor_spec = g_new0 (MetaMonitorSpec, 1);
- *new_monitor_spec = (MetaMonitorSpec) {
- .connector = g_strdup (monitor_spec->connector),
- .vendor = g_strdup (monitor_spec->vendor),
- .product = g_strdup (monitor_spec->product),
- .serial = g_strdup (monitor_spec->serial),
- };
-
- return new_monitor_spec;
-}
-
-gboolean
-meta_monitor_spec_equals (MetaMonitorSpec *monitor_spec,
- MetaMonitorSpec *other_monitor_spec)
-{
- return (g_str_equal (monitor_spec->connector, other_monitor_spec->connector) &&
- g_str_equal (monitor_spec->vendor, other_monitor_spec->vendor) &&
- g_str_equal (monitor_spec->product, other_monitor_spec->product) &&
- g_str_equal (monitor_spec->serial, other_monitor_spec->serial));
-}
-
-int
-meta_monitor_spec_compare (MetaMonitorSpec *monitor_spec_a,
- MetaMonitorSpec *monitor_spec_b)
-{
- int ret;
-
- ret = strcmp (monitor_spec_a->connector, monitor_spec_b->connector);
- if (ret != 0)
- return ret;
-
- ret = strcmp (monitor_spec_a->vendor, monitor_spec_b->vendor);
- if (ret != 0)
- return ret;
-
- ret = strcmp (monitor_spec_a->product, monitor_spec_b->product);
- if (ret != 0)
- return ret;
-
- return strcmp (monitor_spec_a->serial, monitor_spec_b->serial);
-}
-
-void
-meta_monitor_spec_free (MetaMonitorSpec *monitor_spec)
-{
- g_free (monitor_spec->connector);
- g_free (monitor_spec->vendor);
- g_free (monitor_spec->product);
- g_free (monitor_spec->serial);
- g_free (monitor_spec);
-}
-
-static const MetaOutputInfo *
-meta_monitor_get_main_output_info (MetaMonitor *monitor)
-{
- MetaOutput *output = meta_monitor_get_main_output (monitor);
-
- return meta_output_get_info (output);
-}
-
-static void
-meta_monitor_generate_spec (MetaMonitor *monitor)
-{
- MetaMonitorPrivate *priv = meta_monitor_get_instance_private (monitor);
- const MetaOutputInfo *output_info =
- meta_monitor_get_main_output_info (monitor);
- MetaMonitorSpec *monitor_spec;
-
- monitor_spec = g_new0 (MetaMonitorSpec, 1);
- *monitor_spec = (MetaMonitorSpec) {
- .connector = g_strdup (output_info->name),
- .vendor = g_strdup (output_info->vendor),
- .product = g_strdup (output_info->product),
- .serial = g_strdup (output_info->serial),
- };
-
- priv->spec = monitor_spec;
-}
-
-static const double known_diagonals[] = {
- 12.1,
- 13.3,
- 15.6
-};
-
-static char *
-diagonal_to_str (double d)
-{
- unsigned int i;
-
- for (i = 0; i < G_N_ELEMENTS (known_diagonals); i++)
- {
- double delta;
-
- delta = fabs(known_diagonals[i] - d);
- if (delta < 0.1)
- return g_strdup_printf ("%0.1lf\"", known_diagonals[i]);
- }
-
- return g_strdup_printf ("%d\"", (int) (d + 0.5));
-}
-
-static char *
-meta_monitor_make_display_name (MetaMonitor *monitor,
- MetaMonitorManager *monitor_manager)
-{
- g_autofree char *inches = NULL;
- g_autofree char *vendor_name = NULL;
- const char *vendor = NULL;
- const char *product_name = NULL;
- int width_mm;
- int height_mm;
-
- meta_monitor_get_physical_dimensions (monitor, &width_mm, &height_mm);
-
- if (meta_monitor_is_laptop_panel (monitor))
- return g_strdup (_("Built-in display"));
-
- if (width_mm > 0 && height_mm > 0)
- {
- if (!meta_monitor_has_aspect_as_size (monitor))
- {
- double d = sqrt (width_mm * width_mm +
- height_mm * height_mm);
- inches = diagonal_to_str (d / 25.4);
- }
- else
- {
- product_name = meta_monitor_get_product (monitor);
- }
- }
-
- vendor = meta_monitor_get_vendor (monitor);
-
- if (g_strcmp0 (vendor, "unknown") != 0)
- {
- vendor_name = meta_monitor_manager_get_vendor_name (monitor_manager,
- vendor);
-
- if (!vendor_name)
- vendor_name = g_strdup (vendor);
- }
- else
- {
- if (inches != NULL)
- vendor_name = g_strdup (_("Unknown"));
- else
- vendor_name = g_strdup (_("Unknown Display"));
- }
-
- if (inches != NULL)
- {
- /**/
- return g_strdup_printf (C_("This is a monitor vendor name, followed by a "
- "size in inches, like 'Dell 15\"'",
- "%s %s"),
- vendor_name, inches);
- }
- else if (product_name != NULL)
- {
- return g_strdup_printf (C_("This is a monitor vendor name followed by "
- "product/model name where size in inches "
- "could not be calculated, e.g. Dell U2414H",
- "%s %s"),
- vendor_name, product_name);
- }
- else
- {
- return g_strdup (vendor_name);
- }
-}
-
-MetaBackend *
-meta_monitor_get_backend (MetaMonitor *monitor)
-{
- MetaMonitorPrivate *priv = meta_monitor_get_instance_private (monitor);
-
- return priv->backend;
-}
-
-GList *
-meta_monitor_get_outputs (MetaMonitor *monitor)
-{
- MetaMonitorPrivate *priv = meta_monitor_get_instance_private (monitor);
-
- return priv->outputs;
-}
-
-MetaOutput *
-meta_monitor_get_main_output (MetaMonitor *monitor)
-{
- return META_MONITOR_GET_CLASS (monitor)->get_main_output (monitor);
-}
-
-gboolean
-meta_monitor_is_active (MetaMonitor *monitor)
-{
- MetaMonitorPrivate *priv = meta_monitor_get_instance_private (monitor);
-
- return !!priv->current_mode;
-}
-
-gboolean
-meta_monitor_is_primary (MetaMonitor *monitor)
-{
- MetaOutput *output;
-
- output = meta_monitor_get_main_output (monitor);
-
- return meta_output_is_primary (output);
-}
-
-gboolean
-meta_monitor_supports_underscanning (MetaMonitor *monitor)
-{
- const MetaOutputInfo *output_info =
- meta_monitor_get_main_output_info (monitor);
-
- return output_info->supports_underscanning;
-}
-
-gboolean
-meta_monitor_is_underscanning (MetaMonitor *monitor)
-{
- MetaOutput *output;
-
- output = meta_monitor_get_main_output (monitor);
-
- return meta_output_is_underscanning (output);
-}
-
-gboolean
-meta_monitor_is_laptop_panel (MetaMonitor *monitor)
-{
- const MetaOutputInfo *output_info =
- meta_monitor_get_main_output_info (monitor);
-
- switch (output_info->connector_type)
- {
- case META_CONNECTOR_TYPE_eDP:
- case META_CONNECTOR_TYPE_LVDS:
- case META_CONNECTOR_TYPE_DSI:
- return TRUE;
- default:
- return FALSE;
- }
-}
-
-gboolean
-meta_monitor_is_same_as (MetaMonitor *monitor,
- MetaMonitor *other_monitor)
-{
- MetaMonitorPrivate *priv =
- meta_monitor_get_instance_private (monitor);
- MetaMonitorPrivate *other_priv =
- meta_monitor_get_instance_private (other_monitor);
-
- return priv->winsys_id == other_priv->winsys_id;
-}
-
-void
-meta_monitor_get_current_resolution (MetaMonitor *monitor,
- int *width,
- int *height)
-{
- MetaMonitorMode *mode = meta_monitor_get_current_mode (monitor);
-
- *width = mode->spec.width;
- *height = mode->spec.height;
-}
-
-void
-meta_monitor_derive_layout (MetaMonitor *monitor,
- MetaRectangle *layout)
-{
- META_MONITOR_GET_CLASS (monitor)->derive_layout (monitor, layout);
-}
-
-void
-meta_monitor_get_physical_dimensions (MetaMonitor *monitor,
- int *width_mm,
- int *height_mm)
-{
- const MetaOutputInfo *output_info =
- meta_monitor_get_main_output_info (monitor);
-
- *width_mm = output_info->width_mm;
- *height_mm = output_info->height_mm;
-}
-
-CoglSubpixelOrder
-meta_monitor_get_subpixel_order (MetaMonitor *monitor)
-{
- const MetaOutputInfo *output_info =
- meta_monitor_get_main_output_info (monitor);
-
- return output_info->subpixel_order;
-}
-
-const char *
-meta_monitor_get_connector (MetaMonitor *monitor)
-{
- const MetaOutputInfo *output_info =
- meta_monitor_get_main_output_info (monitor);
-
- return output_info->name;
-}
-
-const char *
-meta_monitor_get_vendor (MetaMonitor *monitor)
-{
- const MetaOutputInfo *output_info =
- meta_monitor_get_main_output_info (monitor);
-
- return output_info->vendor;
-}
-
-const char *
-meta_monitor_get_product (MetaMonitor *monitor)
-{
- const MetaOutputInfo *output_info =
- meta_monitor_get_main_output_info (monitor);
-
- return output_info->product;
-}
-
-const char *
-meta_monitor_get_serial (MetaMonitor *monitor)
-{
- const MetaOutputInfo *output_info =
- meta_monitor_get_main_output_info (monitor);
-
- return output_info->serial;
-}
-
-MetaConnectorType
-meta_monitor_get_connector_type (MetaMonitor *monitor)
-{
- const MetaOutputInfo *output_info =
- meta_monitor_get_main_output_info (monitor);
-
- return output_info->connector_type;
-}
-
-MetaMonitorTransform
-meta_monitor_logical_to_crtc_transform (MetaMonitor *monitor,
- MetaMonitorTransform transform)
-{
- MetaOutput *output = meta_monitor_get_main_output (monitor);
-
- return meta_output_logical_to_crtc_transform (output, transform);
-}
-
-MetaMonitorTransform
-meta_monitor_crtc_to_logical_transform (MetaMonitor *monitor,
- MetaMonitorTransform transform)
-{
- MetaOutput *output = meta_monitor_get_main_output (monitor);
-
- return meta_output_crtc_to_logical_transform (output, transform);
-}
-
-static void
-meta_monitor_dispose (GObject *object)
-{
- MetaMonitor *monitor = META_MONITOR (object);
- MetaMonitorPrivate *priv = meta_monitor_get_instance_private (monitor);
-
- if (priv->outputs)
- {
- g_list_foreach (priv->outputs, (GFunc) meta_output_unset_monitor, NULL);
- g_list_free_full (priv->outputs, g_object_unref);
- priv->outputs = NULL;
- }
-
- G_OBJECT_CLASS (meta_monitor_parent_class)->dispose (object);
-}
-
-static void
-meta_monitor_finalize (GObject *object)
-{
- MetaMonitor *monitor = META_MONITOR (object);
- MetaMonitorPrivate *priv = meta_monitor_get_instance_private (monitor);
-
- g_hash_table_destroy (priv->mode_ids);
- g_list_free_full (priv->modes, (GDestroyNotify) meta_monitor_mode_free);
- meta_monitor_spec_free (priv->spec);
- g_free (priv->display_name);
-
- G_OBJECT_CLASS (meta_monitor_parent_class)->finalize (object);
-}
-
-static void
-meta_monitor_init (MetaMonitor *monitor)
-{
- MetaMonitorPrivate *priv = meta_monitor_get_instance_private (monitor);
-
- priv->mode_ids = g_hash_table_new (g_str_hash, g_str_equal);
-}
-
-static void
-meta_monitor_class_init (MetaMonitorClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- object_class->dispose = meta_monitor_dispose;
- object_class->finalize = meta_monitor_finalize;
-}
-
-static char *
-generate_mode_id (MetaMonitorModeSpec *monitor_mode_spec)
-{
- gboolean is_interlaced;
- char refresh_rate_str[G_ASCII_DTOSTR_BUF_SIZE];
-
- is_interlaced = !!(monitor_mode_spec->flags & META_CRTC_MODE_FLAG_INTERLACE);
- g_ascii_dtostr (refresh_rate_str, G_ASCII_DTOSTR_BUF_SIZE,
- monitor_mode_spec->refresh_rate);
-
- return g_strdup_printf ("%dx%d%s@%s",
- monitor_mode_spec->width,
- monitor_mode_spec->height,
- is_interlaced ? "i" : "",
- refresh_rate_str);
-}
-
-static gboolean
-meta_monitor_add_mode (MetaMonitor *monitor,
- MetaMonitorMode *monitor_mode,
- gboolean replace)
-{
- MetaMonitorPrivate *priv = meta_monitor_get_instance_private (monitor);
- MetaMonitorMode *existing_mode;
-
- existing_mode = g_hash_table_lookup (priv->mode_ids,
- meta_monitor_mode_get_id (monitor_mode));
- if (existing_mode && !replace)
- return FALSE;
-
- if (existing_mode)
- priv->modes = g_list_remove (priv->modes, existing_mode);
-
- priv->modes = g_list_append (priv->modes, monitor_mode);
- g_hash_table_replace (priv->mode_ids, monitor_mode->id, monitor_mode);
-
- return TRUE;
-}
-
-static MetaMonitorModeSpec
-meta_monitor_create_spec (MetaMonitor *monitor,
- int width,
- int height,
- MetaCrtcMode *crtc_mode)
-{
- const MetaOutputInfo *output_info =
- meta_monitor_get_main_output_info (monitor);
- const MetaCrtcModeInfo *crtc_mode_info =
- meta_crtc_mode_get_info (crtc_mode);
-
- if (meta_monitor_transform_is_rotated (output_info->panel_orientation_transform))
- {
- int temp = width;
- width = height;
- height = temp;
- }
-
- return (MetaMonitorModeSpec) {
- .width = width,
- .height = height,
- .refresh_rate = crtc_mode_info->refresh_rate,
- .flags = crtc_mode_info->flags & HANDLED_CRTC_MODE_FLAGS
- };
-}
-
-static void
-meta_monitor_normal_generate_modes (MetaMonitorNormal *monitor_normal)
-{
- MetaMonitor *monitor = META_MONITOR (monitor_normal);
- MetaMonitorPrivate *monitor_priv =
- meta_monitor_get_instance_private (monitor);
- MetaOutput *output;
- const MetaOutputInfo *output_info;
- MetaCrtcMode *preferred_mode;
- MetaCrtcModeFlag preferred_mode_flags;
- unsigned int i;
-
- output = meta_monitor_get_main_output (monitor);
- output_info = meta_output_get_info (output);
- preferred_mode = output_info->preferred_mode;
- preferred_mode_flags = meta_crtc_mode_get_info (preferred_mode)->flags;
-
- for (i = 0; i < output_info->n_modes; i++)
- {
- MetaCrtcMode *crtc_mode = output_info->modes[i];
- const MetaCrtcModeInfo *crtc_mode_info =
- meta_crtc_mode_get_info (crtc_mode);
- MetaCrtc *crtc;
- MetaMonitorMode *mode;
- gboolean replace;
-
- mode = g_new0 (MetaMonitorMode, 1);
- mode->monitor = monitor;
- mode->spec = meta_monitor_create_spec (monitor,
- crtc_mode_info->width,
- crtc_mode_info->height,
- crtc_mode);
- mode->id = generate_mode_id (&mode->spec);
- mode->crtc_modes = g_new (MetaMonitorCrtcMode, 1);
- mode->crtc_modes[0] = (MetaMonitorCrtcMode) {
- .output = output,
- .crtc_mode = crtc_mode
- };
-
- /*
- * We don't distinguish between all available mode flags, just the ones
- * that are configurable. We still need to pick some mode though, so
- * prefer ones that has the same set of flags as the preferred mode;
- * otherwise take the first one in the list. This guarantees that the
- * preferred mode is always added.
- */
- replace = crtc_mode_info->flags == preferred_mode_flags;
-
- if (!meta_monitor_add_mode (monitor, mode, replace))
- {
- g_assert (crtc_mode != output_info->preferred_mode);
- meta_monitor_mode_free (mode);
- continue;
- }
-
- if (crtc_mode == output_info->preferred_mode)
- monitor_priv->preferred_mode = mode;
-
- crtc = meta_output_get_assigned_crtc (output);
- if (crtc)
- {
- const MetaCrtcConfig *crtc_config;
-
- crtc_config = meta_crtc_get_config (crtc);
- if (crtc_config && crtc_mode == crtc_config->mode)
- monitor_priv->current_mode = mode;
- }
- }
-}
-
-MetaMonitorNormal *
-meta_monitor_normal_new (MetaMonitorManager *monitor_manager,
- MetaOutput *output)
-{
- MetaMonitorNormal *monitor_normal;
- MetaMonitor *monitor;
- MetaMonitorPrivate *monitor_priv;
-
- monitor_normal = g_object_new (META_TYPE_MONITOR_NORMAL, NULL);
- monitor = META_MONITOR (monitor_normal);
- monitor_priv = meta_monitor_get_instance_private (monitor);
-
- monitor_priv->backend = meta_monitor_manager_get_backend (monitor_manager);
-
- monitor_priv->outputs = g_list_append (NULL, g_object_ref (output));
- meta_output_set_monitor (output, monitor);
-
- monitor_priv->winsys_id = meta_output_get_id (output);
- meta_monitor_generate_spec (monitor);
-
- meta_monitor_normal_generate_modes (monitor_normal);
-
- monitor_priv->display_name = meta_monitor_make_display_name (monitor,
- monitor_manager);
-
- return monitor_normal;
-}
-
-static MetaOutput *
-meta_monitor_normal_get_main_output (MetaMonitor *monitor)
-{
- MetaMonitorPrivate *monitor_priv =
- meta_monitor_get_instance_private (monitor);
-
- return monitor_priv->outputs->data;
-}
-
-static void
-meta_monitor_normal_derive_layout (MetaMonitor *monitor,
- MetaRectangle *layout)
-{
- MetaOutput *output;
- MetaCrtc *crtc;
- const MetaCrtcConfig *crtc_config;
-
- output = meta_monitor_get_main_output (monitor);
- crtc = meta_output_get_assigned_crtc (output);
- crtc_config = meta_crtc_get_config (crtc);
-
- g_return_if_fail (crtc_config);
-
- meta_rectangle_from_graphene_rect (&crtc_config->layout,
- META_ROUNDING_STRATEGY_ROUND,
- layout);
-}
-
-static gboolean
-meta_monitor_normal_get_suggested_position (MetaMonitor *monitor,
- int *x,
- int *y)
-{
- const MetaOutputInfo *output_info =
- meta_monitor_get_main_output_info (monitor);
-
- if (!output_info->hotplug_mode_update)
- return FALSE;
-
- if (output_info->suggested_x < 0 && output_info->suggested_y < 0)
- return FALSE;
-
- *x = output_info->suggested_x;
- *y = output_info->suggested_y;
-
- return TRUE;
-}
-
-static void
-meta_monitor_normal_calculate_crtc_pos (MetaMonitor *monitor,
- MetaMonitorMode *monitor_mode,
- MetaOutput *output,
- MetaMonitorTransform crtc_transform,
- int *out_x,
- int *out_y)
-{
- *out_x = 0;
- *out_y = 0;
-}
-
-static void
-meta_monitor_normal_init (MetaMonitorNormal *monitor)
-{
-}
-
-static void
-meta_monitor_normal_class_init (MetaMonitorNormalClass *klass)
-{
- MetaMonitorClass *monitor_class = META_MONITOR_CLASS (klass);
-
- monitor_class->get_main_output = meta_monitor_normal_get_main_output;
- monitor_class->derive_layout = meta_monitor_normal_derive_layout;
- monitor_class->calculate_crtc_pos = meta_monitor_normal_calculate_crtc_pos;
- monitor_class->get_suggested_position = meta_monitor_normal_get_suggested_position;
-}
-
-uint32_t
-meta_monitor_tiled_get_tile_group_id (MetaMonitorTiled *monitor_tiled)
-{
- return monitor_tiled->tile_group_id;
-}
-
-gboolean
-meta_monitor_get_suggested_position (MetaMonitor *monitor,
- int *x,
- int *y)
-{
- return META_MONITOR_GET_CLASS (monitor)->get_suggested_position (monitor,
- x, y);
-}
-
-static void
-add_tiled_monitor_outputs (MetaGpu *gpu,
- MetaMonitorTiled *monitor_tiled)
-{
- MetaMonitorPrivate *monitor_priv =
- meta_monitor_get_instance_private (META_MONITOR (monitor_tiled));
- GList *outputs;
- GList *l;
-
- outputs = meta_gpu_get_outputs (gpu);
- for (l = outputs; l; l = l->next)
- {
- MetaOutput *output = l->data;
- const MetaOutputInfo *output_info = meta_output_get_info (output);
- const MetaOutputInfo *origin_output_info;
-
- if (output_info->tile_info.group_id != monitor_tiled->tile_group_id)
- continue;
-
- origin_output_info = meta_output_get_info (monitor_tiled->origin_output);
- g_warn_if_fail (output_info->subpixel_order ==
- origin_output_info->subpixel_order);
-
- monitor_priv->outputs = g_list_append (monitor_priv->outputs,
- g_object_ref (output));
-
- meta_output_set_monitor (output, META_MONITOR (monitor_tiled));
- }
-}
-
-static void
-calculate_tile_coordinate (MetaMonitor *monitor,
- MetaOutput *output,
- MetaMonitorTransform crtc_transform,
- int *out_x,
- int *out_y)
-{
- MetaMonitorPrivate *monitor_priv =
- meta_monitor_get_instance_private (monitor);
- const MetaOutputInfo *output_info = meta_output_get_info (output);
- GList *l;
- int x = 0;
- int y = 0;
-
- for (l = monitor_priv->outputs; l; l = l->next)
- {
- const MetaOutputInfo *other_output_info = meta_output_get_info (l->data);
-
- switch (crtc_transform)
- {
- case META_MONITOR_TRANSFORM_NORMAL:
- case META_MONITOR_TRANSFORM_FLIPPED:
- if ((other_output_info->tile_info.loc_v_tile ==
- output_info->tile_info.loc_v_tile) &&
- (other_output_info->tile_info.loc_h_tile <
- output_info->tile_info.loc_h_tile))
- x += other_output_info->tile_info.tile_w;
- if ((other_output_info->tile_info.loc_h_tile ==
- output_info->tile_info.loc_h_tile) &&
- (other_output_info->tile_info.loc_v_tile <
- output_info->tile_info.loc_v_tile))
- y += other_output_info->tile_info.tile_h;
- break;
- case META_MONITOR_TRANSFORM_180:
- case META_MONITOR_TRANSFORM_FLIPPED_180:
- if ((other_output_info->tile_info.loc_v_tile ==
- output_info->tile_info.loc_v_tile) &&
- (other_output_info->tile_info.loc_h_tile >
- output_info->tile_info.loc_h_tile))
- x += other_output_info->tile_info.tile_w;
- if ((other_output_info->tile_info.loc_h_tile ==
- output_info->tile_info.loc_h_tile) &&
- (other_output_info->tile_info.loc_v_tile >
- output_info->tile_info.loc_v_tile))
- y += other_output_info->tile_info.tile_h;
- break;
- case META_MONITOR_TRANSFORM_270:
- case META_MONITOR_TRANSFORM_FLIPPED_270:
- if ((other_output_info->tile_info.loc_v_tile ==
- output_info->tile_info.loc_v_tile) &&
- (other_output_info->tile_info.loc_h_tile >
- output_info->tile_info.loc_h_tile))
- y += other_output_info->tile_info.tile_w;
- if ((other_output_info->tile_info.loc_h_tile ==
- output_info->tile_info.loc_h_tile) &&
- (other_output_info->tile_info.loc_v_tile >
- output_info->tile_info.loc_v_tile))
- x += other_output_info->tile_info.tile_h;
- break;
- case META_MONITOR_TRANSFORM_90:
- case META_MONITOR_TRANSFORM_FLIPPED_90:
- if ((other_output_info->tile_info.loc_v_tile ==
- output_info->tile_info.loc_v_tile) &&
- (other_output_info->tile_info.loc_h_tile <
- output_info->tile_info.loc_h_tile))
- y += other_output_info->tile_info.tile_w;
- if ((other_output_info->tile_info.loc_h_tile ==
- output_info->tile_info.loc_h_tile) &&
- (other_output_info->tile_info.loc_v_tile <
- output_info->tile_info.loc_v_tile))
- x += other_output_info->tile_info.tile_h;
- break;
- }
- }
-
- *out_x = x;
- *out_y = y;
-}
-
-static void
-meta_monitor_tiled_calculate_tiled_size (MetaMonitor *monitor,
- int *out_width,
- int *out_height)
-{
- MetaMonitorPrivate *monitor_priv =
- meta_monitor_get_instance_private (monitor);
- GList *l;
- int width;
- int height;
-
- width = 0;
- height = 0;
- for (l = monitor_priv->outputs; l; l = l->next)
- {
- const MetaOutputInfo *output_info = meta_output_get_info (l->data);
-
- if (output_info->tile_info.loc_v_tile == 0)
- width += output_info->tile_info.tile_w;
-
- if (output_info->tile_info.loc_h_tile == 0)
- height += output_info->tile_info.tile_h;
- }
-
- *out_width = width;
- *out_height = height;
-}
-
-static gboolean
-is_monitor_mode_assigned (MetaMonitor *monitor,
- MetaMonitorMode *mode)
-{
- MetaMonitorPrivate *priv = meta_monitor_get_instance_private (monitor);
- GList *l;
- int i;
-
- for (l = priv->outputs, i = 0; l; l = l->next, i++)
- {
- MetaOutput *output = l->data;
- MetaMonitorCrtcMode *monitor_crtc_mode = &mode->crtc_modes[i];
- MetaCrtc *crtc;
- const MetaCrtcConfig *crtc_config;
-
- crtc = meta_output_get_assigned_crtc (output);
- crtc_config = crtc ? meta_crtc_get_config (crtc) : NULL;
-
- if (monitor_crtc_mode->crtc_mode &&
- (!crtc || !crtc_config ||
- crtc_config->mode != monitor_crtc_mode->crtc_mode))
- return FALSE;
- else if (!monitor_crtc_mode->crtc_mode && crtc)
- return FALSE;
- }
-
- return TRUE;
-}
-
-static gboolean
-is_crtc_mode_tiled (MetaOutput *output,
- MetaCrtcMode *crtc_mode)
-{
- const MetaOutputInfo *output_info = meta_output_get_info (output);
- const MetaCrtcModeInfo *crtc_mode_info = meta_crtc_mode_get_info (crtc_mode);
-
- return (crtc_mode_info->width == (int) output_info->tile_info.tile_w &&
- crtc_mode_info->height == (int) output_info->tile_info.tile_h);
-}
-
-static MetaCrtcMode *
-find_tiled_crtc_mode (MetaOutput *output,
- MetaCrtcMode *reference_crtc_mode)
-{
- const MetaOutputInfo *output_info = meta_output_get_info (output);
- const MetaCrtcModeInfo *reference_crtc_mode_info =
- meta_crtc_mode_get_info (reference_crtc_mode);
- MetaCrtcMode *crtc_mode;
- unsigned int i;
-
- crtc_mode = output_info->preferred_mode;
- if (is_crtc_mode_tiled (output, crtc_mode))
- return crtc_mode;
-
- for (i = 0; i < output_info->n_modes; i++)
- {
- const MetaCrtcModeInfo *crtc_mode_info;
-
- crtc_mode = output_info->modes[i];
- crtc_mode_info = meta_crtc_mode_get_info (crtc_mode);
-
- if (!is_crtc_mode_tiled (output, crtc_mode))
- continue;
-
- if (crtc_mode_info->refresh_rate != reference_crtc_mode_info->refresh_rate)
- continue;
-
- if (crtc_mode_info->flags != reference_crtc_mode_info->flags)
- continue;
-
- return crtc_mode;
- }
-
- return NULL;
-}
-
-static MetaMonitorMode *
-create_tiled_monitor_mode (MetaMonitorTiled *monitor_tiled,
- MetaCrtcMode *reference_crtc_mode,
- gboolean *out_is_preferred)
-{
- MetaMonitor *monitor = META_MONITOR (monitor_tiled);
- MetaMonitorPrivate *monitor_priv =
- meta_monitor_get_instance_private (monitor);
- MetaMonitorModeTiled *mode;
- int width, height;
- GList *l;
- unsigned int i;
- gboolean is_preferred = TRUE;
-
- mode = g_new0 (MetaMonitorModeTiled, 1);
- mode->is_tiled = TRUE;
- meta_monitor_tiled_calculate_tiled_size (monitor, &width, &height);
- mode->parent.monitor = monitor;
- mode->parent.spec =
- meta_monitor_create_spec (monitor, width, height, reference_crtc_mode);
- mode->parent.id = generate_mode_id (&mode->parent.spec);
-
- mode->parent.crtc_modes = g_new0 (MetaMonitorCrtcMode,
- g_list_length (monitor_priv->outputs));
- for (l = monitor_priv->outputs, i = 0; l; l = l->next, i++)
- {
- MetaOutput *output = l->data;
- const MetaOutputInfo *output_info = meta_output_get_info (output);
- MetaCrtcMode *tiled_crtc_mode;
-
- tiled_crtc_mode = find_tiled_crtc_mode (output, reference_crtc_mode);
- if (!tiled_crtc_mode)
- {
- g_warning ("No tiled mode found on %s", meta_output_get_name (output));
- meta_monitor_mode_free ((MetaMonitorMode *) mode);
- return NULL;
- }
-
- mode->parent.crtc_modes[i] = (MetaMonitorCrtcMode) {
- .output = output,
- .crtc_mode = tiled_crtc_mode
- };
-
- is_preferred = (is_preferred &&
- tiled_crtc_mode == output_info->preferred_mode);
- }
-
- *out_is_preferred = is_preferred;
-
- return (MetaMonitorMode *) mode;
-}
-
-static void
-generate_tiled_monitor_modes (MetaMonitorTiled *monitor_tiled)
-{
- MetaMonitor *monitor = META_MONITOR (monitor_tiled);
- MetaMonitorPrivate *monitor_priv =
- meta_monitor_get_instance_private (monitor);
- MetaOutput *main_output;
- const MetaOutputInfo *main_output_info;
- GList *tiled_modes = NULL;
- unsigned int i;
- MetaMonitorMode *best_mode = NULL;
- GList *l;
-
- main_output = meta_monitor_get_main_output (META_MONITOR (monitor_tiled));
- main_output_info = meta_output_get_info (main_output);
-
- for (i = 0; i < main_output_info->n_modes; i++)
- {
- MetaCrtcMode *reference_crtc_mode = main_output_info->modes[i];
- MetaMonitorMode *mode;
- gboolean is_preferred;
-
- if (!is_crtc_mode_tiled (main_output, reference_crtc_mode))
- continue;
-
- mode = create_tiled_monitor_mode (monitor_tiled, reference_crtc_mode,
- &is_preferred);
- if (!mode)
- continue;
-
- tiled_modes = g_list_append (tiled_modes, mode);
-
- if (is_monitor_mode_assigned (monitor, mode))
- monitor_priv->current_mode = mode;
-
- if (is_preferred)
- monitor_priv->preferred_mode = mode;
- }
-
- while ((l = tiled_modes))
- {
- MetaMonitorMode *mode = l->data;
-
- tiled_modes = g_list_remove_link (tiled_modes, l);
-
- if (!meta_monitor_add_mode (monitor, mode, FALSE))
- {
- meta_monitor_mode_free (mode);
- continue;
- }
-
- if (!monitor_priv->preferred_mode)
- {
- if (!best_mode ||
- mode->spec.refresh_rate > best_mode->spec.refresh_rate)
- best_mode = mode;
- }
- }
-
- if (best_mode)
- monitor_priv->preferred_mode = best_mode;
-}
-
-static MetaMonitorMode *
-create_untiled_monitor_mode (MetaMonitorTiled *monitor_tiled,
- MetaOutput *main_output,
- MetaCrtcMode *crtc_mode)
-{
- MetaMonitor *monitor = META_MONITOR (monitor_tiled);
- MetaMonitorPrivate *monitor_priv =
- meta_monitor_get_instance_private (monitor);
- MetaMonitorModeTiled *mode;
- const MetaCrtcModeInfo *crtc_mode_info;
- GList *l;
- int i;
-
- if (is_crtc_mode_tiled (main_output, crtc_mode))
- return NULL;
-
- mode = g_new0 (MetaMonitorModeTiled, 1);
- mode->is_tiled = FALSE;
- mode->parent.monitor = monitor;
-
- crtc_mode_info = meta_crtc_mode_get_info (crtc_mode);
- mode->parent.spec = meta_monitor_create_spec (monitor,
- crtc_mode_info->width,
- crtc_mode_info->height,
- crtc_mode);
- mode->parent.id = generate_mode_id (&mode->parent.spec);
- mode->parent.crtc_modes = g_new0 (MetaMonitorCrtcMode,
- g_list_length (monitor_priv->outputs));
-
- for (l = monitor_priv->outputs, i = 0; l; l = l->next, i++)
- {
- MetaOutput *output = l->data;
-
- if (output == main_output)
- {
- mode->parent.crtc_modes[i] = (MetaMonitorCrtcMode) {
- .output = output,
- .crtc_mode = crtc_mode
- };
- }
- else
- {
- mode->parent.crtc_modes[i] = (MetaMonitorCrtcMode) {
- .output = output,
- .crtc_mode = NULL
- };
- }
- }
-
- return &mode->parent;
-}
-
-static int
-count_untiled_crtc_modes (MetaOutput *output)
-{
- const MetaOutputInfo *output_info = meta_output_get_info (output);
- int count;
- unsigned int i;
-
- count = 0;
- for (i = 0; i < output_info->n_modes; i++)
- {
- MetaCrtcMode *crtc_mode = output_info->modes[i];
-
- if (!is_crtc_mode_tiled (output, crtc_mode))
- count++;
- }
-
- return count;
-}
-
-static MetaOutput *
-find_untiled_output (MetaMonitorTiled *monitor_tiled)
-{
- MetaMonitor *monitor = META_MONITOR (monitor_tiled);
- MetaMonitorPrivate *monitor_priv =
- meta_monitor_get_instance_private (monitor);
- MetaOutput *best_output;
- int best_untiled_crtc_mode_count;
- GList *l;
-
- best_output = monitor_tiled->origin_output;
- best_untiled_crtc_mode_count =
- count_untiled_crtc_modes (monitor_tiled->origin_output);
-
- for (l = monitor_priv->outputs; l; l = l->next)
- {
- MetaOutput *output = l->data;
- int untiled_crtc_mode_count;
-
- if (output == monitor_tiled->origin_output)
- continue;
-
- untiled_crtc_mode_count = count_untiled_crtc_modes (output);
- if (untiled_crtc_mode_count > best_untiled_crtc_mode_count)
- {
- best_untiled_crtc_mode_count = untiled_crtc_mode_count;
- best_output = output;
- }
- }
-
- return best_output;
-}
-
-static void
-generate_untiled_monitor_modes (MetaMonitorTiled *monitor_tiled)
-{
- MetaMonitor *monitor = META_MONITOR (monitor_tiled);
- MetaMonitorPrivate *monitor_priv =
- meta_monitor_get_instance_private (monitor);
- MetaOutput *main_output;
- const MetaOutputInfo *main_output_info;
- unsigned int i;
-
- main_output = meta_monitor_get_main_output (monitor);
- main_output_info = meta_output_get_info (main_output);
-
- for (i = 0; i < main_output_info->n_modes; i++)
- {
- MetaCrtcMode *crtc_mode = main_output_info->modes[i];
- MetaMonitorMode *mode;
-
- mode = create_untiled_monitor_mode (monitor_tiled,
- main_output,
- crtc_mode);
- if (!mode)
- continue;
-
- if (!meta_monitor_add_mode (monitor, mode, FALSE))
- {
- meta_monitor_mode_free (mode);
- continue;
- }
-
- if (is_monitor_mode_assigned (monitor, mode))
- {
- g_assert (!monitor_priv->current_mode);
- monitor_priv->current_mode = mode;
- }
-
- if (!monitor_priv->preferred_mode &&
- crtc_mode == main_output_info->preferred_mode)
- monitor_priv->preferred_mode = mode;
- }
-}
-
-static MetaMonitorMode *
-find_best_mode (MetaMonitor *monitor)
-{
- MetaMonitorPrivate *monitor_priv =
- meta_monitor_get_instance_private (monitor);
- MetaMonitorMode *best_mode = NULL;
- GList *l;
-
- for (l = monitor_priv->modes; l; l = l->next)
- {
- MetaMonitorMode *mode = l->data;
- int area, best_area;
-
- if (!best_mode)
- {
- best_mode = mode;
- continue;
- }
-
- area = mode->spec.width * mode->spec.height;
- best_area = best_mode->spec.width * best_mode->spec.height;
- if (area > best_area)
- {
- best_mode = mode;
- continue;
- }
-
- if (mode->spec.refresh_rate > best_mode->spec.refresh_rate)
- {
- best_mode = mode;
- continue;
- }
- }
-
- return best_mode;
-}
-
-static void
-meta_monitor_tiled_generate_modes (MetaMonitorTiled *monitor_tiled)
-{
- MetaMonitor *monitor = META_MONITOR (monitor_tiled);
- MetaMonitorPrivate *monitor_priv =
- meta_monitor_get_instance_private (monitor);
-
- /*
- * Tiled monitors may look a bit different from each other, depending on the
- * monitor itself, the driver, etc.
- *
- * On some, the tiled modes will be the preferred CRTC modes, and running
- * untiled is done by only enabling (0, 0) tile. In this case, things are
- * pretty straight forward.
- *
- * Other times a monitor may have some bogus mode preferred on the main tile,
- * and an untiled mode preferred on the non-main tile, and there seems to be
- * no guarantee that the (0, 0) tile is the one that should drive the
- * non-tiled mode.
- *
- * To handle both these cases, the following hueristics are implemented:
- *
- * 1) Find all the tiled CRTC modes of the (0, 0) tile, and create tiled
- * monitor modes for all tiles based on these.
- * 2) If there is any tiled monitor mode combination where all CRTC modes
- * are the preferred ones, that one is marked as preferred.
- * 3) If there is no preferred mode determined so far, assume the tiled
- * monitor mode with the highest refresh rate is preferred.
- * 4) Find the tile with highest number of untiled CRTC modes available,
- * assume this is the one driving the monitor in untiled mode, and
- * create monitor modes for all untiled CRTC modes of that tile. If
- * there is still no preferred mode, set any untiled mode as preferred
- * if the CRTC mode is marked as such.
- * 5) If at this point there is still no preferred mode, just pick the one
- * with the highest number of pixels and highest refresh rate.
- *
- * Note that this ignores the preference if the preference is a non-tiled
- * mode. This seems to be the case on some systems, where the user tends to
- * manually set up the tiled mode anyway.
- */
-
- generate_tiled_monitor_modes (monitor_tiled);
-
- if (!monitor_priv->preferred_mode)
- g_warning ("Tiled monitor on %s didn't have any tiled modes",
- monitor_priv->spec->connector);
-
- generate_untiled_monitor_modes (monitor_tiled);
-
- if (!monitor_priv->preferred_mode)
- {
- g_warning ("Tiled monitor on %s didn't have a valid preferred mode",
- monitor_priv->spec->connector);
- monitor_priv->preferred_mode = find_best_mode (monitor);
- }
-}
-
-MetaMonitorTiled *
-meta_monitor_tiled_new (MetaMonitorManager *monitor_manager,
- MetaOutput *output)
-{
- const MetaOutputInfo *output_info = meta_output_get_info (output);
- MetaMonitorTiled *monitor_tiled;
- MetaMonitor *monitor;
- MetaMonitorPrivate *monitor_priv;
-
- monitor_tiled = g_object_new (META_TYPE_MONITOR_TILED, NULL);
- monitor = META_MONITOR (monitor_tiled);
- monitor_priv = meta_monitor_get_instance_private (monitor);
-
- monitor_priv->backend = meta_monitor_manager_get_backend (monitor_manager);
-
- monitor_tiled->tile_group_id = output_info->tile_info.group_id;
- monitor_priv->winsys_id = meta_output_get_id (output);
-
- monitor_tiled->origin_output = output;
- add_tiled_monitor_outputs (meta_output_get_gpu (output), monitor_tiled);
-
- monitor_tiled->main_output = find_untiled_output (monitor_tiled);
-
- meta_monitor_generate_spec (monitor);
-
- monitor_tiled->monitor_manager = monitor_manager;
- meta_monitor_manager_tiled_monitor_added (monitor_manager,
- META_MONITOR (monitor_tiled));
-
- meta_monitor_tiled_generate_modes (monitor_tiled);
-
- monitor_priv->display_name = meta_monitor_make_display_name (monitor,
- monitor_manager);
-
- return monitor_tiled;
-}
-
-static MetaOutput *
-meta_monitor_tiled_get_main_output (MetaMonitor *monitor)
-{
- MetaMonitorTiled *monitor_tiled = META_MONITOR_TILED (monitor);
-
- return monitor_tiled->main_output;
-}
-
-static void
-meta_monitor_tiled_derive_layout (MetaMonitor *monitor,
- MetaRectangle *layout)
-{
- MetaMonitorPrivate *monitor_priv =
- meta_monitor_get_instance_private (monitor);
- GList *l;
- float min_x, min_y, max_x, max_y;
-
- min_x = FLT_MAX;
- min_y = FLT_MAX;
- max_x = 0.0;
- max_y = 0.0;
- for (l = monitor_priv->outputs; l; l = l->next)
- {
- MetaOutput *output = l->data;
- MetaCrtc *crtc;
- const MetaCrtcConfig *crtc_config;
- const graphene_rect_t *crtc_layout;
-
- crtc = meta_output_get_assigned_crtc (output);
- if (!crtc)
- continue;
-
- crtc_config = meta_crtc_get_config (crtc);
- g_return_if_fail (crtc_config);
-
- crtc_layout = &crtc_config->layout;
-
- min_x = MIN (crtc_layout->origin.x, min_x);
- min_y = MIN (crtc_layout->origin.y, min_y);
- max_x = MAX (crtc_layout->origin.x + crtc_layout->size.width, max_x);
- max_y = MAX (crtc_layout->origin.y + crtc_layout->size.height, max_y);
- }
-
- *layout = (MetaRectangle) {
- .x = roundf (min_x),
- .y = roundf (min_y),
- .width = roundf (max_x - min_x),
- .height = roundf (max_y - min_y)
- };
-}
-
-static gboolean
-meta_monitor_tiled_get_suggested_position (MetaMonitor *monitor,
- int *x,
- int *y)
-{
- return FALSE;
-}
-
-static void
-meta_monitor_tiled_calculate_crtc_pos (MetaMonitor *monitor,
- MetaMonitorMode *monitor_mode,
- MetaOutput *output,
- MetaMonitorTransform crtc_transform,
- int *out_x,
- int *out_y)
-{
- MetaMonitorModeTiled *mode_tiled = (MetaMonitorModeTiled *) monitor_mode;
-
- if (mode_tiled->is_tiled)
- {
- calculate_tile_coordinate (monitor, output, crtc_transform,
- out_x, out_y);
- }
- else
- {
- *out_x = 0;
- *out_y = 0;
- }
-}
-
-static void
-meta_monitor_tiled_finalize (GObject *object)
-{
- MetaMonitorTiled *monitor_tiled = META_MONITOR_TILED (object);
-
- meta_monitor_manager_tiled_monitor_removed (monitor_tiled->monitor_manager,
- META_MONITOR (monitor_tiled));
-
- G_OBJECT_CLASS (meta_monitor_tiled_parent_class)->finalize (object);
-}
-
-static void
-meta_monitor_tiled_init (MetaMonitorTiled *monitor)
-{
-}
-
-static void
-meta_monitor_tiled_class_init (MetaMonitorTiledClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
- MetaMonitorClass *monitor_class = META_MONITOR_CLASS (klass);
-
- object_class->finalize = meta_monitor_tiled_finalize;
-
- monitor_class->get_main_output = meta_monitor_tiled_get_main_output;
- monitor_class->derive_layout = meta_monitor_tiled_derive_layout;
- monitor_class->calculate_crtc_pos = meta_monitor_tiled_calculate_crtc_pos;
- monitor_class->get_suggested_position = meta_monitor_tiled_get_suggested_position;
-}
-
-static void
-meta_monitor_mode_free (MetaMonitorMode *monitor_mode)
-{
- g_free (monitor_mode->id);
- g_free (monitor_mode->crtc_modes);
- g_free (monitor_mode);
-}
-
-MetaMonitorSpec *
-meta_monitor_get_spec (MetaMonitor *monitor)
-{
- MetaMonitorPrivate *priv = meta_monitor_get_instance_private (monitor);
-
- return priv->spec;
-}
-
-MetaLogicalMonitor *
-meta_monitor_get_logical_monitor (MetaMonitor *monitor)
-{
- MetaMonitorPrivate *priv = meta_monitor_get_instance_private (monitor);
-
- return priv->logical_monitor;
-}
-
-MetaMonitorMode *
-meta_monitor_get_mode_from_id (MetaMonitor *monitor,
- const char *monitor_mode_id)
-{
- MetaMonitorPrivate *priv = meta_monitor_get_instance_private (monitor);
-
- return g_hash_table_lookup (priv->mode_ids, monitor_mode_id);
-}
-
-static gboolean
-meta_monitor_mode_spec_equals (MetaMonitorModeSpec *monitor_mode_spec,
- MetaMonitorModeSpec *other_monitor_mode_spec)
-{
- return (monitor_mode_spec->width == other_monitor_mode_spec->width &&
- monitor_mode_spec->height == other_monitor_mode_spec->height &&
- ABS (monitor_mode_spec->refresh_rate -
- other_monitor_mode_spec->refresh_rate) < MAXIMUM_REFRESH_RATE_DIFF &&
- monitor_mode_spec->flags == other_monitor_mode_spec->flags);
-}
-
-MetaMonitorMode *
-meta_monitor_get_mode_from_spec (MetaMonitor *monitor,
- MetaMonitorModeSpec *monitor_mode_spec)
-{
- MetaMonitorPrivate *priv = meta_monitor_get_instance_private (monitor);
- GList *l;
-
- for (l = priv->modes; l; l = l->next)
- {
- MetaMonitorMode *monitor_mode = l->data;
-
- if (meta_monitor_mode_spec_equals (monitor_mode_spec,
- &monitor_mode->spec))
- return monitor_mode;
- }
-
- return NULL;
-}
-
-MetaMonitorMode *
-meta_monitor_get_preferred_mode (MetaMonitor *monitor)
-{
- MetaMonitorPrivate *priv = meta_monitor_get_instance_private (monitor);
-
- return priv->preferred_mode;
-}
-
-MetaMonitorMode *
-meta_monitor_get_current_mode (MetaMonitor *monitor)
-{
- MetaMonitorPrivate *priv = meta_monitor_get_instance_private (monitor);
-
- return priv->current_mode;
-}
-
-static gboolean
-is_current_mode_known (MetaMonitor *monitor)
-{
- MetaOutput *output;
- MetaCrtc *crtc;
-
- output = meta_monitor_get_main_output (monitor);
- crtc = meta_output_get_assigned_crtc (output);
-
- return (meta_monitor_is_active (monitor) ==
- (crtc && meta_crtc_get_config (crtc)));
-}
-
-void
-meta_monitor_derive_current_mode (MetaMonitor *monitor)
-{
- MetaMonitorPrivate *priv = meta_monitor_get_instance_private (monitor);
- MetaMonitorMode *current_mode = NULL;
- GList *l;
-
- for (l = priv->modes; l; l = l->next)
- {
- MetaMonitorMode *mode = l->data;
-
- if (is_monitor_mode_assigned (monitor, mode))
- {
- current_mode = mode;
- break;
- }
- }
-
- priv->current_mode = current_mode;
-
- g_warn_if_fail (is_current_mode_known (monitor));
-}
-
-void
-meta_monitor_set_current_mode (MetaMonitor *monitor,
- MetaMonitorMode *mode)
-{
- MetaMonitorPrivate *priv = meta_monitor_get_instance_private (monitor);
-
- priv->current_mode = mode;
-}
-
-GList *
-meta_monitor_get_modes (MetaMonitor *monitor)
-{
- MetaMonitorPrivate *priv = meta_monitor_get_instance_private (monitor);
-
- return priv->modes;
-}
-
-void
-meta_monitor_calculate_crtc_pos (MetaMonitor *monitor,
- MetaMonitorMode *monitor_mode,
- MetaOutput *output,
- MetaMonitorTransform crtc_transform,
- int *out_x,
- int *out_y)
-{
- META_MONITOR_GET_CLASS (monitor)->calculate_crtc_pos (monitor,
- monitor_mode,
- output,
- crtc_transform,
- out_x,
- out_y);
-}
-
-/* The minimum resolution at which we turn on a window-scale of 2 */
-#define HIDPI_LIMIT 192
-
-/*
- * The minimum screen height at which we turn on a window-scale of 2;
- * below this there just isn't enough vertical real estate for GNOME
- * apps to work, and it's better to just be tiny
- */
-#define HIDPI_MIN_HEIGHT 1200
-
-/* From http://en.wikipedia.org/wiki/4K_resolution#Resolutions_of_common_formats */
-#define SMALLEST_4K_WIDTH 3656
-
-static float
-calculate_scale (MetaMonitor *monitor,
- MetaMonitorMode *monitor_mode)
-{
- int resolution_width, resolution_height;
- int width_mm, height_mm;
- int scale;
-
- scale = 1.0;
-
- meta_monitor_mode_get_resolution (monitor_mode,
- &resolution_width,
- &resolution_height);
-
- if (resolution_height < HIDPI_MIN_HEIGHT)
- goto out;
-
- /* 4K TV */
- switch (meta_monitor_get_connector_type (monitor))
- {
- case META_CONNECTOR_TYPE_HDMIA:
- case META_CONNECTOR_TYPE_HDMIB:
- if (resolution_width < SMALLEST_4K_WIDTH)
- goto out;
- break;
- default:
- break;
- }
-
- meta_monitor_get_physical_dimensions (monitor, &width_mm, &height_mm);
-
- /*
- * Somebody encoded the aspect ratio (16/9 or 16/10) instead of the physical
- * size.
- */
- if (meta_monitor_has_aspect_as_size (monitor))
- goto out;
-
- if (width_mm > 0 && height_mm > 0)
- {
- double dpi_x, dpi_y;
-
- dpi_x = (double) resolution_width / (width_mm / 25.4);
- dpi_y = (double) resolution_height / (height_mm / 25.4);
-
- /*
- * We don't completely trust these values so both must be high, and never
- * pick higher ratio than 2 automatically.
- */
- if (dpi_x > HIDPI_LIMIT && dpi_y > HIDPI_LIMIT)
- scale = 2.0;
- }
-
-out:
- return scale;
-}
-
-float
-meta_monitor_calculate_mode_scale (MetaMonitor *monitor,
- MetaMonitorMode *monitor_mode)
-{
- MetaBackend *backend = meta_get_backend ();
- MetaSettings *settings = meta_backend_get_settings (backend);
- int global_scaling_factor;
-
- if (meta_settings_get_global_scaling_factor (settings,
- &global_scaling_factor))
- return global_scaling_factor;
-
- return calculate_scale (monitor, monitor_mode);
-}
-
-static gboolean
-is_logical_size_large_enough (int width,
- int height)
-{
- return width * height >= MINIMUM_LOGICAL_AREA;
-}
-
-gboolean
-meta_monitor_mode_should_be_advertised (MetaMonitorMode *monitor_mode)
-{
- MetaMonitorMode *preferred_mode;
-
- g_return_val_if_fail (monitor_mode != NULL, FALSE);
-
- preferred_mode = meta_monitor_get_preferred_mode (monitor_mode->monitor);
- if (monitor_mode->spec.width == preferred_mode->spec.width &&
- monitor_mode->spec.height == preferred_mode->spec.height)
- return TRUE;
-
- return is_logical_size_large_enough (monitor_mode->spec.width,
- monitor_mode->spec.height);
-}
-
-static float
-get_closest_scale_factor_for_resolution (float width,
- float height,
- float scale)
-{
- unsigned int i, j;
- float scaled_h;
- float scaled_w;
- float best_scale;
- int base_scaled_w;
- gboolean found_one;
-
- best_scale = 0;
- scaled_w = width / scale;
- scaled_h = height / scale;
-
- if (scale < MINIMUM_SCALE_FACTOR ||
- scale > MAXIMUM_SCALE_FACTOR ||
- !is_logical_size_large_enough (floorf (scaled_w), floorf (scaled_h)))
- goto out;
-
- if (floorf (scaled_w) == scaled_w && floorf (scaled_h) == scaled_h)
- return scale;
-
- i = 0;
- found_one = FALSE;
- base_scaled_w = floorf (scaled_w);
-
- do
- {
- for (j = 0; j < 2; j++)
- {
- float current_scale;
- int offset = i * (j ? 1 : -1);
-
- scaled_w = base_scaled_w + offset;
- current_scale = width / scaled_w;
- scaled_h = height / current_scale;
-
- if (current_scale >= scale + SCALE_FACTORS_STEPS ||
- current_scale <= scale - SCALE_FACTORS_STEPS ||
- current_scale < MINIMUM_SCALE_FACTOR ||
- current_scale > MAXIMUM_SCALE_FACTOR)
- {
- goto out;
- }
-
- if (floorf (scaled_h) == scaled_h)
- {
- found_one = TRUE;
-
- if (fabsf (current_scale - scale) < fabsf (best_scale - scale))
- best_scale = current_scale;
- }
- }
-
- i++;
- }
- while (!found_one);
-
-out:
- return best_scale;
-}
-
-float *
-meta_monitor_calculate_supported_scales (MetaMonitor *monitor,
- MetaMonitorMode *monitor_mode,
- MetaMonitorScalesConstraint constraints,
- int *n_supported_scales)
-{
- unsigned int i, j;
- int width, height;
- GArray *supported_scales;
-
- supported_scales = g_array_new (FALSE, FALSE, sizeof (float));
-
- meta_monitor_mode_get_resolution (monitor_mode, &width, &height);
-
- for (i = floorf (MINIMUM_SCALE_FACTOR);
- i <= ceilf (MAXIMUM_SCALE_FACTOR);
- i++)
- {
- for (j = 0; j < SCALE_FACTORS_PER_INTEGER; j++)
- {
- float scale;
- float scale_value = i + j * SCALE_FACTORS_STEPS;
-
- if ((constraints & META_MONITOR_SCALES_CONSTRAINT_NO_FRAC) &&
- fmodf (scale_value, 1.0) != 0.0)
- {
- continue;
- }
-
- scale = get_closest_scale_factor_for_resolution (width,
- height,
- scale_value);
-
- if (scale > 0.0f)
- g_array_append_val (supported_scales, scale);
- }
- }
-
- if (supported_scales->len == 0)
- {
- float fallback_scale;
-
- fallback_scale = 1.0;
- g_array_append_val (supported_scales, fallback_scale);
- }
-
- *n_supported_scales = supported_scales->len;
- return (float *) g_array_free (supported_scales, FALSE);
-}
-
-MetaMonitorModeSpec *
-meta_monitor_mode_get_spec (MetaMonitorMode *monitor_mode)
-{
- return &monitor_mode->spec;
-}
-
-const char *
-meta_monitor_mode_get_id (MetaMonitorMode *monitor_mode)
-{
- return monitor_mode->id;
-}
-
-void
-meta_monitor_mode_get_resolution (MetaMonitorMode *monitor_mode,
- int *width,
- int *height)
-{
- *width = monitor_mode->spec.width;
- *height = monitor_mode->spec.height;
-}
-
-float
-meta_monitor_mode_get_refresh_rate (MetaMonitorMode *monitor_mode)
-{
- return monitor_mode->spec.refresh_rate;
-}
-
-MetaCrtcModeFlag
-meta_monitor_mode_get_flags (MetaMonitorMode *monitor_mode)
-{
- return monitor_mode->spec.flags;
-}
-
-gboolean
-meta_monitor_mode_foreach_crtc (MetaMonitor *monitor,
- MetaMonitorMode *mode,
- MetaMonitorModeFunc func,
- gpointer user_data,
- GError **error)
-{
- MetaMonitorPrivate *monitor_priv =
- meta_monitor_get_instance_private (monitor);
- GList *l;
- int i;
-
- for (l = monitor_priv->outputs, i = 0; l; l = l->next, i++)
- {
- MetaMonitorCrtcMode *monitor_crtc_mode = &mode->crtc_modes[i];
-
- if (!monitor_crtc_mode->crtc_mode)
- continue;
-
- if (!func (monitor, mode, monitor_crtc_mode, user_data, error))
- return FALSE;
- }
-
- return TRUE;
-}
-
-gboolean
-meta_monitor_mode_foreach_output (MetaMonitor *monitor,
- MetaMonitorMode *mode,
- MetaMonitorModeFunc func,
- gpointer user_data,
- GError **error)
-{
- MetaMonitorPrivate *monitor_priv =
- meta_monitor_get_instance_private (monitor);
- GList *l;
- int i;
-
- for (l = monitor_priv->outputs, i = 0; l; l = l->next, i++)
- {
- MetaMonitorCrtcMode *monitor_crtc_mode = &mode->crtc_modes[i];
-
- if (!func (monitor, mode, monitor_crtc_mode, user_data, error))
- return FALSE;
- }
-
- return TRUE;
-}
-
-MetaMonitorCrtcMode *
-meta_monitor_get_crtc_mode_for_output (MetaMonitor *monitor,
- MetaMonitorMode *mode,
- MetaOutput *output)
-{
- MetaMonitorPrivate *monitor_priv =
- meta_monitor_get_instance_private (monitor);
- GList *l;
- int i;
-
- for (l = monitor_priv->outputs, i = 0; l; l = l->next, i++)
- {
- MetaMonitorCrtcMode *monitor_crtc_mode = &mode->crtc_modes[i];
-
- if (monitor_crtc_mode->output == output)
- return monitor_crtc_mode;
- }
-
- g_warn_if_reached ();
- return NULL;
-}
-
-const char *
-meta_monitor_get_display_name (MetaMonitor *monitor)
-{
- MetaMonitorPrivate *monitor_priv =
- meta_monitor_get_instance_private (monitor);
-
- return monitor_priv->display_name;
-}
-
-void
-meta_monitor_set_logical_monitor (MetaMonitor *monitor,
- MetaLogicalMonitor *logical_monitor)
-{
- MetaMonitorPrivate *priv = meta_monitor_get_instance_private (monitor);
-
- priv->logical_monitor = logical_monitor;
-}
diff --git a/src/backends/meta-monitor.h b/src/backends/meta-monitor.h
deleted file mode 100644
index 341657ae3..000000000
--- a/src/backends/meta-monitor.h
+++ /dev/null
@@ -1,280 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2016 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-
-#ifndef META_MONITOR_H
-#define META_MONITOR_H
-
-#include <glib-object.h>
-
-#include "backends/meta-backend-types.h"
-#include "backends/meta-crtc.h"
-#include "backends/meta-output.h"
-
-typedef struct _MetaMonitorSpec
-{
- char *connector;
- char *vendor;
- char *product;
- char *serial;
-} MetaMonitorSpec;
-
-typedef struct _MetaMonitorModeSpec
-{
- int width;
- int height;
- float refresh_rate;
- MetaCrtcModeFlag flags;
-} MetaMonitorModeSpec;
-
-typedef struct _MetaMonitorCrtcMode
-{
- MetaOutput *output;
- MetaCrtcMode *crtc_mode;
-} MetaMonitorCrtcMode;
-
-#define HANDLED_CRTC_MODE_FLAGS (META_CRTC_MODE_FLAG_INTERLACE)
-
-typedef gboolean (* MetaMonitorModeFunc) (MetaMonitor *monitor,
- MetaMonitorMode *mode,
- MetaMonitorCrtcMode *monitor_crtc_mode,
- gpointer user_data,
- GError **error);
-
-typedef enum _MetaMonitorScalesConstraint
-{
- META_MONITOR_SCALES_CONSTRAINT_NONE = 0,
- META_MONITOR_SCALES_CONSTRAINT_NO_FRAC = (1 << 0),
-} MetaMonitorScalesConstraint;
-
-#define META_TYPE_MONITOR (meta_monitor_get_type ())
-META_EXPORT_TEST
-G_DECLARE_DERIVABLE_TYPE (MetaMonitor, meta_monitor, META, MONITOR, GObject)
-
-struct _MetaMonitorClass
-{
- GObjectClass parent_class;
-
- MetaOutput * (* get_main_output) (MetaMonitor *monitor);
- void (* derive_layout) (MetaMonitor *monitor,
- MetaRectangle *layout);
- void (* calculate_crtc_pos) (MetaMonitor *monitor,
- MetaMonitorMode *monitor_mode,
- MetaOutput *output,
- MetaMonitorTransform crtc_transform,
- int *out_x,
- int *out_y);
- gboolean (* get_suggested_position) (MetaMonitor *monitor,
- int *width,
- int *height);
-};
-
-#define META_TYPE_MONITOR_NORMAL (meta_monitor_normal_get_type ())
-G_DECLARE_FINAL_TYPE (MetaMonitorNormal, meta_monitor_normal,
- META, MONITOR_NORMAL,
- MetaMonitor)
-
-#define META_TYPE_MONITOR_TILED (meta_monitor_tiled_get_type ())
-G_DECLARE_FINAL_TYPE (MetaMonitorTiled, meta_monitor_tiled,
- META, MONITOR_TILED,
- MetaMonitor)
-
-MetaMonitorTiled * meta_monitor_tiled_new (MetaMonitorManager *monitor_manager,
- MetaOutput *output);
-
-MetaMonitorNormal * meta_monitor_normal_new (MetaMonitorManager *monitor_manager,
- MetaOutput *output);
-
-MetaMonitorSpec * meta_monitor_get_spec (MetaMonitor *monitor);
-
-MetaBackend * meta_monitor_get_backend (MetaMonitor *monitor);
-
-META_EXPORT_TEST
-gboolean meta_monitor_is_active (MetaMonitor *monitor);
-
-META_EXPORT_TEST
-MetaOutput * meta_monitor_get_main_output (MetaMonitor *monitor);
-
-gboolean meta_monitor_is_primary (MetaMonitor *monitor);
-
-gboolean meta_monitor_supports_underscanning (MetaMonitor *monitor);
-
-gboolean meta_monitor_is_underscanning (MetaMonitor *monitor);
-
-gboolean meta_monitor_is_laptop_panel (MetaMonitor *monitor);
-
-gboolean meta_monitor_is_same_as (MetaMonitor *monitor,
- MetaMonitor *other_monitor);
-
-META_EXPORT_TEST
-GList * meta_monitor_get_outputs (MetaMonitor *monitor);
-
-void meta_monitor_get_current_resolution (MetaMonitor *monitor,
- int *width,
- int *height);
-
-void meta_monitor_derive_layout (MetaMonitor *monitor,
- MetaRectangle *layout);
-
-META_EXPORT_TEST
-void meta_monitor_get_physical_dimensions (MetaMonitor *monitor,
- int *width_mm,
- int *height_mm);
-
-CoglSubpixelOrder meta_monitor_get_subpixel_order (MetaMonitor *monitor);
-
-META_EXPORT_TEST
-const char * meta_monitor_get_connector (MetaMonitor *monitor);
-
-META_EXPORT_TEST
-const char * meta_monitor_get_vendor (MetaMonitor *monitor);
-
-META_EXPORT_TEST
-const char * meta_monitor_get_product (MetaMonitor *monitor);
-
-META_EXPORT_TEST
-const char * meta_monitor_get_serial (MetaMonitor *monitor);
-
-META_EXPORT_TEST
-MetaConnectorType meta_monitor_get_connector_type (MetaMonitor *monitor);
-
-/* This function returns the transform corrected for the panel orientation */
-META_EXPORT_TEST
-MetaMonitorTransform meta_monitor_logical_to_crtc_transform (MetaMonitor *monitor,
- MetaMonitorTransform transform);
-/*
- * This function converts a transform corrected for the panel orientation
- * to its logical (user-visible) transform.
- */
-META_EXPORT_TEST
-MetaMonitorTransform meta_monitor_crtc_to_logical_transform (MetaMonitor *monitor,
- MetaMonitorTransform transform);
-
-META_EXPORT_TEST
-uint32_t meta_monitor_tiled_get_tile_group_id (MetaMonitorTiled *monitor_tiled);
-
-META_EXPORT_TEST
-gboolean meta_monitor_get_suggested_position (MetaMonitor *monitor,
- int *x,
- int *y);
-
-META_EXPORT_TEST
-MetaLogicalMonitor * meta_monitor_get_logical_monitor (MetaMonitor *monitor);
-
-META_EXPORT_TEST
-MetaMonitorMode * meta_monitor_get_mode_from_id (MetaMonitor *monitor,
- const char *monitor_mode_id);
-
-META_EXPORT_TEST
-MetaMonitorMode * meta_monitor_get_mode_from_spec (MetaMonitor *monitor,
- MetaMonitorModeSpec *monitor_mode_spec);
-
-META_EXPORT_TEST
-MetaMonitorMode * meta_monitor_get_preferred_mode (MetaMonitor *monitor);
-
-META_EXPORT_TEST
-MetaMonitorMode * meta_monitor_get_current_mode (MetaMonitor *monitor);
-
-META_EXPORT_TEST
-void meta_monitor_derive_current_mode (MetaMonitor *monitor);
-
-META_EXPORT_TEST
-void meta_monitor_set_current_mode (MetaMonitor *monitor,
- MetaMonitorMode *mode);
-
-META_EXPORT_TEST
-GList * meta_monitor_get_modes (MetaMonitor *monitor);
-
-META_EXPORT_TEST
-void meta_monitor_calculate_crtc_pos (MetaMonitor *monitor,
- MetaMonitorMode *monitor_mode,
- MetaOutput *output,
- MetaMonitorTransform crtc_transform,
- int *out_x,
- int *out_y);
-
-META_EXPORT_TEST
-float meta_monitor_calculate_mode_scale (MetaMonitor *monitor,
- MetaMonitorMode *monitor_mode);
-
-META_EXPORT_TEST
-float * meta_monitor_calculate_supported_scales (MetaMonitor *monitor,
- MetaMonitorMode *monitor_mode,
- MetaMonitorScalesConstraint constraints,
- int *n_supported_scales);
-
-META_EXPORT_TEST
-const char * meta_monitor_mode_get_id (MetaMonitorMode *monitor_mode);
-
-META_EXPORT_TEST
-MetaMonitorModeSpec * meta_monitor_mode_get_spec (MetaMonitorMode *monitor_mode);
-
-META_EXPORT_TEST
-void meta_monitor_mode_get_resolution (MetaMonitorMode *monitor_mode,
- int *width,
- int *height);
-
-META_EXPORT_TEST
-float meta_monitor_mode_get_refresh_rate (MetaMonitorMode *monitor_mode);
-
-META_EXPORT_TEST
-MetaCrtcModeFlag meta_monitor_mode_get_flags (MetaMonitorMode *monitor_mode);
-
-META_EXPORT_TEST
-gboolean meta_monitor_mode_foreach_crtc (MetaMonitor *monitor,
- MetaMonitorMode *mode,
- MetaMonitorModeFunc func,
- gpointer user_data,
- GError **error);
-
-META_EXPORT_TEST
-gboolean meta_monitor_mode_foreach_output (MetaMonitor *monitor,
- MetaMonitorMode *mode,
- MetaMonitorModeFunc func,
- gpointer user_data,
- GError **error);
-
-MetaMonitorCrtcMode * meta_monitor_get_crtc_mode_for_output (MetaMonitor *monitor,
- MetaMonitorMode *mode,
- MetaOutput *output);
-
-META_EXPORT_TEST
-gboolean meta_monitor_mode_should_be_advertised (MetaMonitorMode *monitor_mode);
-
-META_EXPORT_TEST
-MetaMonitorSpec * meta_monitor_spec_clone (MetaMonitorSpec *monitor_id);
-
-META_EXPORT_TEST
-gboolean meta_monitor_spec_equals (MetaMonitorSpec *monitor_id,
- MetaMonitorSpec *other_monitor_id);
-
-META_EXPORT_TEST
-int meta_monitor_spec_compare (MetaMonitorSpec *monitor_spec_a,
- MetaMonitorSpec *monitor_spec_b);
-
-META_EXPORT_TEST
-void meta_monitor_spec_free (MetaMonitorSpec *monitor_id);
-
-const char * meta_monitor_get_display_name (MetaMonitor *monitor);
-
-void meta_monitor_set_logical_monitor (MetaMonitor *monitor,
- MetaLogicalMonitor *logical_monitor);
-
-#endif /* META_MONITOR_H */
diff --git a/src/backends/meta-orientation-manager.c b/src/backends/meta-orientation-manager.c
deleted file mode 100644
index 52a1d1de6..000000000
--- a/src/backends/meta-orientation-manager.c
+++ /dev/null
@@ -1,335 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2017 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-
-#include "config.h"
-
-#include "backends/meta-orientation-manager.h"
-
-#include <gio/gio.h>
-
-enum
-{
- ORIENTATION_CHANGED,
-
- N_SIGNALS
-};
-
-static guint signals[N_SIGNALS];
-
-enum
-{
- PROP_0,
-
- PROP_HAS_ACCELEROMETER,
-
- PROP_LAST
-};
-
-static GParamSpec *props[PROP_LAST];
-
-struct _MetaOrientationManager
-{
- GObject parent_instance;
-
- GCancellable *cancellable;
-
- guint iio_watch_id;
- GDBusProxy *iio_proxy;
- MetaOrientation prev_orientation;
- MetaOrientation curr_orientation;
- guint has_accel : 1;
-
- GSettings *settings;
-};
-
-G_DEFINE_TYPE (MetaOrientationManager, meta_orientation_manager, G_TYPE_OBJECT)
-
-#define CONF_SCHEMA "org.gnome.settings-daemon.peripherals.touchscreen"
-#define ORIENTATION_LOCK_KEY "orientation-lock"
-
-static MetaOrientation
-orientation_from_string (const char *orientation)
-{
- if (g_strcmp0 (orientation, "normal") == 0)
- return META_ORIENTATION_NORMAL;
- if (g_strcmp0 (orientation, "bottom-up") == 0)
- return META_ORIENTATION_BOTTOM_UP;
- if (g_strcmp0 (orientation, "left-up") == 0)
- return META_ORIENTATION_LEFT_UP;
- if (g_strcmp0 (orientation, "right-up") == 0)
- return META_ORIENTATION_RIGHT_UP;
-
- return META_ORIENTATION_UNDEFINED;
-}
-
-static void
-read_iio_proxy (MetaOrientationManager *self)
-{
- GVariant *v;
-
- self->curr_orientation = META_ORIENTATION_UNDEFINED;
-
- if (!self->iio_proxy)
- {
- self->has_accel = FALSE;
- return;
- }
-
- v = g_dbus_proxy_get_cached_property (self->iio_proxy, "HasAccelerometer");
- if (v)
- {
- self->has_accel = !!g_variant_get_boolean (v);
- g_variant_unref (v);
- }
-
- if (self->has_accel)
- {
- v = g_dbus_proxy_get_cached_property (self->iio_proxy, "AccelerometerOrientation");
- if (v)
- {
- self->curr_orientation = orientation_from_string (g_variant_get_string (v, NULL));
- g_variant_unref (v);
- }
- }
-}
-
-static void
-sync_state (MetaOrientationManager *self)
-{
- gboolean had_accel = self->has_accel;
-
- read_iio_proxy (self);
-
- if (had_accel != self->has_accel)
- g_object_notify_by_pspec (G_OBJECT (self), props[PROP_HAS_ACCELEROMETER]);
-
- if (g_settings_get_boolean (self->settings, ORIENTATION_LOCK_KEY))
- return;
-
- if (self->prev_orientation == self->curr_orientation)
- return;
-
- self->prev_orientation = self->curr_orientation;
-
- if (self->curr_orientation == META_ORIENTATION_UNDEFINED)
- return;
-
- g_signal_emit (self, signals[ORIENTATION_CHANGED], 0);
-}
-
-static void
-orientation_lock_changed (GSettings *settings,
- gchar *key,
- gpointer user_data)
-{
- MetaOrientationManager *self = user_data;
- sync_state (self);
-}
-
-static void
-iio_properties_changed (GDBusProxy *proxy,
- GVariant *changed_properties,
- GStrv invalidated_properties,
- gpointer user_data)
-{
- MetaOrientationManager *self = user_data;
- sync_state (self);
-}
-
-static void
-accelerometer_claimed (GObject *source,
- GAsyncResult *res,
- gpointer user_data)
-{
- MetaOrientationManager *self = user_data;
- GVariant *v;
- GError *error = NULL;
-
- v = g_dbus_proxy_call_finish (G_DBUS_PROXY (source), res, &error);
- if (!v)
- {
- if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
- g_warning ("Failed to claim accelerometer: %s", error->message);
- g_error_free (error);
- return;
- }
-
- g_variant_unref (v);
-
- sync_state (self);
-}
-
-static void
-iio_proxy_ready (GObject *source,
- GAsyncResult *res,
- gpointer user_data)
-{
- MetaOrientationManager *self = user_data;
- GDBusProxy *proxy;
- GError *error = NULL;
-
- proxy = g_dbus_proxy_new_finish (res, &error);
- if (!proxy)
- {
- if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
- g_warning ("Failed to obtain IIO DBus proxy: %s", error->message);
- g_error_free (error);
- return;
- }
-
- self->iio_proxy = proxy;
- g_signal_connect_object (self->iio_proxy, "g-properties-changed",
- G_CALLBACK (iio_properties_changed), self, 0);
- g_dbus_proxy_call (self->iio_proxy,
- "ClaimAccelerometer",
- NULL,
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- self->cancellable,
- accelerometer_claimed,
- self);
-}
-
-static void
-iio_sensor_appeared_cb (GDBusConnection *connection,
- const gchar *name,
- const gchar *name_owner,
- gpointer user_data)
-{
- MetaOrientationManager *self = user_data;
-
- self->cancellable = g_cancellable_new ();
- g_dbus_proxy_new (connection,
- G_DBUS_PROXY_FLAGS_NONE,
- NULL,
- "net.hadess.SensorProxy",
- "/net/hadess/SensorProxy",
- "net.hadess.SensorProxy",
- self->cancellable,
- iio_proxy_ready,
- self);
-}
-
-static void
-iio_sensor_vanished_cb (GDBusConnection *connection,
- const gchar *name,
- gpointer user_data)
-{
- MetaOrientationManager *self = user_data;
-
- g_cancellable_cancel (self->cancellable);
- g_clear_object (&self->cancellable);
-
- g_clear_object (&self->iio_proxy);
-
- sync_state (self);
-}
-
-static void
-meta_orientation_manager_init (MetaOrientationManager *self)
-{
- self->iio_watch_id = g_bus_watch_name (G_BUS_TYPE_SYSTEM,
- "net.hadess.SensorProxy",
- G_BUS_NAME_WATCHER_FLAGS_NONE,
- iio_sensor_appeared_cb,
- iio_sensor_vanished_cb,
- self,
- NULL);
-
- self->settings = g_settings_new (CONF_SCHEMA);
- g_signal_connect_object (self->settings, "changed::"ORIENTATION_LOCK_KEY,
- G_CALLBACK (orientation_lock_changed), self, 0);
- sync_state (self);
-}
-
-static void
-meta_orientation_manager_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- MetaOrientationManager *self = META_ORIENTATION_MANAGER (object);
-
- switch (prop_id)
- {
- case PROP_HAS_ACCELEROMETER:
- g_value_set_boolean (value, self->has_accel);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-
-static void
-meta_orientation_manager_finalize (GObject *object)
-{
- MetaOrientationManager *self = META_ORIENTATION_MANAGER (object);
-
- g_cancellable_cancel (self->cancellable);
- g_clear_object (&self->cancellable);
-
- g_bus_unwatch_name (self->iio_watch_id);
- g_clear_object (&self->iio_proxy);
-
- g_clear_object (&self->settings);
-
- G_OBJECT_CLASS (meta_orientation_manager_parent_class)->finalize (object);
-}
-
-static void
-meta_orientation_manager_class_init (MetaOrientationManagerClass *klass)
-{
- GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
-
- gobject_class->finalize = meta_orientation_manager_finalize;
- gobject_class->get_property = meta_orientation_manager_get_property;
-
- signals[ORIENTATION_CHANGED] =
- g_signal_new ("orientation-changed",
- G_TYPE_FROM_CLASS (gobject_class),
- G_SIGNAL_RUN_LAST,
- 0,
- NULL, NULL, NULL,
- G_TYPE_NONE, 0);
-
- props[PROP_HAS_ACCELEROMETER] =
- g_param_spec_boolean ("has-accelerometer",
- "Has accelerometer",
- "Has accelerometer",
- FALSE,
- G_PARAM_READABLE |
- G_PARAM_EXPLICIT_NOTIFY |
- G_PARAM_STATIC_STRINGS);
- g_object_class_install_properties (gobject_class, PROP_LAST, props);
-}
-
-MetaOrientation
-meta_orientation_manager_get_orientation (MetaOrientationManager *self)
-{
- return self->curr_orientation;
-}
-
-gboolean
-meta_orientation_manager_has_accelerometer (MetaOrientationManager *self)
-{
- return self->has_accel;
-}
diff --git a/src/backends/meta-orientation-manager.h b/src/backends/meta-orientation-manager.h
deleted file mode 100644
index 9ae87957d..000000000
--- a/src/backends/meta-orientation-manager.h
+++ /dev/null
@@ -1,44 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2017 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-
-#ifndef META_ORIENTATION_MANAGER_H
-#define META_ORIENTATION_MANAGER_H
-
-#include <glib-object.h>
-
-typedef enum
-{
- META_ORIENTATION_UNDEFINED,
- META_ORIENTATION_NORMAL,
- META_ORIENTATION_BOTTOM_UP,
- META_ORIENTATION_LEFT_UP,
- META_ORIENTATION_RIGHT_UP
-} MetaOrientation;
-
-#define META_TYPE_ORIENTATION_MANAGER (meta_orientation_manager_get_type ())
-G_DECLARE_FINAL_TYPE (MetaOrientationManager, meta_orientation_manager,
- META, ORIENTATION_MANAGER, GObject)
-
-MetaOrientation meta_orientation_manager_get_orientation (MetaOrientationManager *self);
-
-gboolean meta_orientation_manager_has_accelerometer (MetaOrientationManager *self);
-
-#endif /* META_ORIENTATION_MANAGER_H */
diff --git a/src/backends/meta-output.c b/src/backends/meta-output.c
deleted file mode 100644
index 432697d6d..000000000
--- a/src/backends/meta-output.c
+++ /dev/null
@@ -1,465 +0,0 @@
-/*
- * Copyright (C) 2017 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-
-#include "config.h"
-
-#include "backends/edid.h"
-#include "backends/meta-output.h"
-
-#include "backends/meta-crtc.h"
-
-enum
-{
- PROP_0,
-
- PROP_ID,
- PROP_GPU,
- PROP_INFO,
-
- N_PROPS
-};
-
-static GParamSpec *obj_props[N_PROPS];
-
-typedef struct _MetaOutputPrivate
-{
- uint64_t id;
-
- MetaGpu *gpu;
-
- MetaOutputInfo *info;
-
- MetaMonitor *monitor;
-
- /* The CRTC driving this output, NULL if the output is not enabled */
- MetaCrtc *crtc;
-
- gboolean is_primary;
- gboolean is_presentation;
-
- gboolean is_underscanning;
-
- int backlight;
-} MetaOutputPrivate;
-
-G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (MetaOutput, meta_output, G_TYPE_OBJECT)
-
-G_DEFINE_BOXED_TYPE (MetaOutputInfo, meta_output_info,
- meta_output_info_ref,
- meta_output_info_unref)
-
-MetaOutputInfo *
-meta_output_info_new (void)
-{
- MetaOutputInfo *output_info;
-
- output_info = g_new0 (MetaOutputInfo, 1);
- g_ref_count_init (&output_info->ref_count);
-
- return output_info;
-}
-
-MetaOutputInfo *
-meta_output_info_ref (MetaOutputInfo *output_info)
-{
- g_ref_count_inc (&output_info->ref_count);
- return output_info;
-}
-
-void
-meta_output_info_unref (MetaOutputInfo *output_info)
-{
- if (g_ref_count_dec (&output_info->ref_count))
- {
- g_free (output_info->name);
- g_free (output_info->vendor);
- g_free (output_info->product);
- g_free (output_info->serial);
- g_free (output_info->modes);
- g_free (output_info->possible_crtcs);
- g_free (output_info->possible_clones);
- g_free (output_info);
- }
-}
-
-uint64_t
-meta_output_get_id (MetaOutput *output)
-{
- MetaOutputPrivate *priv = meta_output_get_instance_private (output);
-
- return priv->id;
-}
-
-MetaGpu *
-meta_output_get_gpu (MetaOutput *output)
-{
- MetaOutputPrivate *priv = meta_output_get_instance_private (output);
-
- return priv->gpu;
-}
-
-MetaMonitor *
-meta_output_get_monitor (MetaOutput *output)
-{
- MetaOutputPrivate *priv = meta_output_get_instance_private (output);
-
- g_warn_if_fail (priv->monitor);
-
- return priv->monitor;
-}
-
-void
-meta_output_set_monitor (MetaOutput *output,
- MetaMonitor *monitor)
-{
- MetaOutputPrivate *priv = meta_output_get_instance_private (output);
-
- g_warn_if_fail (!priv->monitor);
-
- priv->monitor = monitor;
-}
-
-void
-meta_output_unset_monitor (MetaOutput *output)
-{
- MetaOutputPrivate *priv = meta_output_get_instance_private (output);
-
- g_warn_if_fail (priv->monitor);
-
- priv->monitor = NULL;
-}
-
-const char *
-meta_output_get_name (MetaOutput *output)
-{
- MetaOutputPrivate *priv = meta_output_get_instance_private (output);
-
- return priv->info->name;
-}
-
-gboolean
-meta_output_is_primary (MetaOutput *output)
-{
- MetaOutputPrivate *priv = meta_output_get_instance_private (output);
-
- return priv->is_primary;
-}
-
-gboolean
-meta_output_is_presentation (MetaOutput *output)
-{
- MetaOutputPrivate *priv = meta_output_get_instance_private (output);
-
- return priv->is_presentation;
-}
-
-gboolean
-meta_output_is_underscanning (MetaOutput *output)
-{
- MetaOutputPrivate *priv = meta_output_get_instance_private (output);
-
- return priv->is_underscanning;
-}
-
-void
-meta_output_set_backlight (MetaOutput *output,
- int backlight)
-{
- MetaOutputPrivate *priv = meta_output_get_instance_private (output);
-
- priv->backlight = backlight;
-}
-
-int
-meta_output_get_backlight (MetaOutput *output)
-{
- MetaOutputPrivate *priv = meta_output_get_instance_private (output);
-
- return priv->backlight;
-}
-
-void
-meta_output_add_possible_clone (MetaOutput *output,
- MetaOutput *possible_clone)
-{
- MetaOutputPrivate *priv = meta_output_get_instance_private (output);
- MetaOutputInfo *output_info = priv->info;
-
- output_info->n_possible_clones++;
- output_info->possible_clones = g_renew (MetaOutput *,
- output_info->possible_clones,
- output_info->n_possible_clones);
- output_info->possible_clones[output_info->n_possible_clones - 1] =
- possible_clone;
-}
-
-const MetaOutputInfo *
-meta_output_get_info (MetaOutput *output)
-{
- MetaOutputPrivate *priv = meta_output_get_instance_private (output);
-
- return priv->info;
-}
-
-void
-meta_output_assign_crtc (MetaOutput *output,
- MetaCrtc *crtc,
- const MetaOutputAssignment *output_assignment)
-{
- MetaOutputPrivate *priv = meta_output_get_instance_private (output);
-
- g_assert (crtc);
-
- meta_output_unassign_crtc (output);
-
- g_set_object (&priv->crtc, crtc);
-
- meta_crtc_assign_output (crtc, output);
-
- priv->is_primary = output_assignment->is_primary;
- priv->is_presentation = output_assignment->is_presentation;
- priv->is_underscanning = output_assignment->is_underscanning;
-}
-
-void
-meta_output_unassign_crtc (MetaOutput *output)
-{
- MetaOutputPrivate *priv = meta_output_get_instance_private (output);
-
- if (priv->crtc)
- {
- meta_crtc_unassign_output (priv->crtc, output);
- g_clear_object (&priv->crtc);
- }
-
- priv->is_primary = FALSE;
- priv->is_presentation = FALSE;
-}
-
-MetaCrtc *
-meta_output_get_assigned_crtc (MetaOutput *output)
-{
- MetaOutputPrivate *priv = meta_output_get_instance_private (output);
-
- return priv->crtc;
-}
-
-MetaMonitorTransform
-meta_output_logical_to_crtc_transform (MetaOutput *output,
- MetaMonitorTransform transform)
-{
- MetaOutputPrivate *priv = meta_output_get_instance_private (output);
- MetaMonitorTransform panel_orientation_transform;
-
- panel_orientation_transform = priv->info->panel_orientation_transform;
- return meta_monitor_transform_transform (transform,
- panel_orientation_transform);
-}
-
-MetaMonitorTransform
-meta_output_crtc_to_logical_transform (MetaOutput *output,
- MetaMonitorTransform transform)
-{
- MetaOutputPrivate *priv = meta_output_get_instance_private (output);
- MetaMonitorTransform inverted_panel_orientation_transform;
-
- inverted_panel_orientation_transform =
- meta_monitor_transform_invert (priv->info->panel_orientation_transform);
- return meta_monitor_transform_transform (transform,
- inverted_panel_orientation_transform);
-}
-
-void
-meta_output_info_parse_edid (MetaOutputInfo *output_info,
- GBytes *edid)
-{
- MonitorInfo *parsed_edid;
- size_t len;
-
- if (!edid)
- goto out;
-
- parsed_edid = decode_edid (g_bytes_get_data (edid, &len));
-
- if (parsed_edid)
- {
- output_info->vendor = g_strndup (parsed_edid->manufacturer_code, 4);
- if (!g_utf8_validate (output_info->vendor, -1, NULL))
- g_clear_pointer (&output_info->vendor, g_free);
-
- output_info->product = g_strndup (parsed_edid->dsc_product_name, 14);
- if (!g_utf8_validate (output_info->product, -1, NULL) ||
- output_info->product[0] == '\0')
- {
- g_clear_pointer (&output_info->product, g_free);
- output_info->product = g_strdup_printf ("0x%04x", (unsigned) parsed_edid->product_code);
- }
-
- output_info->serial = g_strndup (parsed_edid->dsc_serial_number, 14);
- if (!g_utf8_validate (output_info->serial, -1, NULL) ||
- output_info->serial[0] == '\0')
- {
- g_clear_pointer (&output_info->serial, g_free);
- output_info->serial = g_strdup_printf ("0x%08x", parsed_edid->serial_number);
- }
-
- g_free (parsed_edid);
- }
-
- out:
- if (!output_info->vendor)
- output_info->vendor = g_strdup ("unknown");
- if (!output_info->product)
- output_info->product = g_strdup ("unknown");
- if (!output_info->serial)
- output_info->serial = g_strdup ("unknown");
-}
-
-gboolean
-meta_output_is_laptop (MetaOutput *output)
-{
- const MetaOutputInfo *output_info = meta_output_get_info (output);
-
- switch (output_info->connector_type)
- {
- case META_CONNECTOR_TYPE_eDP:
- case META_CONNECTOR_TYPE_LVDS:
- case META_CONNECTOR_TYPE_DSI:
- return TRUE;
- default:
- return FALSE;
- }
-}
-
-static void
-meta_output_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- MetaOutput *output = META_OUTPUT (object);
- MetaOutputPrivate *priv = meta_output_get_instance_private (output);
-
- switch (prop_id)
- {
- case PROP_ID:
- priv->id = g_value_get_uint64 (value);
- break;
- case PROP_GPU:
- priv->gpu = g_value_get_object (value);
- break;
- case PROP_INFO:
- priv->info = meta_output_info_ref (g_value_get_boxed (value));
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- }
-}
-
-static void
-meta_output_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- MetaOutput *output = META_OUTPUT (object);
- MetaOutputPrivate *priv = meta_output_get_instance_private (output);
-
- switch (prop_id)
- {
- case PROP_ID:
- g_value_set_uint64 (value, priv->id);
- break;
- case PROP_GPU:
- g_value_set_object (value, priv->gpu);
- break;
- case PROP_INFO:
- g_value_set_boxed (value, priv->info);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- }
-}
-
-static void
-meta_output_dispose (GObject *object)
-{
- MetaOutput *output = META_OUTPUT (object);
- MetaOutputPrivate *priv = meta_output_get_instance_private (output);
-
- g_clear_object (&priv->crtc);
-
- G_OBJECT_CLASS (meta_output_parent_class)->dispose (object);
-}
-
-static void
-meta_output_finalize (GObject *object)
-{
- MetaOutput *output = META_OUTPUT (object);
- MetaOutputPrivate *priv = meta_output_get_instance_private (output);
-
- g_clear_pointer (&priv->info, meta_output_info_unref);
-
- G_OBJECT_CLASS (meta_output_parent_class)->finalize (object);
-}
-
-static void
-meta_output_init (MetaOutput *output)
-{
- MetaOutputPrivate *priv = meta_output_get_instance_private (output);
-
- priv->backlight = -1;
-}
-
-static void
-meta_output_class_init (MetaOutputClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- object_class->set_property = meta_output_set_property;
- object_class->get_property = meta_output_get_property;
- object_class->dispose = meta_output_dispose;
- object_class->finalize = meta_output_finalize;
-
- obj_props[PROP_ID] =
- g_param_spec_uint64 ("id",
- "id",
- "CRTC id",
- 0, UINT64_MAX, 0,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT_ONLY |
- G_PARAM_STATIC_STRINGS);
- obj_props[PROP_GPU] =
- g_param_spec_object ("gpu",
- "gpu",
- "MetaGpu",
- META_TYPE_GPU,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT_ONLY |
- G_PARAM_STATIC_STRINGS);
- obj_props[PROP_INFO] =
- g_param_spec_boxed ("info",
- "info",
- "MetaOutputInfo",
- META_TYPE_OUTPUT_INFO,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT_ONLY |
- G_PARAM_STATIC_STRINGS);
- g_object_class_install_properties (object_class, N_PROPS, obj_props);
-}
diff --git a/src/backends/meta-output.h b/src/backends/meta-output.h
deleted file mode 100644
index b96c118d8..000000000
--- a/src/backends/meta-output.h
+++ /dev/null
@@ -1,192 +0,0 @@
-/*
- * Copyright (C) 2017 Red Hat
- * Copyright (C) 2020 NVIDIA CORPORATION
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-
-#ifndef META_OUTPUT_H
-#define META_OUTPUT_H
-
-#include <glib-object.h>
-
-#include "backends/meta-backend-types.h"
-#include "backends/meta-gpu.h"
-#include "core/util-private.h"
-
-struct _MetaTileInfo
-{
- uint32_t group_id;
- uint32_t flags;
- uint32_t max_h_tiles;
- uint32_t max_v_tiles;
- uint32_t loc_h_tile;
- uint32_t loc_v_tile;
- uint32_t tile_w;
- uint32_t tile_h;
-};
-
-/* The first 17 matches the values in drm_mode.h, the ones starting with
- * 1000 do not. */
-typedef enum
-{
- META_CONNECTOR_TYPE_Unknown = 0,
- META_CONNECTOR_TYPE_VGA = 1,
- META_CONNECTOR_TYPE_DVII = 2,
- META_CONNECTOR_TYPE_DVID = 3,
- META_CONNECTOR_TYPE_DVIA = 4,
- META_CONNECTOR_TYPE_Composite = 5,
- META_CONNECTOR_TYPE_SVIDEO = 6,
- META_CONNECTOR_TYPE_LVDS = 7,
- META_CONNECTOR_TYPE_Component = 8,
- META_CONNECTOR_TYPE_9PinDIN = 9,
- META_CONNECTOR_TYPE_DisplayPort = 10,
- META_CONNECTOR_TYPE_HDMIA = 11,
- META_CONNECTOR_TYPE_HDMIB = 12,
- META_CONNECTOR_TYPE_TV = 13,
- META_CONNECTOR_TYPE_eDP = 14,
- META_CONNECTOR_TYPE_VIRTUAL = 15,
- META_CONNECTOR_TYPE_DSI = 16,
-
- META_CONNECTOR_TYPE_META = 1000,
-} MetaConnectorType;
-
-typedef struct _MetaOutputInfo
-{
- grefcount ref_count;
-
- char *name;
- char *vendor;
- char *product;
- char *serial;
- int width_mm;
- int height_mm;
- CoglSubpixelOrder subpixel_order;
-
- MetaConnectorType connector_type;
- MetaMonitorTransform panel_orientation_transform;
-
- MetaCrtcMode *preferred_mode;
- MetaCrtcMode **modes;
- unsigned int n_modes;
-
- MetaCrtc **possible_crtcs;
- unsigned int n_possible_crtcs;
-
- MetaOutput **possible_clones;
- unsigned int n_possible_clones;
-
- int backlight_min;
- int backlight_max;
-
- gboolean supports_underscanning;
- gboolean supports_color_transform;
-
- /*
- * Get a new preferred mode on hotplug events, to handle dynamic guest
- * resizing.
- */
- gboolean hotplug_mode_update;
- int suggested_x;
- int suggested_y;
-
- MetaTileInfo tile_info;
-} MetaOutputInfo;
-
-#define META_TYPE_OUTPUT_INFO (meta_output_info_get_type ())
-META_EXPORT_TEST
-GType meta_output_info_get_type (void);
-
-META_EXPORT_TEST
-MetaOutputInfo * meta_output_info_new (void);
-
-META_EXPORT_TEST
-MetaOutputInfo * meta_output_info_ref (MetaOutputInfo *output_info);
-
-META_EXPORT_TEST
-void meta_output_info_unref (MetaOutputInfo *output_info);
-
-META_EXPORT_TEST
-void meta_output_info_parse_edid (MetaOutputInfo *output_info,
- GBytes *edid);
-
-gboolean meta_output_is_laptop (MetaOutput *output);
-
-G_DEFINE_AUTOPTR_CLEANUP_FUNC (MetaOutputInfo, meta_output_info_unref)
-
-#define META_TYPE_OUTPUT (meta_output_get_type ())
-META_EXPORT_TEST
-G_DECLARE_DERIVABLE_TYPE (MetaOutput, meta_output, META, OUTPUT, GObject)
-
-struct _MetaOutputClass
-{
- GObjectClass parent_class;
-};
-
-META_EXPORT_TEST
-uint64_t meta_output_get_id (MetaOutput *output);
-
-META_EXPORT_TEST
-MetaGpu * meta_output_get_gpu (MetaOutput *output);
-
-META_EXPORT_TEST
-MetaMonitor * meta_output_get_monitor (MetaOutput *output);
-
-void meta_output_set_monitor (MetaOutput *output,
- MetaMonitor *monitor);
-
-void meta_output_unset_monitor (MetaOutput *output);
-
-const char * meta_output_get_name (MetaOutput *output);
-
-META_EXPORT_TEST
-gboolean meta_output_is_primary (MetaOutput *output);
-
-META_EXPORT_TEST
-gboolean meta_output_is_presentation (MetaOutput *output);
-
-META_EXPORT_TEST
-gboolean meta_output_is_underscanning (MetaOutput *output);
-
-void meta_output_set_backlight (MetaOutput *output,
- int backlight);
-
-int meta_output_get_backlight (MetaOutput *output);
-
-void meta_output_add_possible_clone (MetaOutput *output,
- MetaOutput *possible_clone);
-
-META_EXPORT_TEST
-const MetaOutputInfo * meta_output_get_info (MetaOutput *output);
-
-META_EXPORT_TEST
-void meta_output_assign_crtc (MetaOutput *output,
- MetaCrtc *crtc,
- const MetaOutputAssignment *output_assignment);
-
-META_EXPORT_TEST
-void meta_output_unassign_crtc (MetaOutput *output);
-
-META_EXPORT_TEST
-MetaCrtc * meta_output_get_assigned_crtc (MetaOutput *output);
-
-MetaMonitorTransform meta_output_logical_to_crtc_transform (MetaOutput *output,
- MetaMonitorTransform transform);
-
-MetaMonitorTransform meta_output_crtc_to_logical_transform (MetaOutput *output,
- MetaMonitorTransform transform);
-
-#endif /* META_OUTPUT_H */
diff --git a/src/backends/meta-pointer-constraint.c b/src/backends/meta-pointer-constraint.c
deleted file mode 100644
index 7682b14b0..000000000
--- a/src/backends/meta-pointer-constraint.c
+++ /dev/null
@@ -1,146 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2015 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Written by:
- * Jonas Ådahl <jadahl@gmail.com>
- */
-
-/**
- * SECTION:meta-pointer-constraint
- * @title: MetaPointerConstraint
- * @short_description: Pointer client constraints.
- *
- * A MetaPointerConstraint can be used to implement any kind of pointer
- * constraint as requested by a client, such as cursor lock.
- *
- * Examples of pointer constraints are "pointer confinement" and "pointer
- * locking" (as defined in the wayland pointer constraint protocol extension),
- * which restrict movement in relation to a given client.
- */
-
-#include "config.h"
-
-#include "backends/meta-pointer-constraint.h"
-
-#ifdef HAVE_NATIVE_BACKEND
-#include "backends/native/meta-backend-native.h"
-#include "backends/native/meta-pointer-constraint-native.h"
-#endif
-
-#include <glib-object.h>
-
-struct _MetaPointerConstraint
-{
- GObject parent_instance;
- cairo_region_t *region;
-};
-
-G_DEFINE_TYPE (MetaPointerConstraint, meta_pointer_constraint, G_TYPE_OBJECT);
-
-G_DEFINE_TYPE (MetaPointerConstraintImpl, meta_pointer_constraint_impl,
- G_TYPE_OBJECT);
-
-static void
-meta_pointer_constraint_finalize (GObject *object)
-{
- MetaPointerConstraint *constraint = META_POINTER_CONSTRAINT (object);
-
- g_clear_pointer (&constraint->region, cairo_region_destroy);
-
- G_OBJECT_CLASS (meta_pointer_constraint_parent_class)->finalize (object);
-}
-
-static void
-meta_pointer_constraint_init (MetaPointerConstraint *constraint)
-{
-}
-
-static void
-meta_pointer_constraint_class_init (MetaPointerConstraintClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- object_class->finalize = meta_pointer_constraint_finalize;
-}
-
-
-MetaPointerConstraint *
-meta_pointer_constraint_new (const cairo_region_t *region)
-{
- MetaPointerConstraint *constraint;
-
- constraint = g_object_new (META_TYPE_POINTER_CONSTRAINT, NULL);
- constraint->region = cairo_region_copy (region);
-
- return constraint;
-}
-
-cairo_region_t *
-meta_pointer_constraint_get_region (MetaPointerConstraint *constraint)
-{
- return constraint->region;
-}
-
-static void
-meta_pointer_constraint_impl_init (MetaPointerConstraintImpl *constraint_impl)
-{
-}
-
-static void
-meta_pointer_constraint_impl_class_init (MetaPointerConstraintImplClass *klass)
-{
-}
-
-/**
- * meta_pointer_constraint_impl_constrain:
- * @constraint_impl: a #MetaPointerConstraintImpl.
- * @device; the device of the pointer.
- * @time: the timestamp (in ms) of the event.
- * @prev_x: X-coordinate of the previous pointer position.
- * @prev_y: Y-coordinate of the previous pointer position.
- * @x: The modifiable X-coordinate to which the pointer would like to go to.
- * @y: The modifiable Y-coordinate to which the pointer would like to go to.
- *
- * Constrains the pointer movement from point (@prev_x, @prev_y) to (@x, @y),
- * if needed.
- */
-void
-meta_pointer_constraint_impl_constrain (MetaPointerConstraintImpl *constraint_impl,
- ClutterInputDevice *device,
- uint32_t time,
- float prev_x,
- float prev_y,
- float *x,
- float *y)
-{
- META_POINTER_CONSTRAINT_IMPL_GET_CLASS (constraint_impl)->constrain (constraint_impl,
- device,
- time,
- prev_x, prev_y,
- x, y);
-}
-
-void
-meta_pointer_constraint_impl_ensure_constrained (MetaPointerConstraintImpl *constraint_impl,
- ClutterInputDevice *device)
-{
- META_POINTER_CONSTRAINT_IMPL_GET_CLASS (constraint_impl)->ensure_constrained (constraint_impl,
- device);
-}
diff --git a/src/backends/meta-pointer-constraint.h b/src/backends/meta-pointer-constraint.h
deleted file mode 100644
index b47eda490..000000000
--- a/src/backends/meta-pointer-constraint.h
+++ /dev/null
@@ -1,77 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2015 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Written by:
- * Jonas Ådahl <jadahl@gmail.com>
- */
-
-#ifndef META_POINTER_CONSTRAINT_H
-#define META_POINTER_CONSTRAINT_H
-
-#include <glib-object.h>
-
-#include "clutter/clutter.h"
-
-G_BEGIN_DECLS
-
-#define META_TYPE_POINTER_CONSTRAINT (meta_pointer_constraint_get_type ())
-G_DECLARE_FINAL_TYPE (MetaPointerConstraint, meta_pointer_constraint,
- META, POINTER_CONSTRAINT, GObject);
-
-MetaPointerConstraint * meta_pointer_constraint_new (const cairo_region_t *region);
-cairo_region_t * meta_pointer_constraint_get_region (MetaPointerConstraint *constraint);
-
-#define META_TYPE_POINTER_CONSTRAINT_IMPL (meta_pointer_constraint_impl_get_type ())
-G_DECLARE_DERIVABLE_TYPE (MetaPointerConstraintImpl, meta_pointer_constraint_impl,
- META, POINTER_CONSTRAINT_IMPL, GObject);
-
-/**
- * MetaPointerConstraintImplClass:
- * @constrain: the virtual function pointer for
- * meta_pointer_constraint_impl_constrain().
- */
-struct _MetaPointerConstraintImplClass
-{
- GObjectClass parent_class;
-
- void (* constrain) (MetaPointerConstraintImpl *constraint_impl,
- ClutterInputDevice *device,
- uint32_t time,
- float prev_x,
- float prev_y,
- float *x,
- float *y);
- void (* ensure_constrained) (MetaPointerConstraintImpl *constraint_impl,
- ClutterInputDevice *device);
-};
-
-void meta_pointer_constraint_impl_constrain (MetaPointerConstraintImpl *constraint_impl,
- ClutterInputDevice *device,
- uint32_t time,
- float prev_x,
- float prev_y,
- float *x,
- float *y);
-void meta_pointer_constraint_impl_ensure_constrained (MetaPointerConstraintImpl *constraint_impl,
- ClutterInputDevice *device);
-
-G_END_DECLS
-
-#endif /* META_POINTER_CONSTRAINT_H */
diff --git a/src/backends/meta-profiler.c b/src/backends/meta-profiler.c
deleted file mode 100644
index 7a18b85ce..000000000
--- a/src/backends/meta-profiler.c
+++ /dev/null
@@ -1,203 +0,0 @@
-/*
- * Copyright (C) 2019 Endless, Inc
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-
-#include "config.h"
-
-#include "src/backends/meta-profiler.h"
-
-#include <glib-unix.h>
-#include <glib/gi18n.h>
-#include <gio/gunixfdlist.h>
-
-#include "cogl/cogl.h"
-
-#define META_SYSPROF_PROFILER_DBUS_PATH "/org/gnome/Sysprof3/Profiler"
-
-struct _MetaProfiler
-{
- MetaDBusSysprof3ProfilerSkeleton parent_instance;
-
- GDBusConnection *connection;
- GCancellable *cancellable;
-
- gboolean running;
-};
-
-static void
-meta_sysprof_capturer_init_iface (MetaDBusSysprof3ProfilerIface *iface);
-
-G_DEFINE_TYPE_WITH_CODE (MetaProfiler,
- meta_profiler,
- META_DBUS_TYPE_SYSPROF3_PROFILER_SKELETON,
- G_IMPLEMENT_INTERFACE (META_DBUS_TYPE_SYSPROF3_PROFILER,
- meta_sysprof_capturer_init_iface))
-
-static gboolean
-handle_start (MetaDBusSysprof3Profiler *dbus_profiler,
- GDBusMethodInvocation *invocation,
- GUnixFDList *fd_list,
- GVariant *options,
- GVariant *fd_variant)
-{
- MetaProfiler *profiler = META_PROFILER (dbus_profiler);
- GMainContext *main_context = g_main_context_default ();
- const char *group_name;
- int position;
- int fd = -1;
-
- if (profiler->running)
- {
- g_dbus_method_invocation_return_error (invocation,
- G_DBUS_ERROR,
- G_DBUS_ERROR_FAILED,
- "Profiler already running");
- return TRUE;
- }
-
- g_variant_get (fd_variant, "h", &position);
-
- if (fd_list)
- fd = g_unix_fd_list_get (fd_list, position, NULL);
-
- /* Translators: this string will appear in Sysprof */
- group_name = _("Compositor");
-
- if (fd != -1)
- {
- cogl_set_tracing_enabled_on_thread_with_fd (main_context,
- group_name,
- fd);
- }
- else
- {
- cogl_set_tracing_enabled_on_thread (main_context,
- group_name,
- "mutter-profile.syscap");
- }
-
- profiler->running = TRUE;
-
- g_debug ("Profiler running");
-
- meta_dbus_sysprof3_profiler_complete_start (dbus_profiler, invocation, NULL);
- return TRUE;
-}
-
-static gboolean
-handle_stop (MetaDBusSysprof3Profiler *dbus_profiler,
- GDBusMethodInvocation *invocation)
-{
- MetaProfiler *profiler = META_PROFILER (dbus_profiler);
-
- if (!profiler->running)
- {
- g_dbus_method_invocation_return_error (invocation,
- G_DBUS_ERROR,
- G_DBUS_ERROR_FAILED,
- "Profiler not running");
- return TRUE;
- }
-
- cogl_set_tracing_disabled_on_thread (g_main_context_default ());
- profiler->running = FALSE;
-
- g_debug ("Stopping profiler");
-
- meta_dbus_sysprof3_profiler_complete_stop (dbus_profiler, invocation);
- return TRUE;
-}
-
-static void
-meta_sysprof_capturer_init_iface (MetaDBusSysprof3ProfilerIface *iface)
-{
- iface->handle_start = handle_start;
- iface->handle_stop = handle_stop;
-}
-
-static void
-on_bus_acquired_cb (GObject *source,
- GAsyncResult *result,
- gpointer user_data)
-{
- g_autoptr (GDBusConnection) connection = NULL;
- GDBusInterfaceSkeleton *interface_skeleton;
- g_autoptr (GError) error = NULL;
- MetaProfiler *profiler;
-
- connection = g_bus_get_finish (result, &error);
-
- if (error)
- {
- if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
- g_warning ("Failed to get session bus: %s", error->message);
- return;
- }
-
- profiler = META_PROFILER (user_data);
- interface_skeleton = G_DBUS_INTERFACE_SKELETON (profiler);
-
- if (!g_dbus_interface_skeleton_export (interface_skeleton,
- connection,
- META_SYSPROF_PROFILER_DBUS_PATH,
- &error))
- {
- g_warning ("Failed to export profiler object: %s", error->message);
- return;
- }
-
- profiler->connection = g_steal_pointer (&connection);
-}
-
-static void
-meta_profiler_finalize (GObject *object)
-{
- MetaProfiler *self = (MetaProfiler *)object;
-
- g_cancellable_cancel (self->cancellable);
-
- g_clear_object (&self->cancellable);
- g_clear_object (&self->connection);
-
- G_OBJECT_CLASS (meta_profiler_parent_class)->finalize (object);
-}
-
-static void
-meta_profiler_class_init (MetaProfilerClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- object_class->finalize = meta_profiler_finalize;
-}
-
-static void
-meta_profiler_init (MetaProfiler *self)
-{
- self->cancellable = g_cancellable_new ();
-
- g_bus_get (G_BUS_TYPE_SESSION,
- self->cancellable,
- on_bus_acquired_cb,
- self);
-}
-
-MetaProfiler *
-meta_profiler_new (void)
-{
- return g_object_new (META_TYPE_PROFILER, NULL);
-}
diff --git a/src/backends/meta-profiler.h b/src/backends/meta-profiler.h
deleted file mode 100644
index aa0d72640..000000000
--- a/src/backends/meta-profiler.h
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright (C) 2019 Endless, Inc
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-
-#ifndef META_PROFILER_H
-#define META_PROFILER_H
-
-#include <glib-object.h>
-
-#include "meta-dbus-sysprof3-profiler.h"
-
-G_BEGIN_DECLS
-
-#define META_TYPE_PROFILER (meta_profiler_get_type())
-
-G_DECLARE_FINAL_TYPE (MetaProfiler,
- meta_profiler,
- META,
- PROFILER,
- MetaDBusSysprof3ProfilerSkeleton)
-
-MetaProfiler * meta_profiler_new (void);
-
-G_END_DECLS
-
-#endif /* META_PROFILER_H */
diff --git a/src/backends/meta-remote-access-controller-private.h b/src/backends/meta-remote-access-controller-private.h
deleted file mode 100644
index 8c8a319c4..000000000
--- a/src/backends/meta-remote-access-controller-private.h
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright (C) 2018 Red Hat Inc.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- */
-
-#ifndef META_REMOTE_ACCESS_CONTROLLER_PRIVATE_H
-#define META_REMOTE_ACCESS_CONTROLLER_PRIVATE_H
-
-#include "backends/meta-backend-types.h"
-#include "meta/meta-remote-access-controller.h"
-
-MetaRemoteAccessController * meta_remote_access_controller_new (MetaRemoteDesktop *remote_desktop,
- MetaScreenCast *screen_cast);
-
-void meta_remote_access_controller_notify_new_handle (MetaRemoteAccessController *controller,
- MetaRemoteAccessHandle *handle);
-
-void meta_remote_access_handle_notify_stopped (MetaRemoteAccessHandle *handle);
-
-void meta_remote_access_handle_set_disable_animations (MetaRemoteAccessHandle *handle,
- gboolean disable_animations);
-
-#endif /* META_REMOTE_ACCESS_CONTROLLER_PRIVATE_H */
diff --git a/src/backends/meta-remote-access-controller.c b/src/backends/meta-remote-access-controller.c
deleted file mode 100644
index b2ac93d88..000000000
--- a/src/backends/meta-remote-access-controller.c
+++ /dev/null
@@ -1,283 +0,0 @@
-/*
- * Copyright (C) 2018 Red Hat Inc.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- */
-
-#include "config.h"
-
-#include "backends/meta-remote-access-controller-private.h"
-
-#ifdef HAVE_REMOTE_DESKTOP
-#include "backends/meta-remote-desktop.h"
-#include "backends/meta-screen-cast.h"
-#endif
-
-enum
-{
- HANDLE_STOPPED,
-
- N_HANDLE_SIGNALS
-};
-
-static int handle_signals[N_HANDLE_SIGNALS];
-
-enum
-{
- PROP_0,
-
- PROP_IS_RECORDING,
-
- N_PROPS
-};
-
-static GParamSpec *obj_props[N_PROPS];
-
-enum
-{
- CONTROLLER_NEW_HANDLE,
-
- N_CONTROLLER_SIGNALS
-};
-
-static int controller_signals[N_CONTROLLER_SIGNALS];
-
-typedef struct _MetaRemoteAccessHandlePrivate
-{
- gboolean has_stopped;
-
- gboolean disable_animations;
-
- gboolean is_recording;
-} MetaRemoteAccessHandlePrivate;
-
-G_DEFINE_TYPE_WITH_PRIVATE (MetaRemoteAccessHandle,
- meta_remote_access_handle,
- G_TYPE_OBJECT)
-
-struct _MetaRemoteAccessController
-{
- GObject parent;
-
- MetaRemoteDesktop *remote_desktop;
- MetaScreenCast *screen_cast;
-};
-
-G_DEFINE_TYPE (MetaRemoteAccessController,
- meta_remote_access_controller,
- G_TYPE_OBJECT)
-
-/**
- * meta_remote_access_handle_stop:
- * @handle: A #MetaRemoteAccessHandle
- *
- * Stop the associated remote access session.
- */
-void
-meta_remote_access_handle_stop (MetaRemoteAccessHandle *handle)
-{
- MetaRemoteAccessHandlePrivate *priv =
- meta_remote_access_handle_get_instance_private (handle);
-
- if (priv->has_stopped)
- return;
-
- META_REMOTE_ACCESS_HANDLE_GET_CLASS (handle)->stop (handle);
-}
-
-/**
- * meta_remote_access_get_disable_animations:
- * @handle: A #MetaRemoteAccessHandle
- *
- * Returns: %TRUE if the remote access requested that animations should be
- * disabled.
- */
-gboolean
-meta_remote_access_handle_get_disable_animations (MetaRemoteAccessHandle *handle)
-{
- MetaRemoteAccessHandlePrivate *priv =
- meta_remote_access_handle_get_instance_private (handle);
-
- return priv->disable_animations;
-}
-
-void
-meta_remote_access_handle_set_disable_animations (MetaRemoteAccessHandle *handle,
- gboolean disable_animations)
-{
- MetaRemoteAccessHandlePrivate *priv =
- meta_remote_access_handle_get_instance_private (handle);
-
- priv->disable_animations = disable_animations;
-}
-
-void
-meta_remote_access_handle_notify_stopped (MetaRemoteAccessHandle *handle)
-{
- MetaRemoteAccessHandlePrivate *priv =
- meta_remote_access_handle_get_instance_private (handle);
-
- priv->has_stopped = TRUE;
- g_signal_emit (handle, handle_signals[HANDLE_STOPPED], 0);
-}
-
-void
-meta_remote_access_controller_notify_new_handle (MetaRemoteAccessController *controller,
- MetaRemoteAccessHandle *handle)
-{
- g_signal_emit (controller, controller_signals[CONTROLLER_NEW_HANDLE], 0,
- handle);
-}
-
-/**
- * meta_remote_access_controller_inhibit_remote_access:
- * @controller: a #MetaRemoteAccessController
- *
- * Inhibits remote access sessions from being created and running. Any active
- * remote access session will be terminated.
- */
-void
-meta_remote_access_controller_inhibit_remote_access (MetaRemoteAccessController *controller)
-{
-#ifdef HAVE_REMOTE_DESKTOP
- meta_remote_desktop_inhibit (controller->remote_desktop);
- meta_screen_cast_inhibit (controller->screen_cast);
-#endif
-}
-
-/**
- * meta_remote_access_controller_uninhibit_remote_access:
- * @controller: a #MetaRemoteAccessController
- *
- * Uninhibits remote access sessions from being created and running. If this was
- * the last inhibitation that was inhibited, new remote access sessions can now
- * be created.
- */
-void
-meta_remote_access_controller_uninhibit_remote_access (MetaRemoteAccessController *controller)
-{
-#ifdef HAVE_REMOTE_DESKTOP
- meta_screen_cast_uninhibit (controller->screen_cast);
- meta_remote_desktop_uninhibit (controller->remote_desktop);
-#endif
-}
-
-MetaRemoteAccessController *
-meta_remote_access_controller_new (MetaRemoteDesktop *remote_desktop,
- MetaScreenCast *screen_cast)
-{
- MetaRemoteAccessController *remote_access_controller;
-
- remote_access_controller = g_object_new (META_TYPE_REMOTE_ACCESS_CONTROLLER,
- NULL);
- remote_access_controller->remote_desktop = remote_desktop;
- remote_access_controller->screen_cast = screen_cast;
-
- return remote_access_controller;
-}
-
-static void
-meta_remote_access_handle_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- MetaRemoteAccessHandle *handle = META_REMOTE_ACCESS_HANDLE (object);
- MetaRemoteAccessHandlePrivate *priv =
- meta_remote_access_handle_get_instance_private (handle);
-
- switch (prop_id)
- {
- case PROP_IS_RECORDING:
- g_value_set_boolean (value, priv->is_recording);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-
-static void
-meta_remote_access_handle_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- MetaRemoteAccessHandle *handle = META_REMOTE_ACCESS_HANDLE (object);
- MetaRemoteAccessHandlePrivate *priv =
- meta_remote_access_handle_get_instance_private (handle);
-
- switch (prop_id)
- {
- case PROP_IS_RECORDING:
- priv->is_recording = g_value_get_boolean (value);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-
-static void
-meta_remote_access_handle_init (MetaRemoteAccessHandle *handle)
-{
-}
-
-static void
-meta_remote_access_handle_class_init (MetaRemoteAccessHandleClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- object_class->get_property = meta_remote_access_handle_get_property;
- object_class->set_property = meta_remote_access_handle_set_property;
-
- handle_signals[HANDLE_STOPPED] =
- g_signal_new ("stopped",
- G_TYPE_FROM_CLASS (klass),
- G_SIGNAL_RUN_LAST,
- 0,
- NULL, NULL, NULL,
- G_TYPE_NONE, 0);
-
- obj_props[PROP_IS_RECORDING] =
- g_param_spec_boolean ("is-recording",
- "is-recording",
- "Is a screen recording",
- FALSE,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT_ONLY |
- G_PARAM_STATIC_STRINGS);
- g_object_class_install_properties (object_class, N_PROPS, obj_props);
-}
-
-static void
-meta_remote_access_controller_init (MetaRemoteAccessController *controller)
-{
-}
-
-static void
-meta_remote_access_controller_class_init (MetaRemoteAccessControllerClass *klass)
-{
- controller_signals[CONTROLLER_NEW_HANDLE] =
- g_signal_new ("new-handle",
- G_TYPE_FROM_CLASS (klass),
- G_SIGNAL_RUN_LAST,
- 0,
- NULL, NULL, NULL,
- G_TYPE_NONE, 1,
- META_TYPE_REMOTE_ACCESS_HANDLE);
-}
diff --git a/src/backends/meta-remote-desktop-session.c b/src/backends/meta-remote-desktop-session.c
deleted file mode 100644
index e15bd63de..000000000
--- a/src/backends/meta-remote-desktop-session.c
+++ /dev/null
@@ -1,1725 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2015-2017 Red Hat Inc.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- */
-
-#include "config.h"
-
-#include "backends/meta-remote-desktop-session.h"
-
-#include <fcntl.h>
-#include <gio/gunixfdlist.h>
-#include <gio/gunixoutputstream.h>
-#include <glib-unix.h>
-#include <linux/input.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <xkbcommon/xkbcommon.h>
-
-#include "backends/meta-dbus-session-watcher.h"
-#include "backends/meta-screen-cast-session.h"
-#include "backends/meta-remote-access-controller-private.h"
-#include "backends/x11/meta-backend-x11.h"
-#include "cogl/cogl.h"
-#include "core/display-private.h"
-#include "core/meta-selection-private.h"
-#include "core/meta-selection-source-remote.h"
-#include "meta/meta-backend.h"
-
-#include "meta-dbus-remote-desktop.h"
-
-#define META_REMOTE_DESKTOP_SESSION_DBUS_PATH "/org/gnome/Mutter/RemoteDesktop/Session"
-
-#define TRANSFER_REQUEST_CLEANUP_TIMEOUT_MS (s2ms (15))
-
-typedef enum _MetaRemoteDesktopNotifyAxisFlags
-{
- META_REMOTE_DESKTOP_NOTIFY_AXIS_FLAGS_NONE = 0,
- META_REMOTE_DESKTOP_NOTIFY_AXIS_FLAGS_FINISH = 1 << 0,
- META_REMOTE_DESKTOP_NOTIFY_AXIS_FLAGS_SOURCE_WHEEL = 1 << 1,
- META_REMOTE_DESKTOP_NOTIFY_AXIS_FLAGS_SOURCE_FINGER = 1 << 2,
- META_REMOTE_DESKTOP_NOTIFY_AXIS_FLAGS_SOURCE_CONTINUOUS = 1 << 3,
-} MetaRemoteDesktopNotifyAxisFlags;
-
-typedef struct _SelectionReadData
-{
- MetaRemoteDesktopSession *session;
- GOutputStream *stream;
- GCancellable *cancellable;
-} SelectionReadData;
-
-struct _MetaRemoteDesktopSession
-{
- MetaDBusRemoteDesktopSessionSkeleton parent;
-
- MetaRemoteDesktop *remote_desktop;
-
- GDBusConnection *connection;
- char *peer_name;
-
- char *session_id;
- char *object_path;
-
- MetaScreenCastSession *screen_cast_session;
- gulong screen_cast_session_closed_handler_id;
- guint started : 1;
-
- ClutterVirtualInputDevice *virtual_pointer;
- ClutterVirtualInputDevice *virtual_keyboard;
- ClutterVirtualInputDevice *virtual_touchscreen;
-
- MetaRemoteDesktopSessionHandle *handle;
-
- gboolean is_clipboard_enabled;
- gulong owner_changed_handler_id;
- SelectionReadData *read_data;
- unsigned int transfer_serial;
- MetaSelectionSourceRemote *current_source;
- GHashTable *transfer_requests;
- guint transfer_request_timeout_id;
-};
-
-static void
-meta_remote_desktop_session_init_iface (MetaDBusRemoteDesktopSessionIface *iface);
-
-static void
-meta_dbus_session_init_iface (MetaDbusSessionInterface *iface);
-
-G_DEFINE_TYPE_WITH_CODE (MetaRemoteDesktopSession,
- meta_remote_desktop_session,
- META_DBUS_TYPE_REMOTE_DESKTOP_SESSION_SKELETON,
- G_IMPLEMENT_INTERFACE (META_DBUS_TYPE_REMOTE_DESKTOP_SESSION,
- meta_remote_desktop_session_init_iface)
- G_IMPLEMENT_INTERFACE (META_TYPE_DBUS_SESSION,
- meta_dbus_session_init_iface))
-
-struct _MetaRemoteDesktopSessionHandle
-{
- MetaRemoteAccessHandle parent;
-
- MetaRemoteDesktopSession *session;
-};
-
-G_DEFINE_TYPE (MetaRemoteDesktopSessionHandle,
- meta_remote_desktop_session_handle,
- META_TYPE_REMOTE_ACCESS_HANDLE)
-
-static MetaRemoteDesktopSessionHandle *
-meta_remote_desktop_session_handle_new (MetaRemoteDesktopSession *session);
-
-static gboolean
-meta_remote_desktop_session_is_running (MetaRemoteDesktopSession *session)
-{
- return !!session->started;
-}
-
-static void
-init_remote_access_handle (MetaRemoteDesktopSession *session)
-{
- MetaBackend *backend = meta_get_backend ();
- MetaRemoteAccessController *remote_access_controller;
- MetaRemoteAccessHandle *remote_access_handle;
-
- session->handle = meta_remote_desktop_session_handle_new (session);
-
- remote_access_controller = meta_backend_get_remote_access_controller (backend);
- remote_access_handle = META_REMOTE_ACCESS_HANDLE (session->handle);
- meta_remote_access_controller_notify_new_handle (remote_access_controller,
- remote_access_handle);
-}
-
-static void
-ensure_virtual_device (MetaRemoteDesktopSession *session,
- ClutterInputDeviceType device_type)
-{
- MetaRemoteDesktop *remote_desktop = session->remote_desktop;
- MetaBackend *backend = meta_remote_desktop_get_backend (remote_desktop);
- ClutterBackend *clutter_backend = meta_backend_get_clutter_backend (backend);
- ClutterSeat *seat = clutter_backend_get_default_seat (clutter_backend);
- ClutterVirtualInputDevice **virtual_device_ptr = NULL;
-
- switch (device_type)
- {
- case CLUTTER_POINTER_DEVICE:
- virtual_device_ptr = &session->virtual_pointer;
- break;
- case CLUTTER_KEYBOARD_DEVICE:
- virtual_device_ptr = &session->virtual_keyboard;
- break;
- case CLUTTER_TOUCHSCREEN_DEVICE:
- virtual_device_ptr = &session->virtual_touchscreen;
- break;
- default:
- g_assert_not_reached ();
- }
-
- g_assert (virtual_device_ptr);
-
- if (*virtual_device_ptr)
- return;
-
- *virtual_device_ptr = clutter_seat_create_virtual_device (seat, device_type);
-}
-
-static gboolean
-meta_remote_desktop_session_start (MetaRemoteDesktopSession *session,
- GError **error)
-{
- g_assert (!session->started);
-
- if (session->screen_cast_session)
- {
- if (!meta_screen_cast_session_start (session->screen_cast_session, error))
- return FALSE;
- }
-
- init_remote_access_handle (session);
- session->started = TRUE;
-
- return TRUE;
-}
-
-void
-meta_remote_desktop_session_close (MetaRemoteDesktopSession *session)
-{
- MetaDBusRemoteDesktopSession *skeleton =
- META_DBUS_REMOTE_DESKTOP_SESSION (session);
-
- session->started = FALSE;
-
- if (session->screen_cast_session)
- {
- g_clear_signal_handler (&session->screen_cast_session_closed_handler_id,
- session->screen_cast_session);
- meta_screen_cast_session_close (session->screen_cast_session);
- session->screen_cast_session = NULL;
- }
-
- g_clear_object (&session->virtual_pointer);
- g_clear_object (&session->virtual_keyboard);
- g_clear_object (&session->virtual_touchscreen);
-
- meta_dbus_session_notify_closed (META_DBUS_SESSION (session));
- meta_dbus_remote_desktop_session_emit_closed (skeleton);
- g_dbus_interface_skeleton_unexport (G_DBUS_INTERFACE_SKELETON (session));
-
- if (session->handle)
- {
- MetaRemoteAccessHandle *remote_access_handle =
- META_REMOTE_ACCESS_HANDLE (session->handle);
-
- meta_remote_access_handle_notify_stopped (remote_access_handle);
- }
-
- g_object_unref (session);
-}
-
-char *
-meta_remote_desktop_session_get_object_path (MetaRemoteDesktopSession *session)
-{
- return session->object_path;
-}
-
-char *
-meta_remote_desktop_session_get_session_id (MetaRemoteDesktopSession *session)
-{
- return session->session_id;
-}
-
-static void
-on_screen_cast_session_closed (MetaScreenCastSession *screen_cast_session,
- MetaRemoteDesktopSession *session)
-{
- session->screen_cast_session = NULL;
- meta_remote_desktop_session_close (session);
-}
-
-gboolean
-meta_remote_desktop_session_register_screen_cast (MetaRemoteDesktopSession *session,
- MetaScreenCastSession *screen_cast_session,
- GError **error)
-{
- if (session->screen_cast_session)
- {
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- "Remote desktop session already have an associated "
- "screen cast session");
- return FALSE;
- }
-
- session->screen_cast_session = screen_cast_session;
- session->screen_cast_session_closed_handler_id =
- g_signal_connect (screen_cast_session, "session-closed",
- G_CALLBACK (on_screen_cast_session_closed),
- session);
-
- return TRUE;
-}
-
-MetaRemoteDesktopSession *
-meta_remote_desktop_session_new (MetaRemoteDesktop *remote_desktop,
- const char *peer_name,
- GError **error)
-{
- MetaBackend *backend = meta_remote_desktop_get_backend (remote_desktop);
- ClutterBackend *clutter_backend = meta_backend_get_clutter_backend (backend);
- ClutterSeat *seat = clutter_backend_get_default_seat (clutter_backend);
- ClutterKeymap *keymap = clutter_seat_get_keymap (seat);
- GDBusInterfaceSkeleton *interface_skeleton;
- MetaRemoteDesktopSession *session;
-
- session = g_object_new (META_TYPE_REMOTE_DESKTOP_SESSION, NULL);
-
- session->remote_desktop = remote_desktop;
- session->peer_name = g_strdup (peer_name);
-
- interface_skeleton = G_DBUS_INTERFACE_SKELETON (session);
- session->connection = meta_remote_desktop_get_connection (remote_desktop);
- if (!g_dbus_interface_skeleton_export (interface_skeleton,
- session->connection,
- session->object_path,
- error))
- {
- g_object_unref (session);
- return NULL;
- }
-
- g_object_bind_property (keymap, "caps-lock-state",
- session, "caps-lock-state",
- G_BINDING_DEFAULT | G_BINDING_SYNC_CREATE);
- g_object_bind_property (keymap, "num-lock-state",
- session, "num-lock-state",
- G_BINDING_DEFAULT | G_BINDING_SYNC_CREATE);
-
- return session;
-}
-
-static gboolean
-check_permission (MetaRemoteDesktopSession *session,
- GDBusMethodInvocation *invocation)
-{
- return g_strcmp0 (session->peer_name,
- g_dbus_method_invocation_get_sender (invocation)) == 0;
-}
-
-static gboolean
-meta_remote_desktop_session_check_can_notify (MetaRemoteDesktopSession *session,
- GDBusMethodInvocation *invocation)
-{
- if (!session->started)
- {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_FAILED,
- "Session not started");
- return FALSE;
- }
-
- if (!check_permission (session, invocation))
- {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_ACCESS_DENIED,
- "Permission denied");
- return FALSE;
- }
-
- return TRUE;
-}
-
-static gboolean
-handle_start (MetaDBusRemoteDesktopSession *skeleton,
- GDBusMethodInvocation *invocation)
-{
- MetaRemoteDesktopSession *session = META_REMOTE_DESKTOP_SESSION (skeleton);
- GError *error = NULL;
-
- if (session->started)
- {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_FAILED,
- "Already started");
- return TRUE;
- }
-
- if (!check_permission (session, invocation))
- {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_ACCESS_DENIED,
- "Permission denied");
- return TRUE;
- }
-
- if (!meta_remote_desktop_session_start (session, &error))
- {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_FAILED,
- "Failed to start remote desktop: %s",
- error->message);
- g_error_free (error);
-
- meta_remote_desktop_session_close (session);
-
- return TRUE;
- }
-
- meta_dbus_remote_desktop_session_complete_start (skeleton, invocation);
-
- return TRUE;
-}
-
-static gboolean
-handle_stop (MetaDBusRemoteDesktopSession *skeleton,
- GDBusMethodInvocation *invocation)
-{
- MetaRemoteDesktopSession *session = META_REMOTE_DESKTOP_SESSION (skeleton);
-
- if (!session->started)
- {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_FAILED,
- "Session not started");
- return TRUE;
- }
-
- if (!check_permission (session, invocation))
- {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_ACCESS_DENIED,
- "Permission denied");
- return TRUE;
- }
-
- meta_remote_desktop_session_close (session);
-
- meta_dbus_remote_desktop_session_complete_stop (skeleton, invocation);
-
- return TRUE;
-}
-
-static gboolean
-handle_notify_keyboard_keycode (MetaDBusRemoteDesktopSession *skeleton,
- GDBusMethodInvocation *invocation,
- unsigned int keycode,
- gboolean pressed)
-{
- MetaRemoteDesktopSession *session = META_REMOTE_DESKTOP_SESSION (skeleton);
- ClutterKeyState state;
-
- if (!meta_remote_desktop_session_check_can_notify (session, invocation))
- return TRUE;
-
- if (pressed)
- {
- ensure_virtual_device (session, CLUTTER_KEYBOARD_DEVICE);
- state = CLUTTER_KEY_STATE_PRESSED;
- }
- else
- {
- if (!session->virtual_keyboard)
- {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_FAILED,
- "Invalid key event");
- return TRUE;
- }
-
- state = CLUTTER_KEY_STATE_RELEASED;
- }
-
- clutter_virtual_input_device_notify_key (session->virtual_keyboard,
- CLUTTER_CURRENT_TIME,
- keycode,
- state);
-
- meta_dbus_remote_desktop_session_complete_notify_keyboard_keycode (skeleton,
- invocation);
- return TRUE;
-}
-
-static gboolean
-handle_notify_keyboard_keysym (MetaDBusRemoteDesktopSession *skeleton,
- GDBusMethodInvocation *invocation,
- unsigned int keysym,
- gboolean pressed)
-{
- MetaRemoteDesktopSession *session = META_REMOTE_DESKTOP_SESSION (skeleton);
- ClutterKeyState state;
-
- if (!meta_remote_desktop_session_check_can_notify (session, invocation))
- return TRUE;
-
- if (pressed)
- {
- ensure_virtual_device (session, CLUTTER_KEYBOARD_DEVICE);
- state = CLUTTER_KEY_STATE_PRESSED;
- }
- else
- {
- if (!session->virtual_keyboard)
- {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_FAILED,
- "Invalid key event");
- return TRUE;
- }
-
- state = CLUTTER_KEY_STATE_RELEASED;
- }
-
- clutter_virtual_input_device_notify_keyval (session->virtual_keyboard,
- CLUTTER_CURRENT_TIME,
- keysym,
- state);
-
- meta_dbus_remote_desktop_session_complete_notify_keyboard_keysym (skeleton,
- invocation);
- return TRUE;
-}
-
-/* Translation taken from the clutter evdev backend. */
-static int
-translate_to_clutter_button (int button)
-{
- switch (button)
- {
- case BTN_LEFT:
- return CLUTTER_BUTTON_PRIMARY;
- case BTN_RIGHT:
- return CLUTTER_BUTTON_SECONDARY;
- case BTN_MIDDLE:
- return CLUTTER_BUTTON_MIDDLE;
- default:
- /*
- * For compatibility reasons, all additional buttons go after the old
- * 4-7 scroll ones.
- */
- return button - (BTN_LEFT - 1) + 4;
- }
-}
-
-static gboolean
-handle_notify_pointer_button (MetaDBusRemoteDesktopSession *skeleton,
- GDBusMethodInvocation *invocation,
- int button_code,
- gboolean pressed)
-{
- MetaRemoteDesktopSession *session = META_REMOTE_DESKTOP_SESSION (skeleton);
- uint32_t button;
- ClutterButtonState state;
-
- if (!meta_remote_desktop_session_check_can_notify (session, invocation))
- return TRUE;
-
- button = translate_to_clutter_button (button_code);
-
- if (pressed)
- {
- ensure_virtual_device (session, CLUTTER_POINTER_DEVICE);
- state = CLUTTER_BUTTON_STATE_PRESSED;
- }
- else
- {
- if (!session->virtual_pointer)
- {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_FAILED,
- "Invalid button event");
- return TRUE;
- }
-
- state = CLUTTER_BUTTON_STATE_RELEASED;
- }
-
- clutter_virtual_input_device_notify_button (session->virtual_pointer,
- CLUTTER_CURRENT_TIME,
- button,
- state);
-
- meta_dbus_remote_desktop_session_complete_notify_pointer_button (skeleton,
- invocation);
-
- return TRUE;
-}
-
-static gboolean
-clutter_scroll_source_from_axis_flags (MetaRemoteDesktopNotifyAxisFlags axis_flags,
- ClutterScrollSource *scroll_source)
-{
- MetaRemoteDesktopNotifyAxisFlags scroll_mask;
-
- scroll_mask = META_REMOTE_DESKTOP_NOTIFY_AXIS_FLAGS_SOURCE_WHEEL |
- META_REMOTE_DESKTOP_NOTIFY_AXIS_FLAGS_SOURCE_FINGER |
- META_REMOTE_DESKTOP_NOTIFY_AXIS_FLAGS_SOURCE_CONTINUOUS;
-
- switch (axis_flags & scroll_mask)
- {
- case META_REMOTE_DESKTOP_NOTIFY_AXIS_FLAGS_SOURCE_WHEEL:
- *scroll_source = CLUTTER_SCROLL_SOURCE_WHEEL;
- return TRUE;
- case META_REMOTE_DESKTOP_NOTIFY_AXIS_FLAGS_NONE:
- case META_REMOTE_DESKTOP_NOTIFY_AXIS_FLAGS_SOURCE_FINGER:
- *scroll_source = CLUTTER_SCROLL_SOURCE_FINGER;
- return TRUE;
- case META_REMOTE_DESKTOP_NOTIFY_AXIS_FLAGS_SOURCE_CONTINUOUS:
- *scroll_source = CLUTTER_SCROLL_SOURCE_CONTINUOUS;
- return TRUE;
- }
-
- return FALSE;
-}
-
-static gboolean
-handle_notify_pointer_axis (MetaDBusRemoteDesktopSession *skeleton,
- GDBusMethodInvocation *invocation,
- double dx,
- double dy,
- uint32_t flags)
-{
- MetaRemoteDesktopSession *session = META_REMOTE_DESKTOP_SESSION (skeleton);
- ClutterScrollFinishFlags finish_flags = CLUTTER_SCROLL_FINISHED_NONE;
- ClutterScrollSource scroll_source;
-
- if (!meta_remote_desktop_session_check_can_notify (session, invocation))
- return TRUE;
-
- if (!clutter_scroll_source_from_axis_flags (flags, &scroll_source))
- {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_FAILED,
- "Invalid scroll source");
- return TRUE;
- }
-
- if (flags & META_REMOTE_DESKTOP_NOTIFY_AXIS_FLAGS_FINISH)
- {
- finish_flags |= (CLUTTER_SCROLL_FINISHED_HORIZONTAL |
- CLUTTER_SCROLL_FINISHED_VERTICAL);
- }
-
- ensure_virtual_device (session, CLUTTER_POINTER_DEVICE);
-
- clutter_virtual_input_device_notify_scroll_continuous (session->virtual_pointer,
- CLUTTER_CURRENT_TIME,
- dx, dy,
- scroll_source,
- finish_flags);
-
- meta_dbus_remote_desktop_session_complete_notify_pointer_axis (skeleton,
- invocation);
-
- return TRUE;
-}
-
-static ClutterScrollDirection
-discrete_steps_to_scroll_direction (unsigned int axis,
- int steps)
-{
- if (axis == 0 && steps < 0)
- return CLUTTER_SCROLL_UP;
- if (axis == 0 && steps > 0)
- return CLUTTER_SCROLL_DOWN;
- if (axis == 1 && steps < 0)
- return CLUTTER_SCROLL_LEFT;
- if (axis == 1 && steps > 0)
- return CLUTTER_SCROLL_RIGHT;
-
- g_assert_not_reached ();
- return 0;
-}
-
-static gboolean
-handle_notify_pointer_axis_discrete (MetaDBusRemoteDesktopSession *skeleton,
- GDBusMethodInvocation *invocation,
- unsigned int axis,
- int steps)
-{
- MetaRemoteDesktopSession *session = META_REMOTE_DESKTOP_SESSION (skeleton);
- ClutterScrollDirection direction;
- int step_count;
-
- if (!meta_remote_desktop_session_check_can_notify (session, invocation))
- return TRUE;
-
- if (axis > 1)
- {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_FAILED,
- "Invalid axis value");
- return TRUE;
- }
-
- if (steps == 0)
- {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_FAILED,
- "Invalid axis steps value");
- return TRUE;
- }
-
- ensure_virtual_device (session, CLUTTER_POINTER_DEVICE);
-
- /*
- * We don't have the actual scroll source, but only know they should be
- * considered as discrete steps. The device that produces such scroll events
- * is the scroll wheel, so pretend that is the scroll source.
- */
- direction = discrete_steps_to_scroll_direction (axis, steps);
-
- for (step_count = 0; step_count < abs (steps); step_count++)
- clutter_virtual_input_device_notify_discrete_scroll (session->virtual_pointer,
- CLUTTER_CURRENT_TIME,
- direction,
- CLUTTER_SCROLL_SOURCE_WHEEL);
-
- meta_dbus_remote_desktop_session_complete_notify_pointer_axis_discrete (skeleton,
- invocation);
-
- return TRUE;
-}
-
-static gboolean
-handle_notify_pointer_motion_relative (MetaDBusRemoteDesktopSession *skeleton,
- GDBusMethodInvocation *invocation,
- double dx,
- double dy)
-{
- MetaRemoteDesktopSession *session = META_REMOTE_DESKTOP_SESSION (skeleton);
-
- if (!meta_remote_desktop_session_check_can_notify (session, invocation))
- return TRUE;
-
- ensure_virtual_device (session, CLUTTER_POINTER_DEVICE);
-
- clutter_virtual_input_device_notify_relative_motion (session->virtual_pointer,
- CLUTTER_CURRENT_TIME,
- dx, dy);
-
- meta_dbus_remote_desktop_session_complete_notify_pointer_motion_relative (skeleton,
- invocation);
-
- return TRUE;
-}
-
-static gboolean
-handle_notify_pointer_motion_absolute (MetaDBusRemoteDesktopSession *skeleton,
- GDBusMethodInvocation *invocation,
- const char *stream_path,
- double x,
- double y)
-{
- MetaRemoteDesktopSession *session = META_REMOTE_DESKTOP_SESSION (skeleton);
- MetaScreenCastStream *stream;
- double abs_x, abs_y;
-
- if (!meta_remote_desktop_session_check_can_notify (session, invocation))
- return TRUE;
-
-
- if (!session->screen_cast_session)
- {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_FAILED,
- "No screen cast active");
- return TRUE;
- }
-
- stream = meta_screen_cast_session_get_stream (session->screen_cast_session,
- stream_path);
- if (!stream)
- {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_FAILED,
- "Unknown stream");
- return TRUE;
- }
-
- ensure_virtual_device (session, CLUTTER_POINTER_DEVICE);
-
- if (meta_screen_cast_stream_transform_position (stream, x, y, &abs_x, &abs_y))
- {
- clutter_virtual_input_device_notify_absolute_motion (session->virtual_pointer,
- CLUTTER_CURRENT_TIME,
- abs_x, abs_y);
- }
- else
- {
- meta_topic (META_DEBUG_REMOTE_DESKTOP,
- "Dropping early absolute pointer motion (%f, %f)", x, y);
- }
-
- meta_dbus_remote_desktop_session_complete_notify_pointer_motion_absolute (skeleton,
- invocation);
-
- return TRUE;
-}
-
-static gboolean
-handle_notify_touch_down (MetaDBusRemoteDesktopSession *skeleton,
- GDBusMethodInvocation *invocation,
- const char *stream_path,
- unsigned int slot,
- double x,
- double y)
-{
- MetaRemoteDesktopSession *session = META_REMOTE_DESKTOP_SESSION (skeleton);
- MetaScreenCastStream *stream;
- double abs_x, abs_y;
-
- if (!meta_remote_desktop_session_check_can_notify (session, invocation))
- return TRUE;
-
- if (slot > CLUTTER_VIRTUAL_INPUT_DEVICE_MAX_TOUCH_SLOTS)
- {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_FAILED,
- "Touch slot out of range");
- return TRUE;
- }
-
- if (!session->screen_cast_session)
- {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_FAILED,
- "No screen cast active");
- return TRUE;
- }
-
- stream = meta_screen_cast_session_get_stream (session->screen_cast_session,
- stream_path);
- if (!stream)
- {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_FAILED,
- "Unknown stream");
- return TRUE;
- }
-
- ensure_virtual_device (session, CLUTTER_TOUCHSCREEN_DEVICE);
-
- if (meta_screen_cast_stream_transform_position (stream, x, y, &abs_x, &abs_y))
- {
- clutter_virtual_input_device_notify_touch_down (session->virtual_touchscreen,
- CLUTTER_CURRENT_TIME,
- slot,
- abs_x, abs_y);
- }
- else
- {
- meta_topic (META_DEBUG_REMOTE_DESKTOP,
- "Dropping early touch down (%f, %f)", x, y);
- }
-
- meta_dbus_remote_desktop_session_complete_notify_touch_down (skeleton,
- invocation);
-
- return TRUE;
-}
-
-static gboolean
-handle_notify_touch_motion (MetaDBusRemoteDesktopSession *skeleton,
- GDBusMethodInvocation *invocation,
- const char *stream_path,
- unsigned int slot,
- double x,
- double y)
-{
- MetaRemoteDesktopSession *session = META_REMOTE_DESKTOP_SESSION (skeleton);
- MetaScreenCastStream *stream;
- double abs_x, abs_y;
-
- if (!meta_remote_desktop_session_check_can_notify (session, invocation))
- return TRUE;
-
-
- if (slot > CLUTTER_VIRTUAL_INPUT_DEVICE_MAX_TOUCH_SLOTS)
- {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_FAILED,
- "Touch slot out of range");
- return TRUE;
- }
-
- if (!session->screen_cast_session)
- {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_FAILED,
- "No screen cast active");
- return TRUE;
- }
-
- stream = meta_screen_cast_session_get_stream (session->screen_cast_session,
- stream_path);
- if (!stream)
- {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_FAILED,
- "Unknown stream");
- return TRUE;
- }
-
- if (!session->virtual_touchscreen)
- {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_FAILED,
- "Invalid touch point");
- return TRUE;
- }
-
- if (meta_screen_cast_stream_transform_position (stream, x, y, &abs_x, &abs_y))
- {
- clutter_virtual_input_device_notify_touch_motion (session->virtual_touchscreen,
- CLUTTER_CURRENT_TIME,
- slot,
- abs_x, abs_y);
- }
- else
- {
- meta_topic (META_DEBUG_REMOTE_DESKTOP,
- "Dropping early touch motion (%f, %f)", x, y);
- }
-
- meta_dbus_remote_desktop_session_complete_notify_touch_motion (skeleton,
- invocation);
-
- return TRUE;
-}
-
-static gboolean
-handle_notify_touch_up (MetaDBusRemoteDesktopSession *skeleton,
- GDBusMethodInvocation *invocation,
- unsigned int slot)
-{
- MetaRemoteDesktopSession *session = META_REMOTE_DESKTOP_SESSION (skeleton);
-
- if (!meta_remote_desktop_session_check_can_notify (session, invocation))
- return TRUE;
-
- if (slot > CLUTTER_VIRTUAL_INPUT_DEVICE_MAX_TOUCH_SLOTS)
- {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_FAILED,
- "Touch slot out of range");
- return TRUE;
- }
-
- if (!session->virtual_touchscreen)
- {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_FAILED,
- "Invalid touch point");
- return TRUE;
- }
-
- clutter_virtual_input_device_notify_touch_up (session->virtual_touchscreen,
- CLUTTER_CURRENT_TIME,
- slot);
-
- meta_dbus_remote_desktop_session_complete_notify_touch_up (skeleton,
- invocation);
-
- return TRUE;
-}
-
-static MetaSelectionSourceRemote *
-create_remote_desktop_source (MetaRemoteDesktopSession *session,
- GVariant *mime_types_variant,
- GError **error)
-{
- GVariantIter iter;
- char *mime_type;
- GList *mime_types = NULL;
-
- g_variant_iter_init (&iter, mime_types_variant);
- if (g_variant_iter_n_children (&iter) == 0)
- {
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_DATA,
- "No mime types in mime types list");
- return NULL;
- }
-
- while (g_variant_iter_next (&iter, "s", &mime_type))
- mime_types = g_list_prepend (mime_types, mime_type);
-
- mime_types = g_list_reverse (mime_types);
-
- return meta_selection_source_remote_new (session, mime_types);
-}
-
-static const char *
-mime_types_to_string (char **formats,
- char *buf,
- int buf_len)
-{
- g_autofree char *mime_types_string = NULL;
- int len;
-
- if (!formats)
- return "N\\A";
-
- mime_types_string = g_strjoinv (",", formats);
- len = strlen (mime_types_string);
- strncpy (buf, mime_types_string, buf_len - 1);
- if (len >= buf_len - 1)
- buf[buf_len - 2] = '*';
- buf[buf_len - 1] = '\0';
-
- return buf;
-}
-
-static gboolean
-is_own_source (MetaRemoteDesktopSession *session,
- MetaSelectionSource *source)
-{
- return source && source == META_SELECTION_SOURCE (session->current_source);
-}
-
-static GVariant *
-generate_owner_changed_variant (char **mime_types_array,
- gboolean is_own_source)
-{
- GVariantBuilder builder;
-
- g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}"));
- if (mime_types_array)
- {
- g_variant_builder_add (&builder, "{sv}", "mime-types",
- g_variant_new ("(^as)", mime_types_array));
- g_variant_builder_add (&builder, "{sv}", "session-is-owner",
- g_variant_new_boolean (is_own_source));
- }
-
- return g_variant_builder_end (&builder);
-}
-
-static void
-emit_owner_changed (MetaRemoteDesktopSession *session,
- MetaSelectionSource *owner)
-{
- char log_buf[255];
- g_autofree char **mime_types_array = NULL;
- GList *l;
- int i;
- GVariant *options_variant;
- const char *object_path;
-
- if (owner)
- {
- GList *mime_types;
-
- mime_types = meta_selection_source_get_mimetypes (owner);
- mime_types_array = g_new0 (char *, g_list_length (mime_types) + 1);
- for (l = meta_selection_source_get_mimetypes (owner), i = 0;
- l;
- l = l->next, i++)
- mime_types_array[i] = l->data;
- }
-
- meta_topic (META_DEBUG_REMOTE_DESKTOP,
- "Clipboard owner changed, owner: %p (%s, is own? %s), mime types: [%s], "
- "notifying %s",
- owner,
- owner ? g_type_name_from_instance ((GTypeInstance *) owner)
- : "NULL",
- is_own_source (session, owner) ? "yes" : "no",
- mime_types_to_string (mime_types_array, log_buf,
- G_N_ELEMENTS (log_buf)),
- session->peer_name);
-
- options_variant =
- generate_owner_changed_variant (mime_types_array,
- is_own_source (session, owner));
-
- object_path = g_dbus_interface_skeleton_get_object_path (
- G_DBUS_INTERFACE_SKELETON (session));
- g_dbus_connection_emit_signal (session->connection,
- NULL,
- object_path,
- "org.gnome.Mutter.RemoteDesktop.Session",
- "SelectionOwnerChanged",
- g_variant_new ("(@a{sv})", options_variant),
- NULL);
-}
-
-static void
-on_selection_owner_changed (MetaSelection *selection,
- MetaSelectionType selection_type,
- MetaSelectionSource *owner,
- MetaRemoteDesktopSession *session)
-{
- if (selection_type != META_SELECTION_CLIPBOARD)
- return;
-
- emit_owner_changed (session, owner);
-}
-
-static gboolean
-handle_enable_clipboard (MetaDBusRemoteDesktopSession *skeleton,
- GDBusMethodInvocation *invocation,
- GVariant *arg_options)
-{
- MetaRemoteDesktopSession *session = META_REMOTE_DESKTOP_SESSION (skeleton);
- GVariant *mime_types_variant;
- g_autoptr (GError) error = NULL;
- MetaDisplay *display = meta_get_display ();
- MetaSelection *selection = meta_display_get_selection (display);
- g_autoptr (MetaSelectionSourceRemote) source_remote = NULL;
-
- meta_topic (META_DEBUG_REMOTE_DESKTOP,
- "Enable clipboard for %s",
- g_dbus_method_invocation_get_sender (invocation));
-
- if (session->is_clipboard_enabled)
- {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_FAILED,
- "Already enabled");
- return TRUE;
- }
-
- mime_types_variant = g_variant_lookup_value (arg_options,
- "mime-types",
- G_VARIANT_TYPE_STRING_ARRAY);
- if (mime_types_variant)
- {
- source_remote = create_remote_desktop_source (session,
- mime_types_variant,
- &error);
- if (!source_remote)
- {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_FAILED,
- "Invalid mime type list: %s",
- error->message);
- return TRUE;
- }
- }
-
- if (source_remote)
- {
- meta_topic (META_DEBUG_REMOTE_DESKTOP,
- "Setting remote desktop clipboard source: %p from %s",
- source_remote, session->peer_name);
-
- g_set_object (&session->current_source, source_remote);
- meta_selection_set_owner (selection,
- META_SELECTION_CLIPBOARD,
- META_SELECTION_SOURCE (source_remote));
- }
- else
- {
- MetaSelectionSource *owner;
-
- owner = meta_selection_get_current_owner (selection,
- META_SELECTION_CLIPBOARD);
-
- if (owner)
- emit_owner_changed (session, owner);
- }
-
- session->is_clipboard_enabled = TRUE;
- session->owner_changed_handler_id =
- g_signal_connect (selection, "owner-changed",
- G_CALLBACK (on_selection_owner_changed),
- session);
-
- meta_dbus_remote_desktop_session_complete_enable_clipboard (skeleton,
- invocation);
-
- return TRUE;
-}
-
-static gboolean
-cancel_transfer_request (gpointer key,
- gpointer value,
- gpointer user_data)
-{
- GTask *task = G_TASK (value);
- MetaRemoteDesktopSession *session = user_data;
-
- meta_selection_source_remote_cancel_transfer (session->current_source,
- task);
-
- return TRUE;
-}
-
-static void
-meta_remote_desktop_session_cancel_transfer_requests (MetaRemoteDesktopSession *session)
-{
- g_return_if_fail (session->current_source);
-
- g_hash_table_foreach_remove (session->transfer_requests,
- cancel_transfer_request,
- session);
-}
-
-static gboolean
-transfer_request_cleanup_timout (gpointer user_data)
-{
- MetaRemoteDesktopSession *session = user_data;
-
- meta_topic (META_DEBUG_REMOTE_DESKTOP,
- "Cancel unanswered SelectionTransfer requests for %s, "
- "waited for %.02f seconds already",
- session->peer_name,
- TRANSFER_REQUEST_CLEANUP_TIMEOUT_MS / 1000.0);
-
- meta_remote_desktop_session_cancel_transfer_requests (session);
-
- session->transfer_request_timeout_id = 0;
- return G_SOURCE_REMOVE;
-}
-
-static void
-reset_current_selection_source (MetaRemoteDesktopSession *session)
-{
- MetaDisplay *display = meta_get_display ();
- MetaSelection *selection = meta_display_get_selection (display);
-
- if (!session->current_source)
- return;
-
- meta_selection_unset_owner (selection,
- META_SELECTION_CLIPBOARD,
- META_SELECTION_SOURCE (session->current_source));
- meta_remote_desktop_session_cancel_transfer_requests (session);
- g_clear_handle_id (&session->transfer_request_timeout_id, g_source_remove);
- g_clear_object (&session->current_source);
-}
-
-static void
-cancel_selection_read (MetaRemoteDesktopSession *session)
-{
- if (!session->read_data)
- return;
-
- g_cancellable_cancel (session->read_data->cancellable);
- session->read_data->session = NULL;
- session->read_data = NULL;
-}
-
-static gboolean
-handle_disable_clipboard (MetaDBusRemoteDesktopSession *skeleton,
- GDBusMethodInvocation *invocation)
-{
- MetaRemoteDesktopSession *session = META_REMOTE_DESKTOP_SESSION (skeleton);
- MetaDisplay *display = meta_get_display ();
- MetaSelection *selection = meta_display_get_selection (display);
-
- meta_topic (META_DEBUG_REMOTE_DESKTOP,
- "Disable clipboard for %s",
- g_dbus_method_invocation_get_sender (invocation));
-
- if (!session->is_clipboard_enabled)
- {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_FAILED,
- "Was not enabled");
- return TRUE;
- }
-
- g_clear_signal_handler (&session->owner_changed_handler_id, selection);
- reset_current_selection_source (session);
- cancel_selection_read (session);
-
- meta_dbus_remote_desktop_session_complete_disable_clipboard (skeleton,
- invocation);
-
- return TRUE;
-}
-
-static gboolean
-handle_set_selection (MetaDBusRemoteDesktopSession *skeleton,
- GDBusMethodInvocation *invocation,
- GVariant *arg_options)
-{
- MetaRemoteDesktopSession *session = META_REMOTE_DESKTOP_SESSION (skeleton);
- g_autoptr (GVariant) mime_types_variant = NULL;
- g_autoptr (GError) error = NULL;
-
- if (!session->is_clipboard_enabled)
- {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_FAILED,
- "Clipboard not enabled");
- return TRUE;
- }
-
- if (session->current_source)
- {
- meta_remote_desktop_session_cancel_transfer_requests (session);
- g_clear_handle_id (&session->transfer_request_timeout_id,
- g_source_remove);
- }
-
- mime_types_variant = g_variant_lookup_value (arg_options,
- "mime-types",
- G_VARIANT_TYPE_STRING_ARRAY);
- if (mime_types_variant)
- {
- g_autoptr (MetaSelectionSourceRemote) source_remote = NULL;
- MetaDisplay *display = meta_get_display ();
-
- source_remote = create_remote_desktop_source (session,
- mime_types_variant,
- &error);
- if (!source_remote)
- {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_FAILED,
- "Invalid format list: %s",
- error->message);
- return TRUE;
- }
-
- meta_topic (META_DEBUG_REMOTE_DESKTOP,
- "Set selection for %s to %p",
- g_dbus_method_invocation_get_sender (invocation),
- source_remote);
-
- g_set_object (&session->current_source, source_remote);
- meta_selection_set_owner (meta_display_get_selection (display),
- META_SELECTION_CLIPBOARD,
- META_SELECTION_SOURCE (source_remote));
- }
- else
- {
- meta_topic (META_DEBUG_REMOTE_DESKTOP,
- "Unset selection for %s",
- g_dbus_method_invocation_get_sender (invocation));
-
- reset_current_selection_source (session);
- }
-
- meta_dbus_remote_desktop_session_complete_set_selection (skeleton,
- invocation);
-
- return TRUE;
-}
-
-static void
-reset_transfer_cleanup_timeout (MetaRemoteDesktopSession *session)
-{
- g_clear_handle_id (&session->transfer_request_timeout_id, g_source_remove);
- session->transfer_request_timeout_id =
- g_timeout_add (TRANSFER_REQUEST_CLEANUP_TIMEOUT_MS,
- transfer_request_cleanup_timout,
- session);
-}
-
-void
-meta_remote_desktop_session_request_transfer (MetaRemoteDesktopSession *session,
- const char *mime_type,
- GTask *task)
-{
- const char *object_path;
-
- session->transfer_serial++;
-
- meta_topic (META_DEBUG_REMOTE_DESKTOP,
- "Emit SelectionTransfer ('%s', %u) for %s",
- mime_type,
- session->transfer_serial,
- session->peer_name);
-
- g_hash_table_insert (session->transfer_requests,
- GUINT_TO_POINTER (session->transfer_serial),
- task);
- reset_transfer_cleanup_timeout (session);
-
- object_path = g_dbus_interface_skeleton_get_object_path (
- G_DBUS_INTERFACE_SKELETON (session));
- g_dbus_connection_emit_signal (session->connection,
- NULL,
- object_path,
- "org.gnome.Mutter.RemoteDesktop.Session",
- "SelectionTransfer",
- g_variant_new ("(su)",
- mime_type,
- session->transfer_serial),
- NULL);
-}
-
-static gboolean
-handle_selection_write (MetaDBusRemoteDesktopSession *skeleton,
- GDBusMethodInvocation *invocation,
- GUnixFDList *fd_list_in,
- unsigned int serial)
-{
- MetaRemoteDesktopSession *session = META_REMOTE_DESKTOP_SESSION (skeleton);
- g_autoptr (GError) error = NULL;
- int pipe_fds[2];
- g_autoptr (GUnixFDList) fd_list = NULL;
- int fd_idx;
- GVariant *fd_variant;
- GTask *task;
-
- meta_topic (META_DEBUG_REMOTE_DESKTOP,
- "Write selection for %s",
- g_dbus_method_invocation_get_sender (invocation));
-
- if (!session->is_clipboard_enabled)
- {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_FAILED,
- "Clipboard not enabled");
- return TRUE;
- }
-
- if (!session->current_source)
- {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_FAILED,
- "No current selection owned");
- return TRUE;
- }
-
- if (!g_hash_table_steal_extended (session->transfer_requests,
- GUINT_TO_POINTER (serial),
- NULL,
- (gpointer *) &task))
- {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_FAILED,
- "Transfer serial %u doesn't match "
- "any transfer request",
- serial);
- return TRUE;
- }
-
- if (!g_unix_open_pipe (pipe_fds, FD_CLOEXEC, &error))
- {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_FAILED,
- "Failed open pipe: %s",
- error->message);
- return TRUE;
- }
-
- if (!g_unix_set_fd_nonblocking (pipe_fds[0], TRUE, &error))
- {
- close (pipe_fds[0]);
- close (pipe_fds[1]);
-
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_FAILED,
- "Failed to make pipe non-blocking: %s",
- error->message);
- return TRUE;
- }
-
- fd_list = g_unix_fd_list_new ();
-
- fd_idx = g_unix_fd_list_append (fd_list, pipe_fds[1], NULL);
- close (pipe_fds[1]);
- fd_variant = g_variant_new_handle (fd_idx);
-
- meta_selection_source_remote_complete_transfer (session->current_source,
- pipe_fds[0],
- task);
-
- meta_dbus_remote_desktop_session_complete_selection_write (skeleton,
- invocation,
- fd_list,
- fd_variant);
-
- return TRUE;
-}
-
-static gboolean
-handle_selection_write_done (MetaDBusRemoteDesktopSession *skeleton,
- GDBusMethodInvocation *invocation,
- unsigned int arg_serial,
- gboolean arg_success)
-{
- MetaRemoteDesktopSession *session = META_REMOTE_DESKTOP_SESSION (skeleton);
-
- meta_topic (META_DEBUG_REMOTE_DESKTOP,
- "Write selection done for %s",
- g_dbus_method_invocation_get_sender (invocation));
-
- if (!session->is_clipboard_enabled)
- {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_FAILED,
- "Clipboard not enabled");
- return TRUE;
- }
-
- meta_dbus_remote_desktop_session_complete_selection_write_done (skeleton,
- invocation);
-
- return TRUE;
-}
-
-static void
-transfer_cb (MetaSelection *selection,
- GAsyncResult *res,
- SelectionReadData *read_data)
-{
- g_autoptr (GError) error = NULL;
-
- if (!meta_selection_transfer_finish (selection, res, &error))
- {
- g_warning ("Could not fetch selection data "
- "for remote desktop session: %s",
- error->message);
- }
-
- if (read_data->session)
- {
- meta_topic (META_DEBUG_REMOTE_DESKTOP, "Finished selection transfer for %s",
- read_data->session->peer_name);
- }
-
- g_output_stream_close (read_data->stream, NULL, NULL);
- g_clear_object (&read_data->stream);
- g_clear_object (&read_data->cancellable);
-
- if (read_data->session)
- read_data->session->read_data = NULL;
-
- g_free (read_data);
-}
-
-static gboolean
-handle_selection_read (MetaDBusRemoteDesktopSession *skeleton,
- GDBusMethodInvocation *invocation,
- GUnixFDList *fd_list_in,
- const char *mime_type)
-{
- MetaRemoteDesktopSession *session = META_REMOTE_DESKTOP_SESSION (skeleton);
- MetaDisplay *display = meta_get_display ();
- MetaSelection *selection = meta_display_get_selection (display);
- MetaSelectionSource *source;
- g_autoptr (GError) error = NULL;
- int pipe_fds[2];
- g_autoptr (GUnixFDList) fd_list = NULL;
- int fd_idx;
- GVariant *fd_variant;
- SelectionReadData *read_data;
-
- meta_topic (META_DEBUG_REMOTE_DESKTOP,
- "Read selection for %s",
- g_dbus_method_invocation_get_sender (invocation));
-
- if (!session->is_clipboard_enabled)
- {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_FAILED,
- "Clipboard not enabled");
- return TRUE;
- }
-
- source = meta_selection_get_current_owner (selection,
- META_SELECTION_CLIPBOARD);
- if (!source)
- {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_FILE_NOT_FOUND,
- "No selection owner available");
- return TRUE;
- }
-
- if (is_own_source (session, source))
- {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_FAILED,
- "Tried to read own selection");
- return TRUE;
- }
-
- if (session->read_data)
- {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_LIMITS_EXCEEDED,
- "Tried to read in parallel");
- return TRUE;
- }
-
- if (!g_unix_open_pipe (pipe_fds, FD_CLOEXEC, &error))
- {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_FAILED,
- "Failed open pipe: %s",
- error->message);
- return TRUE;
- }
-
- if (!g_unix_set_fd_nonblocking (pipe_fds[0], TRUE, &error))
- {
- close (pipe_fds[0]);
- close (pipe_fds[1]);
-
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_FAILED,
- "Failed to make pipe non-blocking: %s",
- error->message);
- return TRUE;
- }
-
- fd_list = g_unix_fd_list_new ();
-
- fd_idx = g_unix_fd_list_append (fd_list, pipe_fds[0], NULL);
- close (pipe_fds[0]);
- fd_variant = g_variant_new_handle (fd_idx);
-
- session->read_data = read_data = g_new0 (SelectionReadData, 1);
- read_data->session = session;
- read_data->stream = g_unix_output_stream_new (pipe_fds[1], TRUE);
- read_data->cancellable = g_cancellable_new ();
- meta_selection_transfer_async (selection,
- META_SELECTION_CLIPBOARD,
- mime_type,
- -1,
- read_data->stream,
- read_data->cancellable,
- (GAsyncReadyCallback) transfer_cb,
- read_data);
-
- meta_dbus_remote_desktop_session_complete_selection_read (skeleton,
- invocation,
- fd_list,
- fd_variant);
-
- return TRUE;
-}
-
-static void
-meta_remote_desktop_session_init_iface (MetaDBusRemoteDesktopSessionIface *iface)
-{
- iface->handle_start = handle_start;
- iface->handle_stop = handle_stop;
- iface->handle_notify_keyboard_keycode = handle_notify_keyboard_keycode;
- iface->handle_notify_keyboard_keysym = handle_notify_keyboard_keysym;
- iface->handle_notify_pointer_button = handle_notify_pointer_button;
- iface->handle_notify_pointer_axis = handle_notify_pointer_axis;
- iface->handle_notify_pointer_axis_discrete = handle_notify_pointer_axis_discrete;
- iface->handle_notify_pointer_motion_relative = handle_notify_pointer_motion_relative;
- iface->handle_notify_pointer_motion_absolute = handle_notify_pointer_motion_absolute;
- iface->handle_notify_touch_down = handle_notify_touch_down;
- iface->handle_notify_touch_motion = handle_notify_touch_motion;
- iface->handle_notify_touch_up = handle_notify_touch_up;
- iface->handle_enable_clipboard = handle_enable_clipboard;
- iface->handle_disable_clipboard = handle_disable_clipboard;
- iface->handle_set_selection = handle_set_selection;
- iface->handle_selection_write = handle_selection_write;
- iface->handle_selection_write_done = handle_selection_write_done;
- iface->handle_selection_read = handle_selection_read;
-}
-
-static void
-meta_remote_desktop_session_client_vanished (MetaDbusSession *dbus_session)
-{
- meta_remote_desktop_session_close (META_REMOTE_DESKTOP_SESSION (dbus_session));
-}
-
-static void
-meta_dbus_session_init_iface (MetaDbusSessionInterface *iface)
-{
- iface->client_vanished = meta_remote_desktop_session_client_vanished;
-}
-
-static void
-meta_remote_desktop_session_finalize (GObject *object)
-{
- MetaRemoteDesktopSession *session = META_REMOTE_DESKTOP_SESSION (object);
- MetaDisplay *display = meta_get_display ();
- MetaSelection *selection = meta_display_get_selection (display);
-
- g_assert (!meta_remote_desktop_session_is_running (session));
-
- g_clear_signal_handler (&session->owner_changed_handler_id, selection);
- reset_current_selection_source (session);
- cancel_selection_read (session);
- g_hash_table_unref (session->transfer_requests);
-
- g_clear_object (&session->handle);
- g_free (session->peer_name);
- g_free (session->session_id);
- g_free (session->object_path);
-
- G_OBJECT_CLASS (meta_remote_desktop_session_parent_class)->finalize (object);
-}
-
-static void
-meta_remote_desktop_session_init (MetaRemoteDesktopSession *session)
-{
- MetaDBusRemoteDesktopSession *skeleton =
- META_DBUS_REMOTE_DESKTOP_SESSION (session);
- GRand *rand;
- static unsigned int global_session_number = 0;
-
- rand = g_rand_new ();
- session->session_id = meta_generate_random_id (rand, 32);
- g_rand_free (rand);
-
- meta_dbus_remote_desktop_session_set_session_id (skeleton, session->session_id);
-
- session->object_path =
- g_strdup_printf (META_REMOTE_DESKTOP_SESSION_DBUS_PATH "/u%u",
- ++global_session_number);
-
- session->transfer_requests = g_hash_table_new (NULL, NULL);
-}
-
-static void
-meta_remote_desktop_session_class_init (MetaRemoteDesktopSessionClass *klass)
-{
-
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- object_class->finalize = meta_remote_desktop_session_finalize;
-}
-
-static MetaRemoteDesktopSessionHandle *
-meta_remote_desktop_session_handle_new (MetaRemoteDesktopSession *session)
-{
- MetaRemoteDesktopSessionHandle *handle;
-
- handle = g_object_new (META_TYPE_REMOTE_DESKTOP_SESSION_HANDLE, NULL);
- handle->session = session;
-
- return handle;
-}
-
-static void
-meta_remote_desktop_session_handle_stop (MetaRemoteAccessHandle *handle)
-{
- MetaRemoteDesktopSession *session;
-
- session = META_REMOTE_DESKTOP_SESSION_HANDLE (handle)->session;
- if (!session)
- return;
-
- meta_remote_desktop_session_close (session);
-}
-
-static void
-meta_remote_desktop_session_handle_init (MetaRemoteDesktopSessionHandle *handle)
-{
-}
-
-static void
-meta_remote_desktop_session_handle_class_init (MetaRemoteDesktopSessionHandleClass *klass)
-{
- MetaRemoteAccessHandleClass *remote_access_handle_class =
- META_REMOTE_ACCESS_HANDLE_CLASS (klass);
-
- remote_access_handle_class->stop = meta_remote_desktop_session_handle_stop;
-}
diff --git a/src/backends/meta-remote-desktop-session.h b/src/backends/meta-remote-desktop-session.h
deleted file mode 100644
index 7af9c4897..000000000
--- a/src/backends/meta-remote-desktop-session.h
+++ /dev/null
@@ -1,60 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2015-2017 Red Hat Inc.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- */
-
-#ifndef META_REMOTE_DESKTOP_SESSION_H
-#define META_REMOTE_DESKTOP_SESSION_H
-
-#include <glib-object.h>
-
-#include "backends/meta-remote-desktop.h"
-#include "backends/meta-screen-cast-session.h"
-
-#define META_TYPE_REMOTE_DESKTOP_SESSION (meta_remote_desktop_session_get_type ())
-G_DECLARE_FINAL_TYPE (MetaRemoteDesktopSession, meta_remote_desktop_session,
- META, REMOTE_DESKTOP_SESSION,
- MetaDBusRemoteDesktopSessionSkeleton)
-
-#define META_TYPE_REMOTE_DESKTOP_SESSION_HANDLE (meta_remote_desktop_session_handle_get_type ())
-G_DECLARE_FINAL_TYPE (MetaRemoteDesktopSessionHandle,
- meta_remote_desktop_session_handle,
- META, REMOTE_DESKTOP_SESSION_HANDLE,
- MetaRemoteAccessHandle)
-
-char * meta_remote_desktop_session_get_object_path (MetaRemoteDesktopSession *session);
-
-char * meta_remote_desktop_session_get_session_id (MetaRemoteDesktopSession *session);
-
-gboolean meta_remote_desktop_session_register_screen_cast (MetaRemoteDesktopSession *session,
- MetaScreenCastSession *screen_cast_session,
- GError **error);
-
-void meta_remote_desktop_session_request_transfer (MetaRemoteDesktopSession *session,
- const char *mime_type,
- GTask *task);
-
-void meta_remote_desktop_session_close (MetaRemoteDesktopSession *session);
-
-MetaRemoteDesktopSession * meta_remote_desktop_session_new (MetaRemoteDesktop *remote_desktop,
- const char *peer_name,
- GError **error);
-
-#endif /* META_REMOTE_DESKTOP_SESSION_H */
diff --git a/src/backends/meta-remote-desktop.c b/src/backends/meta-remote-desktop.c
deleted file mode 100644
index f0a499818..000000000
--- a/src/backends/meta-remote-desktop.c
+++ /dev/null
@@ -1,342 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2015-2017 Red Hat Inc.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- */
-
-#include "config.h"
-
-#include "backends/meta-remote-desktop.h"
-
-#include <errno.h>
-#include <glib.h>
-#include <fcntl.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "backends/meta-backend-private.h"
-#include "backends/meta-cursor-renderer.h"
-#include "backends/meta-remote-desktop-session.h"
-#include "backends/native/meta-cursor-renderer-native.h"
-#include "meta/meta-backend.h"
-
-#include "meta-dbus-remote-desktop.h"
-
-#define META_REMOTE_DESKTOP_DBUS_SERVICE "org.gnome.Mutter.RemoteDesktop"
-#define META_REMOTE_DESKTOP_DBUS_PATH "/org/gnome/Mutter/RemoteDesktop"
-#define META_REMOTE_DESKTOP_API_VERSION 1
-
-typedef enum _MetaRemoteDesktopDeviceTypes
-{
- META_REMOTE_DESKTOP_DEVICE_TYPE_NONE = 0,
- META_REMOTE_DESKTOP_DEVICE_TYPE_KEYBOARD = 1 << 0,
- META_REMOTE_DESKTOP_DEVICE_TYPE_POINTER = 1 << 1,
- META_REMOTE_DESKTOP_DEVICE_TYPE_TOUCHSCREEN = 1 << 2,
-} MetaRemoteDesktopDeviceTypes;
-
-struct _MetaRemoteDesktop
-{
- MetaDBusRemoteDesktopSkeleton parent;
-
- MetaBackend *backend;
- int dbus_name_id;
-
- int inhibit_count;
-
- GHashTable *sessions;
-
- MetaDbusSessionWatcher *session_watcher;
-};
-
-static void
-meta_remote_desktop_init_iface (MetaDBusRemoteDesktopIface *iface);
-
-G_DEFINE_TYPE_WITH_CODE (MetaRemoteDesktop,
- meta_remote_desktop,
- META_DBUS_TYPE_REMOTE_DESKTOP_SKELETON,
- G_IMPLEMENT_INTERFACE (META_DBUS_TYPE_REMOTE_DESKTOP,
- meta_remote_desktop_init_iface));
-
-void
-meta_remote_desktop_inhibit (MetaRemoteDesktop *remote_desktop)
-{
- remote_desktop->inhibit_count++;
- if (remote_desktop->inhibit_count == 1)
- {
- GHashTableIter iter;
- gpointer key, value;
-
- g_hash_table_iter_init (&iter, remote_desktop->sessions);
- while (g_hash_table_iter_next (&iter, &key, &value))
- {
- MetaRemoteDesktopSession *session = value;
-
- g_hash_table_iter_steal (&iter);
- meta_remote_desktop_session_close (session);
- }
- }
-}
-
-void
-meta_remote_desktop_uninhibit (MetaRemoteDesktop *remote_desktop)
-{
- g_return_if_fail (remote_desktop->inhibit_count > 0);
-
- remote_desktop->inhibit_count--;
-}
-
-MetaBackend *
-meta_remote_desktop_get_backend (MetaRemoteDesktop *remote_desktop)
-{
- return remote_desktop->backend;
-}
-
-GDBusConnection *
-meta_remote_desktop_get_connection (MetaRemoteDesktop *remote_desktop)
-{
- GDBusInterfaceSkeleton *interface_skeleton =
- G_DBUS_INTERFACE_SKELETON (remote_desktop);
-
- return g_dbus_interface_skeleton_get_connection (interface_skeleton);
-}
-
-MetaRemoteDesktopSession *
-meta_remote_desktop_get_session (MetaRemoteDesktop *remote_desktop,
- const char *session_id)
-{
- return g_hash_table_lookup (remote_desktop->sessions, session_id);
-}
-
-static void
-on_session_closed (MetaRemoteDesktopSession *session,
- MetaRemoteDesktop *remote_desktop)
-{
- char *session_id;
-
- session_id = meta_remote_desktop_session_get_session_id (session);
- g_hash_table_remove (remote_desktop->sessions, session_id);
-}
-
-static gboolean
-handle_create_session (MetaDBusRemoteDesktop *skeleton,
- GDBusMethodInvocation *invocation)
-{
- MetaRemoteDesktop *remote_desktop = META_REMOTE_DESKTOP (skeleton);
- const char *peer_name;
- MetaRemoteDesktopSession *session;
- GError *error = NULL;
- char *session_id;
- char *session_path;
- const char *client_dbus_name;
-
- if (remote_desktop->inhibit_count > 0)
- {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_ACCESS_DENIED,
- "Session creation inhibited");
-
- return TRUE;
- }
-
- peer_name = g_dbus_method_invocation_get_sender (invocation);
- session = meta_remote_desktop_session_new (remote_desktop,
- peer_name,
- &error);
- if (!session)
- {
- g_warning ("Failed to create remote desktop session: %s",
- error->message);
-
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_FAILED,
- "Failed to create session: %s",
- error->message);
- g_error_free (error);
-
- return TRUE;
- }
-
- session_id = meta_remote_desktop_session_get_session_id (session);
- g_hash_table_insert (remote_desktop->sessions,
- session_id,
- session);
-
- client_dbus_name = g_dbus_method_invocation_get_sender (invocation);
- meta_dbus_session_watcher_watch_session (remote_desktop->session_watcher,
- client_dbus_name,
- META_DBUS_SESSION (session));
-
- session_path = meta_remote_desktop_session_get_object_path (session);
- meta_dbus_remote_desktop_complete_create_session (skeleton,
- invocation,
- session_path);
-
- g_signal_connect (session, "session-closed",
- G_CALLBACK (on_session_closed),
- remote_desktop);
-
- return TRUE;
-}
-
-static void
-meta_remote_desktop_init_iface (MetaDBusRemoteDesktopIface *iface)
-{
- iface->handle_create_session = handle_create_session;
-}
-
-static void
-on_bus_acquired (GDBusConnection *connection,
- const char *name,
- gpointer user_data)
-{
- MetaRemoteDesktop *remote_desktop = user_data;
- GDBusInterfaceSkeleton *interface_skeleton =
- G_DBUS_INTERFACE_SKELETON (remote_desktop);
- GError *error = NULL;
-
- if (!g_dbus_interface_skeleton_export (interface_skeleton,
- connection,
- META_REMOTE_DESKTOP_DBUS_PATH,
- &error))
- g_warning ("Failed to export remote desktop object: %s", error->message);
-}
-
-static void
-on_name_acquired (GDBusConnection *connection,
- const char *name,
- gpointer user_data)
-{
- g_info ("Acquired name %s", name);
-}
-
-static void
-on_name_lost (GDBusConnection *connection,
- const char *name,
- gpointer user_data)
-{
- g_warning ("Lost or failed to acquire name %s", name);
-}
-
-static void
-meta_remote_desktop_constructed (GObject *object)
-{
- MetaRemoteDesktop *remote_desktop = META_REMOTE_DESKTOP (object);
-
- remote_desktop->dbus_name_id =
- g_bus_own_name (G_BUS_TYPE_SESSION,
- META_REMOTE_DESKTOP_DBUS_SERVICE,
- G_BUS_NAME_OWNER_FLAGS_NONE,
- on_bus_acquired,
- on_name_acquired,
- on_name_lost,
- remote_desktop,
- NULL);
-}
-
-static void
-on_prepare_shutdown (MetaBackend *backend,
- MetaRemoteDesktop *remote_desktop)
-{
- GHashTableIter iter;
- gpointer value;
-
- g_hash_table_iter_init (&iter, remote_desktop->sessions);
- while (g_hash_table_iter_next (&iter, NULL, &value))
- {
- MetaRemoteDesktopSession *session = value;
-
- g_hash_table_iter_steal (&iter);
- meta_remote_desktop_session_close (session);
- }
-}
-
-static void
-meta_remote_desktop_finalize (GObject *object)
-{
- MetaRemoteDesktop *remote_desktop = META_REMOTE_DESKTOP (object);
-
- if (remote_desktop->dbus_name_id != 0)
- g_bus_unown_name (remote_desktop->dbus_name_id);
-
- g_assert (g_hash_table_size (remote_desktop->sessions) == 0);
- g_hash_table_destroy (remote_desktop->sessions);
-
- G_OBJECT_CLASS (meta_remote_desktop_parent_class)->finalize (object);
-}
-
-MetaRemoteDesktop *
-meta_remote_desktop_new (MetaBackend *backend,
- MetaDbusSessionWatcher *session_watcher)
-{
- MetaRemoteDesktop *remote_desktop;
-
- remote_desktop = g_object_new (META_TYPE_REMOTE_DESKTOP, NULL);
- remote_desktop->backend = backend;
- remote_desktop->session_watcher = session_watcher;
-
- g_signal_connect (backend, "prepare-shutdown",
- G_CALLBACK (on_prepare_shutdown),
- remote_desktop);
-
- return remote_desktop;
-}
-
-static MetaRemoteDesktopDeviceTypes
-calculate_supported_device_types (void)
-{
- ClutterBackend *backend = clutter_get_default_backend ();
- ClutterSeat *seat = clutter_backend_get_default_seat (backend);
- ClutterVirtualDeviceType device_types;
- MetaRemoteDesktopDeviceTypes supported_devices =
- META_REMOTE_DESKTOP_DEVICE_TYPE_NONE;
-
- device_types =
- clutter_seat_get_supported_virtual_device_types (seat);
-
- if (device_types & CLUTTER_VIRTUAL_DEVICE_TYPE_KEYBOARD)
- supported_devices |= META_REMOTE_DESKTOP_DEVICE_TYPE_KEYBOARD;
- if (device_types & CLUTTER_VIRTUAL_DEVICE_TYPE_POINTER)
- supported_devices |= META_REMOTE_DESKTOP_DEVICE_TYPE_POINTER;
- if (device_types & CLUTTER_VIRTUAL_DEVICE_TYPE_TOUCHSCREEN)
- supported_devices |= META_REMOTE_DESKTOP_DEVICE_TYPE_TOUCHSCREEN;
-
- return supported_devices;
-}
-
-static void
-meta_remote_desktop_init (MetaRemoteDesktop *remote_desktop)
-{
- remote_desktop->sessions = g_hash_table_new (g_str_hash, g_str_equal);
-
- meta_dbus_remote_desktop_set_supported_device_types (
- META_DBUS_REMOTE_DESKTOP (remote_desktop),
- calculate_supported_device_types ());
- meta_dbus_remote_desktop_set_version (
- META_DBUS_REMOTE_DESKTOP (remote_desktop),
- META_REMOTE_DESKTOP_API_VERSION);
-}
-
-static void
-meta_remote_desktop_class_init (MetaRemoteDesktopClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- object_class->constructed = meta_remote_desktop_constructed;
- object_class->finalize = meta_remote_desktop_finalize;
-}
diff --git a/src/backends/meta-remote-desktop.h b/src/backends/meta-remote-desktop.h
deleted file mode 100644
index 3a7f38563..000000000
--- a/src/backends/meta-remote-desktop.h
+++ /dev/null
@@ -1,54 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2015-2017 Red Hat Inc.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- */
-
-#ifndef META_REMOTE_DESKTOP_H
-#define META_REMOTE_DESKTOP_H
-
-#include <glib-object.h>
-
-#include "backends/meta-backend-types.h"
-#include "backends/meta-dbus-session-watcher.h"
-
-#include "meta-dbus-remote-desktop.h"
-
-typedef struct _MetaRemoteDesktopSession MetaRemoteDesktopSession;
-
-#define META_TYPE_REMOTE_DESKTOP (meta_remote_desktop_get_type ())
-G_DECLARE_FINAL_TYPE (MetaRemoteDesktop, meta_remote_desktop,
- META, REMOTE_DESKTOP,
- MetaDBusRemoteDesktopSkeleton)
-
-void meta_remote_desktop_inhibit (MetaRemoteDesktop *remote_desktop);
-
-void meta_remote_desktop_uninhibit (MetaRemoteDesktop *remote_desktop);
-
-MetaBackend * meta_remote_desktop_get_backend (MetaRemoteDesktop *remote_desktop);
-
-MetaRemoteDesktopSession * meta_remote_desktop_get_session (MetaRemoteDesktop *remote_desktop,
- const char *session_id);
-
-GDBusConnection * meta_remote_desktop_get_connection (MetaRemoteDesktop *remote_desktop);
-
-MetaRemoteDesktop * meta_remote_desktop_new (MetaBackend *backend,
- MetaDbusSessionWatcher *session_watcher);
-
-#endif /* META_REMOTE_DESKTOP_H */
diff --git a/src/backends/meta-renderer-view.c b/src/backends/meta-renderer-view.c
deleted file mode 100644
index 55617fc68..000000000
--- a/src/backends/meta-renderer-view.c
+++ /dev/null
@@ -1,247 +0,0 @@
-/*
- * Copyright (C) 2016 Red Hat Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/**
- * SECTION:meta-renderer-view
- * @title: MetaRendererView
- * @short_description: Renders (a part of) the global stage.
- *
- * A MetaRendererView object is responsible for rendering (a part of) the
- * global stage, or more precisely: the part that matches what can be seen on a
- * #MetaLogicalMonitor. By splitting up the rendering into different parts and
- * attaching it to a #MetaLogicalMonitor, we can do the rendering so that each
- * renderer view is responsible for applying the right #MetaMonitorTransform
- * and the right scaling.
- */
-
-#include "config.h"
-
-#include "backends/meta-renderer-view.h"
-
-#include "backends/meta-crtc.h"
-#include "backends/meta-renderer.h"
-#include "clutter/clutter-mutter.h"
-#include "compositor/region-utils.h"
-
-enum
-{
- PROP_0,
-
- PROP_TRANSFORM,
- PROP_CRTC,
-
- PROP_LAST
-};
-
-static GParamSpec *obj_props[PROP_LAST];
-
-struct _MetaRendererView
-{
- MetaStageView parent;
-
- MetaMonitorTransform transform;
-
- MetaCrtc *crtc;
-};
-
-G_DEFINE_TYPE (MetaRendererView, meta_renderer_view,
- META_TYPE_STAGE_VIEW)
-
-MetaMonitorTransform
-meta_renderer_view_get_transform (MetaRendererView *view)
-{
- return view->transform;
-}
-
-MetaCrtc *
-meta_renderer_view_get_crtc (MetaRendererView *view)
-{
- return view->crtc;
-}
-
-static void
-meta_renderer_view_get_offscreen_transformation_matrix (ClutterStageView *view,
- graphene_matrix_t *matrix)
-{
- MetaRendererView *renderer_view = META_RENDERER_VIEW (view);
-
- graphene_matrix_init_identity (matrix);
-
- switch (renderer_view->transform)
- {
- case META_MONITOR_TRANSFORM_NORMAL:
- break;
- case META_MONITOR_TRANSFORM_90:
- graphene_matrix_translate (matrix, &GRAPHENE_POINT3D_INIT (0, -1, 0));
- graphene_matrix_rotate (matrix, 90, graphene_vec3_z_axis ());
- break;
- case META_MONITOR_TRANSFORM_180:
- graphene_matrix_translate (matrix, &GRAPHENE_POINT3D_INIT (-1, -1, 0));
- graphene_matrix_rotate (matrix, 180, graphene_vec3_z_axis ());
- break;
- case META_MONITOR_TRANSFORM_270:
- graphene_matrix_translate (matrix, &GRAPHENE_POINT3D_INIT (-1, 0, 0));
- graphene_matrix_rotate (matrix, 270, graphene_vec3_z_axis ());
- break;
- case META_MONITOR_TRANSFORM_FLIPPED:
- graphene_matrix_translate (matrix, &GRAPHENE_POINT3D_INIT (-1, 0, 0));
- graphene_matrix_scale (matrix, -1, 1, 1);
- break;
- case META_MONITOR_TRANSFORM_FLIPPED_90:
- graphene_matrix_rotate (matrix, 90, graphene_vec3_z_axis ());
- graphene_matrix_scale (matrix, -1, 1, 1);
- break;
- case META_MONITOR_TRANSFORM_FLIPPED_180:
- graphene_matrix_translate (matrix, &GRAPHENE_POINT3D_INIT (0, -1, 0));
- graphene_matrix_rotate (matrix, 180, graphene_vec3_z_axis ());
- graphene_matrix_scale (matrix, -1, 1, 1);
- break;
- case META_MONITOR_TRANSFORM_FLIPPED_270:
- graphene_matrix_translate (matrix, &GRAPHENE_POINT3D_INIT (-1, -1, 0));
- graphene_matrix_rotate (matrix, 270, graphene_vec3_z_axis ());
- graphene_matrix_scale (matrix, -1, 1, 1);
- break;
- }
-}
-
-static void
-meta_renderer_view_setup_offscreen_blit_pipeline (ClutterStageView *view,
- CoglPipeline *pipeline)
-{
- graphene_matrix_t matrix;
-
- meta_renderer_view_get_offscreen_transformation_matrix (view, &matrix);
- cogl_pipeline_set_layer_matrix (pipeline, 0, &matrix);
-}
-
-static void
-meta_renderer_view_transform_rect_to_onscreen (ClutterStageView *view,
- const cairo_rectangle_int_t *src_rect,
- int dst_width,
- int dst_height,
- cairo_rectangle_int_t *dst_rect)
-{
- MetaRendererView *renderer_view = META_RENDERER_VIEW (view);
- MetaMonitorTransform inverted_transform;
-
- inverted_transform =
- meta_monitor_transform_invert (renderer_view->transform);
- return meta_rectangle_transform (src_rect,
- inverted_transform,
- dst_width,
- dst_height,
- dst_rect);
-}
-
-static void
-meta_renderer_view_set_transform (MetaRendererView *view,
- MetaMonitorTransform transform)
-{
- if (view->transform == transform)
- return;
-
- view->transform = transform;
- clutter_stage_view_invalidate_offscreen_blit_pipeline (CLUTTER_STAGE_VIEW (view));
-}
-
-static void
-meta_renderer_view_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- MetaRendererView *view = META_RENDERER_VIEW (object);
-
- switch (prop_id)
- {
- case PROP_TRANSFORM:
- g_value_set_uint (value, view->transform);
- break;
- case PROP_CRTC:
- g_value_set_object (value, view->crtc);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-
-static void
-meta_renderer_view_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- MetaRendererView *view = META_RENDERER_VIEW (object);
-
- switch (prop_id)
- {
- case PROP_TRANSFORM:
- meta_renderer_view_set_transform (view, g_value_get_uint (value));
- break;
- case PROP_CRTC:
- view->crtc = g_value_get_object (value);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-
-static void
-meta_renderer_view_init (MetaRendererView *view)
-{
-}
-
-static void
-meta_renderer_view_class_init (MetaRendererViewClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
- ClutterStageViewClass *view_class = CLUTTER_STAGE_VIEW_CLASS (klass);
-
- view_class->setup_offscreen_blit_pipeline =
- meta_renderer_view_setup_offscreen_blit_pipeline;
- view_class->get_offscreen_transformation_matrix =
- meta_renderer_view_get_offscreen_transformation_matrix;
- view_class->transform_rect_to_onscreen =
- meta_renderer_view_transform_rect_to_onscreen;
-
- object_class->get_property = meta_renderer_view_get_property;
- object_class->set_property = meta_renderer_view_set_property;
-
- obj_props[PROP_TRANSFORM] =
- g_param_spec_uint ("transform",
- "Transform",
- "Transform to apply to the view",
- META_MONITOR_TRANSFORM_NORMAL,
- META_MONITOR_TRANSFORM_FLIPPED_270,
- META_MONITOR_TRANSFORM_NORMAL,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT_ONLY |
- G_PARAM_STATIC_STRINGS);
-
- obj_props[PROP_CRTC] =
- g_param_spec_object ("crtc",
- "MetaCrtc",
- "MetaCrtc",
- META_TYPE_CRTC,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT_ONLY |
- G_PARAM_STATIC_STRINGS);
-
- g_object_class_install_properties (object_class, PROP_LAST, obj_props);
-}
diff --git a/src/backends/meta-renderer-view.h b/src/backends/meta-renderer-view.h
deleted file mode 100644
index 3f21c7c48..000000000
--- a/src/backends/meta-renderer-view.h
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright (C) 2016 Red Hat Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef META_RENDERER_VIEW_H
-#define META_RENDERER_VIEW_H
-
-#include "backends/meta-monitor-manager-private.h"
-#include "backends/meta-stage-impl-private.h"
-#include "backends/meta-stage-view-private.h"
-
-#define META_TYPE_RENDERER_VIEW (meta_renderer_view_get_type ())
-G_DECLARE_FINAL_TYPE (MetaRendererView, meta_renderer_view,
- META, RENDERER_VIEW,
- MetaStageView)
-
-MetaMonitorTransform meta_renderer_view_get_transform (MetaRendererView *view);
-
-MetaCrtc *meta_renderer_view_get_crtc (MetaRendererView *view);
-
-#endif /* META_RENDERER_VIEW_H */
diff --git a/src/backends/meta-renderer.c b/src/backends/meta-renderer.c
deleted file mode 100644
index 8808a52ef..000000000
--- a/src/backends/meta-renderer.c
+++ /dev/null
@@ -1,405 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2016 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Written by:
- * Jonas Ådahl <jadahl@gmail.com>
- */
-
-/**
- * SECTION:meta-renderer
- * @title: MetaRenderer
- * @short_description: Keeps track of the different renderer views.
- *
- * A MetaRenderer object has 2 functions:
- *
- * 1) Keeping a list of #MetaRendererView<!-- -->s, each responsible for
- * rendering a part of the stage, corresponding to each #MetaLogicalMonitor. It
- * keeps track of this list by querying the list of logical monitors in the
- * #MetaBackend's #MetaMonitorManager, and creating a renderer view for each
- * logical monitor it encounters.
- *
- * 2) Creating and setting up an appropriate #CoglRenderer. For example, a
- * #MetaRenderer might call cogl_renderer_set_custom_winsys() to tie the
- * backend-specific mechanisms into Cogl.
- */
-
-#include "config.h"
-
-#include "backends/meta-renderer.h"
-
-#include <glib-object.h>
-
-#include "backends/meta-backend-private.h"
-#include "backends/meta-logical-monitor.h"
-
-enum
-{
- PROP_0,
-
- PROP_BACKEND,
-
- N_PROPS
-};
-
-static GParamSpec *obj_props[N_PROPS];
-
-typedef struct _MetaRendererPrivate
-{
- MetaBackend *backend;
- GList *views;
- gboolean is_paused;
-} MetaRendererPrivate;
-
-G_DEFINE_TYPE_WITH_PRIVATE (MetaRenderer, meta_renderer, G_TYPE_OBJECT)
-
-MetaBackend *
-meta_renderer_get_backend (MetaRenderer *renderer)
-{
- MetaRendererPrivate *priv = meta_renderer_get_instance_private (renderer);
-
- return priv->backend;
-}
-
-/**
- * meta_renderer_create_cogl_renderer:
- * @renderer: a #MetaRenderer object
- *
- * Creates a #CoglRenderer that is appropriate for a certain backend. For
- * example, a #MetaRenderer might call cogl_renderer_set_custom_winsys() to tie
- * the backend-specific mechanisms (such as swapBuffers and vsync) into Cogl.
- *
- * Returns: (transfer full): a newly made #CoglRenderer.
- */
-CoglRenderer *
-meta_renderer_create_cogl_renderer (MetaRenderer *renderer)
-{
- return META_RENDERER_GET_CLASS (renderer)->create_cogl_renderer (renderer);
-}
-
-static MetaRendererView *
-meta_renderer_create_view (MetaRenderer *renderer,
- MetaLogicalMonitor *logical_monitor,
- MetaOutput *output,
- MetaCrtc *crtc)
-{
- return META_RENDERER_GET_CLASS (renderer)->create_view (renderer,
- logical_monitor,
- output,
- crtc);
-}
-
-/**
- * meta_renderer_rebuild_views:
- * @renderer: a #MetaRenderer object
- *
- * Rebuilds the internal list of #MetaRendererView objects by querying the
- * current #MetaBackend's #MetaMonitorManager.
- *
- * This also leads to the original list of monitors being unconditionally freed.
- */
-void
-meta_renderer_rebuild_views (MetaRenderer *renderer)
-{
- return META_RENDERER_GET_CLASS (renderer)->rebuild_views (renderer);
-}
-
-static void
-create_crtc_view (MetaLogicalMonitor *logical_monitor,
- MetaMonitor *monitor,
- MetaOutput *output,
- MetaCrtc *crtc,
- gpointer user_data)
-{
- MetaRenderer *renderer = user_data;
- MetaRendererView *view;
-
- view = meta_renderer_create_view (renderer, logical_monitor, output, crtc);
- meta_renderer_add_view (renderer, view);
-}
-
-static void
-meta_renderer_real_rebuild_views (MetaRenderer *renderer)
-{
- MetaRendererPrivate *priv = meta_renderer_get_instance_private (renderer);
- MetaBackend *backend = meta_get_backend ();
- MetaMonitorManager *monitor_manager =
- meta_backend_get_monitor_manager (backend);
- GList *logical_monitors, *l;
-
- g_clear_list (&priv->views, (GDestroyNotify) clutter_stage_view_destroy);
-
- logical_monitors =
- meta_monitor_manager_get_logical_monitors (monitor_manager);
-
- for (l = logical_monitors; l; l = l->next)
- {
- MetaLogicalMonitor *logical_monitor = l->data;
-
- if (meta_logical_monitor_is_primary (logical_monitor))
- {
- ClutterBackend *clutter_backend;
- float scale;
-
- clutter_backend = meta_backend_get_clutter_backend (backend);
- scale = meta_is_stage_views_scaled ()
- ? meta_logical_monitor_get_scale (logical_monitor)
- : 1.f;
-
- clutter_backend_set_fallback_resource_scale (clutter_backend, scale);
- }
-
- meta_logical_monitor_foreach_crtc (logical_monitor,
- create_crtc_view,
- renderer);
- }
-}
-
-MetaRendererView *
-meta_renderer_get_view_for_crtc (MetaRenderer *renderer,
- MetaCrtc *crtc)
-{
- MetaRendererPrivate *priv = meta_renderer_get_instance_private (renderer);
- GList *l;
-
- for (l = priv->views; l; l = l->next)
- {
- MetaRendererView *view = l->data;
-
- if (meta_renderer_view_get_crtc (view) == crtc)
- return view;
- }
-
- return NULL;
-}
-
-typedef struct _CollectViewsData
-{
- MetaRenderer *renderer;
- GList *out_views;
-} CollectViewsData;
-
-static gboolean
-collect_views (MetaMonitor *monitor,
- MetaMonitorMode *mode,
- MetaMonitorCrtcMode *monitor_crtc_mode,
- gpointer user_data,
- GError **error)
-{
- CollectViewsData *data = user_data;
- MetaCrtc *crtc;
- MetaRendererView *view;
-
- crtc = meta_output_get_assigned_crtc (monitor_crtc_mode->output);
- view = meta_renderer_get_view_for_crtc (data->renderer, crtc);
- if (!g_list_find (data->out_views, view))
- data->out_views = g_list_prepend (data->out_views, view);
-
- return TRUE;
-}
-
-static GList *
-meta_renderer_real_get_views_for_monitor (MetaRenderer *renderer,
- MetaMonitor *monitor)
-{
- CollectViewsData data = { 0 };
- MetaMonitorMode *monitor_mode;
-
- data.renderer = renderer;
-
- monitor_mode = meta_monitor_get_current_mode (monitor);
- meta_monitor_mode_foreach_crtc (monitor, monitor_mode,
- collect_views,
- &data,
- NULL);
-
- return data.out_views;
-}
-
-GList *
-meta_renderer_get_views_for_monitor (MetaRenderer *renderer,
- MetaMonitor *monitor)
-{
- return META_RENDERER_GET_CLASS (renderer)->get_views_for_monitor (renderer,
- monitor);
-}
-
-void
-meta_renderer_add_view (MetaRenderer *renderer,
- MetaRendererView *view)
-{
- MetaRendererPrivate *priv = meta_renderer_get_instance_private (renderer);
-
- priv->views = g_list_append (priv->views, view);
-
- if (priv->is_paused)
- {
- ClutterFrameClock *frame_clock =
- clutter_stage_view_get_frame_clock (CLUTTER_STAGE_VIEW (view));
-
- clutter_frame_clock_inhibit (frame_clock);
- }
-}
-
-/**
- * meta_renderer_get_views:
- * @renderer: a #MetaRenderer object
- *
- * Returns a list of #MetaRendererView objects, each dealing with a part of the
- * stage.
- *
- * Returns: (transfer none) (element-type MetaRendererView): a list of
- * #MetaRendererView objects.
- */
-GList *
-meta_renderer_get_views (MetaRenderer *renderer)
-{
- MetaRendererPrivate *priv = meta_renderer_get_instance_private (renderer);
-
- return priv->views;
-}
-
-void
-meta_renderer_pause (MetaRenderer *renderer)
-{
- MetaRendererPrivate *priv = meta_renderer_get_instance_private (renderer);
- GList *l;
-
- g_return_if_fail (!priv->is_paused);
- priv->is_paused = TRUE;
-
- for (l = priv->views; l; l = l->next)
- {
- ClutterStageView *stage_view = l->data;
- ClutterFrameClock *frame_clock =
- clutter_stage_view_get_frame_clock (stage_view);
-
- clutter_frame_clock_inhibit (frame_clock);
- }
-}
-
-void
-meta_renderer_resume (MetaRenderer *renderer)
-{
- MetaRendererPrivate *priv = meta_renderer_get_instance_private (renderer);
- GList *l;
-
- g_return_if_fail (priv->is_paused);
- priv->is_paused = FALSE;
-
- for (l = priv->views; l; l = l->next)
- {
- ClutterStageView *stage_view = l->data;
- ClutterFrameClock *frame_clock =
- clutter_stage_view_get_frame_clock (stage_view);
-
- clutter_frame_clock_uninhibit (frame_clock);
- }
-}
-
-gboolean
-meta_renderer_is_hardware_accelerated (MetaRenderer *renderer)
-{
- MetaRendererPrivate *priv = meta_renderer_get_instance_private (renderer);
- MetaBackend *backend = priv->backend;
- ClutterBackend *clutter_backend = meta_backend_get_clutter_backend (backend);
- CoglContext *cogl_context =
- clutter_backend_get_cogl_context (clutter_backend);
-
- return cogl_context_is_hardware_accelerated (cogl_context);
-}
-
-static void
-meta_renderer_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- MetaRenderer *renderer = META_RENDERER (object);
- MetaRendererPrivate *priv = meta_renderer_get_instance_private (renderer);
-
- switch (prop_id)
- {
- case PROP_BACKEND:
- g_value_set_object (value, priv->backend);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-
-static void
-meta_renderer_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- MetaRenderer *renderer = META_RENDERER (object);
- MetaRendererPrivate *priv = meta_renderer_get_instance_private (renderer);
-
- switch (prop_id)
- {
- case PROP_BACKEND:
- priv->backend = g_value_get_object (value);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-
-static void
-meta_renderer_dispose (GObject *object)
-{
- MetaRenderer *renderer = META_RENDERER (object);
- MetaRendererPrivate *priv = meta_renderer_get_instance_private (renderer);
-
- g_clear_list (&priv->views, g_object_unref);
-
- G_OBJECT_CLASS (meta_renderer_parent_class)->dispose (object);
-}
-
-static void
-meta_renderer_init (MetaRenderer *renderer)
-{
-}
-
-static void
-meta_renderer_class_init (MetaRendererClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- object_class->get_property = meta_renderer_get_property;
- object_class->set_property = meta_renderer_set_property;
- object_class->dispose = meta_renderer_dispose;
-
- klass->rebuild_views = meta_renderer_real_rebuild_views;
- klass->get_views_for_monitor = meta_renderer_real_get_views_for_monitor;
-
- obj_props[PROP_BACKEND] =
- g_param_spec_object ("backend",
- "backend",
- "MetaBackend",
- META_TYPE_BACKEND,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT_ONLY |
- G_PARAM_STATIC_STRINGS);
- g_object_class_install_properties (object_class, N_PROPS, obj_props);
-}
diff --git a/src/backends/meta-renderer.h b/src/backends/meta-renderer.h
deleted file mode 100644
index 92b0727bb..000000000
--- a/src/backends/meta-renderer.h
+++ /dev/null
@@ -1,78 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2016 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Written by:
- * Jonas Ådahl <jadahl@gmail.com>
- */
-
-#ifndef META_RENDERER_H
-#define META_RENDERER_H
-
-#include <glib-object.h>
-
-#include "backends/meta-monitor-manager-private.h"
-#include "backends/meta-renderer-view.h"
-#include "core/util-private.h"
-#include "clutter/clutter-mutter.h"
-#include "cogl/cogl.h"
-
-#define META_TYPE_RENDERER (meta_renderer_get_type ())
-G_DECLARE_DERIVABLE_TYPE (MetaRenderer, meta_renderer, META, RENDERER, GObject)
-
-struct _MetaRendererClass
-{
- GObjectClass parent_class;
-
- CoglRenderer * (* create_cogl_renderer) (MetaRenderer *renderer);
- MetaRendererView * (* create_view) (MetaRenderer *renderer,
- MetaLogicalMonitor *logical_monitor,
- MetaOutput *output,
- MetaCrtc *crtc);
- void (* rebuild_views) (MetaRenderer *renderer);
- GList * (* get_views_for_monitor) (MetaRenderer *renderer,
- MetaMonitor *monitor);
-};
-
-MetaBackend * meta_renderer_get_backend (MetaRenderer *renderer);
-
-CoglRenderer * meta_renderer_create_cogl_renderer (MetaRenderer *renderer);
-
-void meta_renderer_rebuild_views (MetaRenderer *renderer);
-
-void meta_renderer_add_view (MetaRenderer *renderer,
- MetaRendererView *view);
-
-GList * meta_renderer_get_views_for_monitor (MetaRenderer *renderer,
- MetaMonitor *monitor);
-
-META_EXPORT_TEST
-MetaRendererView * meta_renderer_get_view_for_crtc (MetaRenderer *renderer,
- MetaCrtc *crtc);
-
-META_EXPORT_TEST
-GList * meta_renderer_get_views (MetaRenderer *renderer);
-
-gboolean meta_renderer_is_hardware_accelerated (MetaRenderer *renderer);
-
-void meta_renderer_pause (MetaRenderer *renderer);
-
-void meta_renderer_resume (MetaRenderer *renderer);
-
-#endif /* META_RENDERER_H */
diff --git a/src/backends/meta-screen-cast-area-stream-src.c b/src/backends/meta-screen-cast-area-stream-src.c
deleted file mode 100644
index aa1548101..000000000
--- a/src/backends/meta-screen-cast-area-stream-src.c
+++ /dev/null
@@ -1,652 +0,0 @@
-/*
- * Copyright (C) 2020 Red Hat Inc.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- */
-
-#include "config.h"
-
-#include "backends/meta-screen-cast-area-stream-src.h"
-
-#include <spa/buffer/meta.h>
-
-#include "backends/meta-backend-private.h"
-#include "backends/meta-cursor-tracker-private.h"
-#include "backends/meta-screen-cast-area-stream.h"
-#include "backends/meta-screen-cast-session.h"
-#include "backends/meta-stage-private.h"
-#include "clutter/clutter.h"
-#include "clutter/clutter-mutter.h"
-#include "core/boxes-private.h"
-
-struct _MetaScreenCastAreaStreamSrc
-{
- MetaScreenCastStreamSrc parent;
-
- gboolean cursor_bitmap_invalid;
- gboolean hw_cursor_inhibited;
-
- GList *watches;
-
- gulong position_invalidated_handler_id;
- gulong cursor_changed_handler_id;
-
- guint maybe_record_idle_id;
-};
-
-static void
-hw_cursor_inhibitor_iface_init (MetaHwCursorInhibitorInterface *iface);
-
-G_DEFINE_TYPE_WITH_CODE (MetaScreenCastAreaStreamSrc,
- meta_screen_cast_area_stream_src,
- META_TYPE_SCREEN_CAST_STREAM_SRC,
- G_IMPLEMENT_INTERFACE (META_TYPE_HW_CURSOR_INHIBITOR,
- hw_cursor_inhibitor_iface_init))
-
-static ClutterStage *
-get_stage (MetaScreenCastAreaStreamSrc *area_src)
-{
- MetaScreenCastStreamSrc *src;
- MetaScreenCastStream *stream;
- MetaScreenCastAreaStream *area_stream;
-
- src = META_SCREEN_CAST_STREAM_SRC (area_src);
- stream = meta_screen_cast_stream_src_get_stream (src);
- area_stream = META_SCREEN_CAST_AREA_STREAM (stream);
-
- return meta_screen_cast_area_stream_get_stage (area_stream);
-}
-
-static MetaBackend *
-get_backend (MetaScreenCastAreaStreamSrc *area_src)
-{
- MetaScreenCastStreamSrc *src = META_SCREEN_CAST_STREAM_SRC (area_src);
- MetaScreenCastStream *stream = meta_screen_cast_stream_src_get_stream (src);
- MetaScreenCastSession *session = meta_screen_cast_stream_get_session (stream);
- MetaScreenCast *screen_cast =
- meta_screen_cast_session_get_screen_cast (session);
-
- return meta_screen_cast_get_backend (screen_cast);
-}
-
-static gboolean
-meta_screen_cast_area_stream_src_get_specs (MetaScreenCastStreamSrc *src,
- int *width,
- int *height,
- float *frame_rate)
-{
- MetaScreenCastStream *stream = meta_screen_cast_stream_src_get_stream (src);
- MetaScreenCastAreaStream *area_stream = META_SCREEN_CAST_AREA_STREAM (stream);
- MetaRectangle *area;
- float scale;
-
- area = meta_screen_cast_area_stream_get_area (area_stream);
- scale = meta_screen_cast_area_stream_get_scale (area_stream);
-
- *width = (int) roundf (area->width * scale);
- *height = (int) roundf (area->height * scale);
- *frame_rate = 60.0;
-
- return TRUE;
-}
-
-static gboolean
-is_cursor_in_stream (MetaScreenCastAreaStreamSrc *area_src)
-{
- MetaScreenCastStreamSrc *src = META_SCREEN_CAST_STREAM_SRC (area_src);
- MetaScreenCastStream *stream = meta_screen_cast_stream_src_get_stream (src);
- MetaScreenCastAreaStream *area_stream = META_SCREEN_CAST_AREA_STREAM (stream);
- MetaBackend *backend = get_backend (area_src);
- MetaCursorRenderer *cursor_renderer =
- meta_backend_get_cursor_renderer (backend);
- MetaRectangle *area;
- graphene_rect_t area_rect;
- MetaCursorSprite *cursor_sprite;
-
- area = meta_screen_cast_area_stream_get_area (area_stream);
- area_rect = meta_rectangle_to_graphene_rect (area);
-
- cursor_sprite = meta_cursor_renderer_get_cursor (cursor_renderer);
- if (cursor_sprite)
- {
- graphene_rect_t cursor_rect;
-
- cursor_rect = meta_cursor_renderer_calculate_rect (cursor_renderer,
- cursor_sprite);
- return graphene_rect_intersection (&cursor_rect, &area_rect, NULL);
- }
- else
- {
- MetaCursorTracker *cursor_tracker =
- meta_backend_get_cursor_tracker (backend);
- graphene_point_t cursor_position;
-
- meta_cursor_tracker_get_pointer (cursor_tracker, &cursor_position, NULL);
- return graphene_rect_contains_point (&area_rect, &cursor_position);
- }
-}
-
-static gboolean
-is_redraw_queued (MetaScreenCastAreaStreamSrc *area_src)
-{
- ClutterStage *stage = get_stage (area_src);
- GList *l;
-
- for (l = clutter_stage_peek_stage_views (stage); l; l = l->next)
- {
- ClutterStageView *view = l->data;
-
- if (clutter_stage_is_redraw_queued_on_view (stage, view))
- return TRUE;
- }
-
- return FALSE;
-}
-
-static void
-sync_cursor_state (MetaScreenCastAreaStreamSrc *area_src)
-{
- MetaScreenCastStreamSrc *src = META_SCREEN_CAST_STREAM_SRC (area_src);
- MetaScreenCastRecordFlag flags;
-
- if (is_redraw_queued (area_src))
- return;
-
- flags = META_SCREEN_CAST_RECORD_FLAG_CURSOR_ONLY;
- meta_screen_cast_stream_src_maybe_record_frame (src, flags);
-}
-
-static void
-pointer_position_invalidated (MetaCursorTracker *cursor_tracker,
- MetaScreenCastAreaStreamSrc *area_src)
-{
- sync_cursor_state (area_src);
-}
-
-static void
-cursor_changed (MetaCursorTracker *cursor_tracker,
- MetaScreenCastAreaStreamSrc *area_src)
-{
- area_src->cursor_bitmap_invalid = TRUE;
- sync_cursor_state (area_src);
-}
-
-static void
-inhibit_hw_cursor (MetaScreenCastAreaStreamSrc *area_src)
-{
- MetaHwCursorInhibitor *inhibitor;
- MetaBackend *backend;
-
- g_return_if_fail (!area_src->hw_cursor_inhibited);
-
- backend = get_backend (area_src);
- inhibitor = META_HW_CURSOR_INHIBITOR (area_src);
- meta_backend_add_hw_cursor_inhibitor (backend, inhibitor);
-
- area_src->hw_cursor_inhibited = TRUE;
-}
-
-static void
-uninhibit_hw_cursor (MetaScreenCastAreaStreamSrc *area_src)
-{
- MetaHwCursorInhibitor *inhibitor;
- MetaBackend *backend;
-
- g_return_if_fail (area_src->hw_cursor_inhibited);
-
- backend = get_backend (area_src);
- inhibitor = META_HW_CURSOR_INHIBITOR (area_src);
- meta_backend_remove_hw_cursor_inhibitor (backend, inhibitor);
-
- area_src->hw_cursor_inhibited = FALSE;
-}
-
-static gboolean
-maybe_record_frame_on_idle (gpointer user_data)
-{
- MetaScreenCastAreaStreamSrc *area_src =
- META_SCREEN_CAST_AREA_STREAM_SRC (user_data);
- MetaScreenCastStreamSrc *src = META_SCREEN_CAST_STREAM_SRC (area_src);
- MetaScreenCastRecordFlag flags;
-
- area_src->maybe_record_idle_id = 0;
-
- flags = META_SCREEN_CAST_RECORD_FLAG_NONE;
- meta_screen_cast_stream_src_maybe_record_frame (src, flags);
-
- return G_SOURCE_REMOVE;
-}
-
-static void
-before_stage_painted (MetaStage *stage,
- ClutterStageView *view,
- ClutterPaintContext *paint_context,
- gpointer user_data)
-{
- MetaScreenCastAreaStreamSrc *area_src =
- META_SCREEN_CAST_AREA_STREAM_SRC (user_data);
- MetaScreenCastStreamSrc *src = META_SCREEN_CAST_STREAM_SRC (area_src);
-
- if (area_src->maybe_record_idle_id)
- return;
-
- if (!clutter_stage_view_peek_scanout (view))
- return;
-
- area_src->maybe_record_idle_id = g_idle_add (maybe_record_frame_on_idle, src);
-}
-
-static void
-stage_painted (MetaStage *stage,
- ClutterStageView *view,
- ClutterPaintContext *paint_context,
- gpointer user_data)
-{
- MetaScreenCastAreaStreamSrc *area_src =
- META_SCREEN_CAST_AREA_STREAM_SRC (user_data);
- MetaScreenCastStreamSrc *src = META_SCREEN_CAST_STREAM_SRC (area_src);
- MetaScreenCastStream *stream = meta_screen_cast_stream_src_get_stream (src);
- MetaScreenCastAreaStream *area_stream = META_SCREEN_CAST_AREA_STREAM (stream);
- const cairo_region_t *redraw_clip;
- MetaRectangle *area;
-
- if (area_src->maybe_record_idle_id)
- return;
-
- area = meta_screen_cast_area_stream_get_area (area_stream);
- redraw_clip = clutter_paint_context_get_redraw_clip (paint_context);
-
- if (redraw_clip)
- {
- switch (cairo_region_contains_rectangle (redraw_clip, area))
- {
- case CAIRO_REGION_OVERLAP_IN:
- case CAIRO_REGION_OVERLAP_PART:
- break;
- case CAIRO_REGION_OVERLAP_OUT:
- return;
- }
- }
-
- area_src->maybe_record_idle_id = g_idle_add (maybe_record_frame_on_idle, src);
-}
-
-static void
-add_view_painted_watches (MetaScreenCastAreaStreamSrc *area_src)
-{
- MetaScreenCastStreamSrc *src = META_SCREEN_CAST_STREAM_SRC (area_src);
- MetaScreenCastStream *stream = meta_screen_cast_stream_src_get_stream (src);
- MetaScreenCastAreaStream *area_stream = META_SCREEN_CAST_AREA_STREAM (stream);
- MetaBackend *backend = get_backend (area_src);
- MetaRenderer *renderer = meta_backend_get_renderer (backend);
- ClutterStage *stage;
- MetaStage *meta_stage;
- MetaRectangle *area;
- GList *l;
-
- stage = get_stage (area_src);
- meta_stage = META_STAGE (stage);
- area = meta_screen_cast_area_stream_get_area (area_stream);
-
- for (l = meta_renderer_get_views (renderer); l; l = l->next)
- {
- MetaRendererView *view = l->data;
- MetaRectangle view_layout;
-
- clutter_stage_view_get_layout (CLUTTER_STAGE_VIEW (view), &view_layout);
- if (meta_rectangle_overlap (area, &view_layout))
- {
- MetaStageWatch *watch;
-
- watch = meta_stage_watch_view (meta_stage,
- CLUTTER_STAGE_VIEW (view),
- META_STAGE_WATCH_BEFORE_PAINT,
- before_stage_painted,
- area_src);
-
- area_src->watches = g_list_prepend (area_src->watches, watch);
-
- watch = meta_stage_watch_view (meta_stage,
- CLUTTER_STAGE_VIEW (view),
- META_STAGE_WATCH_AFTER_ACTOR_PAINT,
- stage_painted,
- area_src);
-
- area_src->watches = g_list_prepend (area_src->watches, watch);
- }
- }
-}
-
-static void
-on_monitors_changed (MetaMonitorManager *monitor_manager,
- MetaScreenCastAreaStreamSrc *area_src)
-{
- MetaStage *stage = META_STAGE (get_stage (area_src));
- GList *l;
-
- for (l = area_src->watches; l; l = l->next)
- meta_stage_remove_watch (stage, l->data);
- g_clear_pointer (&area_src->watches, g_list_free);
-
- add_view_painted_watches (area_src);
-}
-
-static void
-meta_screen_cast_area_stream_src_enable (MetaScreenCastStreamSrc *src)
-{
- MetaScreenCastAreaStreamSrc *area_src =
- META_SCREEN_CAST_AREA_STREAM_SRC (src);
- MetaBackend *backend = get_backend (area_src);
- MetaMonitorManager *monitor_manager =
- meta_backend_get_monitor_manager (backend);
- MetaCursorTracker *cursor_tracker = meta_backend_get_cursor_tracker (backend);
- ClutterStage *stage;
- MetaScreenCastStream *stream;
-
- stream = meta_screen_cast_stream_src_get_stream (src);
- stage = get_stage (area_src);
-
- switch (meta_screen_cast_stream_get_cursor_mode (stream))
- {
- case META_SCREEN_CAST_CURSOR_MODE_METADATA:
- area_src->position_invalidated_handler_id =
- g_signal_connect_after (cursor_tracker, "position-invalidated",
- G_CALLBACK (pointer_position_invalidated),
- area_src);
- area_src->cursor_changed_handler_id =
- g_signal_connect_after (cursor_tracker, "cursor-changed",
- G_CALLBACK (cursor_changed),
- area_src);
- meta_cursor_tracker_track_position (cursor_tracker);
- G_GNUC_FALLTHROUGH;
- case META_SCREEN_CAST_CURSOR_MODE_HIDDEN:
- add_view_painted_watches (area_src);
- break;
- case META_SCREEN_CAST_CURSOR_MODE_EMBEDDED:
- inhibit_hw_cursor (area_src);
- meta_cursor_tracker_track_position (cursor_tracker);
- add_view_painted_watches (area_src);
- break;
- }
-
- g_signal_connect_object (monitor_manager, "monitors-changed-internal",
- G_CALLBACK (on_monitors_changed),
- area_src, 0);
-
- clutter_actor_queue_redraw (CLUTTER_ACTOR (stage));
-}
-
-static void
-meta_screen_cast_area_stream_src_disable (MetaScreenCastStreamSrc *src)
-{
- MetaScreenCastAreaStreamSrc *area_src =
- META_SCREEN_CAST_AREA_STREAM_SRC (src);
- MetaScreenCastStream *stream = meta_screen_cast_stream_src_get_stream (src);
- MetaBackend *backend = get_backend (area_src);
- MetaCursorTracker *cursor_tracker = meta_backend_get_cursor_tracker (backend);
- ClutterStage *stage;
- MetaStage *meta_stage;
- GList *l;
-
- stage = get_stage (area_src);
- meta_stage = META_STAGE (stage);
-
- for (l = area_src->watches; l; l = l->next)
- {
- MetaStageWatch *watch = l->data;
-
- meta_stage_remove_watch (meta_stage, watch);
- }
- g_clear_pointer (&area_src->watches, g_list_free);
-
- if (area_src->hw_cursor_inhibited)
- uninhibit_hw_cursor (area_src);
-
- g_clear_signal_handler (&area_src->position_invalidated_handler_id,
- cursor_tracker);
- g_clear_signal_handler (&area_src->cursor_changed_handler_id,
- cursor_tracker);
-
- g_clear_handle_id (&area_src->maybe_record_idle_id, g_source_remove);
-
- switch (meta_screen_cast_stream_get_cursor_mode (stream))
- {
- case META_SCREEN_CAST_CURSOR_MODE_METADATA:
- case META_SCREEN_CAST_CURSOR_MODE_EMBEDDED:
- meta_cursor_tracker_untrack_position (cursor_tracker);
- break;
- case META_SCREEN_CAST_CURSOR_MODE_HIDDEN:
- break;
- }
-}
-
-static gboolean
-meta_screen_cast_area_stream_src_record_to_buffer (MetaScreenCastStreamSrc *src,
- int width,
- int height,
- int stride,
- uint8_t *data,
- GError **error)
-{
- MetaScreenCastAreaStreamSrc *area_src =
- META_SCREEN_CAST_AREA_STREAM_SRC (src);
- MetaScreenCastStream *stream = meta_screen_cast_stream_src_get_stream (src);
- MetaScreenCastAreaStream *area_stream = META_SCREEN_CAST_AREA_STREAM (stream);
- ClutterStage *stage;
- MetaRectangle *area;
- float scale;
- ClutterPaintFlag paint_flags = CLUTTER_PAINT_FLAG_CLEAR;
-
- stage = get_stage (area_src);
- area = meta_screen_cast_area_stream_get_area (area_stream);
- scale = meta_screen_cast_area_stream_get_scale (area_stream);
-
- switch (meta_screen_cast_stream_get_cursor_mode (stream))
- {
- case META_SCREEN_CAST_CURSOR_MODE_METADATA:
- case META_SCREEN_CAST_CURSOR_MODE_HIDDEN:
- paint_flags |= CLUTTER_PAINT_FLAG_NO_CURSORS;
- break;
- case META_SCREEN_CAST_CURSOR_MODE_EMBEDDED:
- paint_flags |= CLUTTER_PAINT_FLAG_FORCE_CURSORS;
- break;
- }
-
- if (!clutter_stage_paint_to_buffer (stage, area, scale,
- data,
- stride,
- CLUTTER_CAIRO_FORMAT_ARGB32,
- paint_flags,
- error))
- return FALSE;
-
- return TRUE;
-}
-
-static gboolean
-meta_screen_cast_area_stream_src_record_to_framebuffer (MetaScreenCastStreamSrc *src,
- CoglFramebuffer *framebuffer,
- GError **error)
-{
- MetaScreenCastAreaStreamSrc *area_src =
- META_SCREEN_CAST_AREA_STREAM_SRC (src);
- MetaScreenCastStream *stream = meta_screen_cast_stream_src_get_stream (src);
- MetaScreenCastAreaStream *area_stream = META_SCREEN_CAST_AREA_STREAM (stream);
- MetaBackend *backend = get_backend (area_src);
- ClutterStage *stage;
- MetaRectangle *area;
- float scale;
- ClutterPaintFlag paint_flags = CLUTTER_PAINT_FLAG_CLEAR;
-
- stage = CLUTTER_STAGE (meta_backend_get_stage (backend));
- area = meta_screen_cast_area_stream_get_area (area_stream);
- scale = meta_screen_cast_area_stream_get_scale (area_stream);
-
- switch (meta_screen_cast_stream_get_cursor_mode (stream))
- {
- case META_SCREEN_CAST_CURSOR_MODE_METADATA:
- case META_SCREEN_CAST_CURSOR_MODE_HIDDEN:
- paint_flags |= CLUTTER_PAINT_FLAG_NO_CURSORS;
- break;
- case META_SCREEN_CAST_CURSOR_MODE_EMBEDDED:
- paint_flags |= CLUTTER_PAINT_FLAG_FORCE_CURSORS;
- break;
- }
- clutter_stage_paint_to_framebuffer (stage, framebuffer,
- area, scale,
- paint_flags);
-
- cogl_framebuffer_flush (framebuffer);
-
- return TRUE;
-}
-
-static void
-meta_screen_cast_area_stream_record_follow_up (MetaScreenCastStreamSrc *src)
-{
- MetaScreenCastAreaStreamSrc *area_src =
- META_SCREEN_CAST_AREA_STREAM_SRC (src);
- MetaScreenCastRecordFlag flags;
-
- g_clear_handle_id (&area_src->maybe_record_idle_id, g_source_remove);
-
- flags = META_SCREEN_CAST_RECORD_FLAG_NONE;
- meta_screen_cast_stream_src_maybe_record_frame (src, flags);
-}
-
-static void
-meta_screen_cast_area_stream_src_set_cursor_metadata (MetaScreenCastStreamSrc *src,
- struct spa_meta_cursor *spa_meta_cursor)
-{
- MetaScreenCastAreaStreamSrc *area_src =
- META_SCREEN_CAST_AREA_STREAM_SRC (src);
- MetaScreenCastStream *stream = meta_screen_cast_stream_src_get_stream (src);
- MetaScreenCastAreaStream *area_stream = META_SCREEN_CAST_AREA_STREAM (stream);
- MetaBackend *backend = get_backend (area_src);
- MetaCursorRenderer *cursor_renderer =
- meta_backend_get_cursor_renderer (backend);
- MetaCursorTracker *cursor_tracker =
- meta_backend_get_cursor_tracker (backend);
- MetaCursorSprite *cursor_sprite;
- MetaRectangle *area;
- float scale;
- graphene_point_t cursor_position;
- int x, y;
-
- cursor_sprite = meta_cursor_renderer_get_cursor (cursor_renderer);
-
- if (!meta_cursor_tracker_get_pointer_visible (cursor_tracker) ||
- !is_cursor_in_stream (area_src))
- {
- meta_screen_cast_stream_src_unset_cursor_metadata (src,
- spa_meta_cursor);
- return;
- }
-
- area = meta_screen_cast_area_stream_get_area (area_stream);
- scale = meta_screen_cast_area_stream_get_scale (area_stream);
-
- meta_cursor_tracker_get_pointer (cursor_tracker, &cursor_position, NULL);
- cursor_position.x -= area->x;
- cursor_position.y -= area->y;
- cursor_position.x *= scale;
- cursor_position.y *= scale;
-
- x = (int) roundf (cursor_position.x);
- y = (int) roundf (cursor_position.y);
-
- if (area_src->cursor_bitmap_invalid)
- {
- if (cursor_sprite)
- {
- float cursor_scale;
- float metadata_scale;
-
- cursor_scale = meta_cursor_sprite_get_texture_scale (cursor_sprite);
- metadata_scale = scale * cursor_scale;
- meta_screen_cast_stream_src_set_cursor_sprite_metadata (src,
- spa_meta_cursor,
- cursor_sprite,
- x, y,
- metadata_scale);
- }
- else
- {
- meta_screen_cast_stream_src_set_empty_cursor_sprite_metadata (src,
- spa_meta_cursor,
- x, y);
- }
-
- area_src->cursor_bitmap_invalid = FALSE;
- }
- else
- {
- meta_screen_cast_stream_src_set_cursor_position_metadata (src,
- spa_meta_cursor,
- x, y);
- }
-}
-
-static gboolean
-meta_screen_cast_area_stream_src_is_cursor_inhibited (MetaHwCursorInhibitor *inhibitor)
-{
- MetaScreenCastAreaStreamSrc *area_src =
- META_SCREEN_CAST_AREA_STREAM_SRC (inhibitor);
-
- return is_cursor_in_stream (area_src);
-}
-
-static void
-hw_cursor_inhibitor_iface_init (MetaHwCursorInhibitorInterface *iface)
-{
- iface->is_cursor_inhibited =
- meta_screen_cast_area_stream_src_is_cursor_inhibited;
-}
-
-MetaScreenCastAreaStreamSrc *
-meta_screen_cast_area_stream_src_new (MetaScreenCastAreaStream *area_stream,
- GError **error)
-{
- return g_initable_new (META_TYPE_SCREEN_CAST_AREA_STREAM_SRC, NULL, error,
- "stream", area_stream,
- NULL);
-}
-
-static void
-meta_screen_cast_area_stream_src_init (MetaScreenCastAreaStreamSrc *area_src)
-{
- area_src->cursor_bitmap_invalid = TRUE;
-}
-
-static void
-meta_screen_cast_area_stream_src_class_init (MetaScreenCastAreaStreamSrcClass *klass)
-{
- MetaScreenCastStreamSrcClass *src_class =
- META_SCREEN_CAST_STREAM_SRC_CLASS (klass);
-
- src_class->get_specs = meta_screen_cast_area_stream_src_get_specs;
- src_class->enable = meta_screen_cast_area_stream_src_enable;
- src_class->disable = meta_screen_cast_area_stream_src_disable;
- src_class->record_to_buffer =
- meta_screen_cast_area_stream_src_record_to_buffer;
- src_class->record_to_framebuffer =
- meta_screen_cast_area_stream_src_record_to_framebuffer;
- src_class->record_follow_up =
- meta_screen_cast_area_stream_record_follow_up;
- src_class->set_cursor_metadata =
- meta_screen_cast_area_stream_src_set_cursor_metadata;
-}
diff --git a/src/backends/meta-screen-cast-area-stream-src.h b/src/backends/meta-screen-cast-area-stream-src.h
deleted file mode 100644
index 72261642c..000000000
--- a/src/backends/meta-screen-cast-area-stream-src.h
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Copyright (C) 2020 Red Hat Inc.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- */
-
-#ifndef META_SCREEN_CAST_AREA_STREAM_SRC_H
-#define META_SCREEN_CAST_AREA_STREAM_SRC_H
-
-#include "backends/meta-screen-cast-stream-src.h"
-
-typedef struct _MetaScreenCastAreaStream MetaScreenCastAreaStream;
-
-#define META_TYPE_SCREEN_CAST_AREA_STREAM_SRC (meta_screen_cast_area_stream_src_get_type ())
-G_DECLARE_FINAL_TYPE (MetaScreenCastAreaStreamSrc,
- meta_screen_cast_area_stream_src,
- META, SCREEN_CAST_AREA_STREAM_SRC,
- MetaScreenCastStreamSrc)
-
-MetaScreenCastAreaStreamSrc * meta_screen_cast_area_stream_src_new (MetaScreenCastAreaStream *area_stream,
- GError **error);
-
-#endif /* META_SCREEN_CAST_AREA_STREAM_SRC_H */
diff --git a/src/backends/meta-screen-cast-area-stream.c b/src/backends/meta-screen-cast-area-stream.c
deleted file mode 100644
index 23d8c9828..000000000
--- a/src/backends/meta-screen-cast-area-stream.c
+++ /dev/null
@@ -1,181 +0,0 @@
-/*
- * Copyright (C) 2020 Red Hat Inc.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- */
-
-#include "config.h"
-
-#include "backends/meta-screen-cast-area-stream.h"
-
-#include "backends/meta-screen-cast-area-stream-src.h"
-
-struct _MetaScreenCastAreaStream
-{
- MetaScreenCastStream parent;
-
- ClutterStage *stage;
-
- MetaRectangle area;
- float scale;
-};
-
-G_DEFINE_TYPE (MetaScreenCastAreaStream,
- meta_screen_cast_area_stream,
- META_TYPE_SCREEN_CAST_STREAM)
-
-ClutterStage *
-meta_screen_cast_area_stream_get_stage (MetaScreenCastAreaStream *area_stream)
-{
- return area_stream->stage;
-}
-
-MetaRectangle *
-meta_screen_cast_area_stream_get_area (MetaScreenCastAreaStream *area_stream)
-{
- return &area_stream->area;
-}
-
-float
-meta_screen_cast_area_stream_get_scale (MetaScreenCastAreaStream *area_stream)
-{
- return area_stream->scale;
-}
-
-static gboolean
-calculate_scale (ClutterStage *stage,
- MetaRectangle *area,
- float *out_scale)
-{
- GList *l;
- float scale = 0.0;
-
- for (l = clutter_stage_peek_stage_views (stage); l; l = l->next)
- {
- ClutterStageView *stage_view = l->data;
- MetaRectangle view_layout;
-
- clutter_stage_view_get_layout (stage_view, &view_layout);
- if (meta_rectangle_overlap (area, &view_layout))
- scale = MAX (clutter_stage_view_get_scale (stage_view), scale);
- }
-
- if (scale == 0.0)
- return FALSE;
-
- *out_scale = scale;
- return TRUE;
-}
-
-MetaScreenCastAreaStream *
-meta_screen_cast_area_stream_new (MetaScreenCastSession *session,
- GDBusConnection *connection,
- MetaRectangle *area,
- ClutterStage *stage,
- MetaScreenCastCursorMode cursor_mode,
- MetaScreenCastFlag flags,
- GError **error)
-{
- MetaScreenCastAreaStream *area_stream;
- float scale;
-
- if (!calculate_scale (stage, area, &scale))
- {
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- "Area is off-screen");
- return NULL;
- }
-
- area_stream = g_initable_new (META_TYPE_SCREEN_CAST_AREA_STREAM,
- NULL,
- error,
- "session", session,
- "connection", connection,
- "cursor-mode", cursor_mode,
- "flags", flags,
- NULL);
- if (!area_stream)
- return NULL;
-
- area_stream->area = *area;
- area_stream->scale = scale;
- area_stream->stage = stage;
-
- return area_stream;
-}
-
-static MetaScreenCastStreamSrc *
-meta_screen_cast_area_stream_create_src (MetaScreenCastStream *stream,
- GError **error)
-{
- MetaScreenCastAreaStream *area_stream =
- META_SCREEN_CAST_AREA_STREAM (stream);
- MetaScreenCastAreaStreamSrc *area_stream_src;
-
- area_stream_src = meta_screen_cast_area_stream_src_new (area_stream,
- error);
- if (!area_stream_src)
- return NULL;
-
- return META_SCREEN_CAST_STREAM_SRC (area_stream_src);
-}
-
-static void
-meta_screen_cast_area_stream_set_parameters (MetaScreenCastStream *stream,
- GVariantBuilder *parameters_builder)
-{
- MetaScreenCastAreaStream *area_stream =
- META_SCREEN_CAST_AREA_STREAM (stream);
-
- g_variant_builder_add (parameters_builder, "{sv}",
- "size",
- g_variant_new ("(ii)",
- area_stream->area.width,
- area_stream->area.height));
-}
-
-static gboolean
-meta_screen_cast_area_stream_transform_position (MetaScreenCastStream *stream,
- double stream_x,
- double stream_y,
- double *x,
- double *y)
-{
- MetaScreenCastAreaStream *area_stream =
- META_SCREEN_CAST_AREA_STREAM (stream);
-
- *x = area_stream->area.x + (int) roundf (stream_x / area_stream->scale);
- *y = area_stream->area.y + (int) roundf (stream_y / area_stream->scale);
-
- return TRUE;
-}
-
-static void
-meta_screen_cast_area_stream_init (MetaScreenCastAreaStream *area_stream)
-{
-}
-
-static void
-meta_screen_cast_area_stream_class_init (MetaScreenCastAreaStreamClass *klass)
-{
- MetaScreenCastStreamClass *stream_class =
- META_SCREEN_CAST_STREAM_CLASS (klass);
-
- stream_class->create_src = meta_screen_cast_area_stream_create_src;
- stream_class->set_parameters = meta_screen_cast_area_stream_set_parameters;
- stream_class->transform_position = meta_screen_cast_area_stream_transform_position;
-}
diff --git a/src/backends/meta-screen-cast-area-stream.h b/src/backends/meta-screen-cast-area-stream.h
deleted file mode 100644
index b11ec1fb9..000000000
--- a/src/backends/meta-screen-cast-area-stream.h
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Copyright (C) 2020 Red Hat Inc.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- */
-
-#ifndef META_SCREEN_CAST_AREA_STREAM_H
-#define META_SCREEN_CAST_AREA_STREAM_H
-
-#include <glib-object.h>
-
-#include "backends/meta-screen-cast-stream.h"
-#include "backends/meta-screen-cast.h"
-
-#define META_TYPE_SCREEN_CAST_AREA_STREAM (meta_screen_cast_area_stream_get_type ())
-G_DECLARE_FINAL_TYPE (MetaScreenCastAreaStream,
- meta_screen_cast_area_stream,
- META, SCREEN_CAST_AREA_STREAM,
- MetaScreenCastStream)
-
-MetaScreenCastAreaStream * meta_screen_cast_area_stream_new (MetaScreenCastSession *session,
- GDBusConnection *connection,
- MetaRectangle *area,
- ClutterStage *stage,
- MetaScreenCastCursorMode cursor_mode,
- MetaScreenCastFlag flags,
- GError **error);
-
-ClutterStage * meta_screen_cast_area_stream_get_stage (MetaScreenCastAreaStream *area_stream);
-
-MetaRectangle * meta_screen_cast_area_stream_get_area (MetaScreenCastAreaStream *area_stream);
-
-float meta_screen_cast_area_stream_get_scale (MetaScreenCastAreaStream *area_stream);
-
-#endif /* META_SCREEN_CAST_AREA_STREAM_H */
diff --git a/src/backends/meta-screen-cast-monitor-stream-src.c b/src/backends/meta-screen-cast-monitor-stream-src.c
deleted file mode 100644
index b85c44fe1..000000000
--- a/src/backends/meta-screen-cast-monitor-stream-src.c
+++ /dev/null
@@ -1,793 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2017 Red Hat Inc.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- */
-
-#include "config.h"
-
-#include "backends/meta-screen-cast-monitor-stream-src.h"
-
-#include <spa/buffer/meta.h>
-
-#include "backends/meta-backend-private.h"
-#include "backends/meta-cursor-tracker-private.h"
-#include "backends/meta-logical-monitor.h"
-#include "backends/meta-monitor.h"
-#include "backends/meta-screen-cast-monitor-stream.h"
-#include "backends/meta-screen-cast-session.h"
-#include "backends/meta-stage-private.h"
-#include "clutter/clutter.h"
-#include "clutter/clutter-mutter.h"
-#include "core/boxes-private.h"
-
-struct _MetaScreenCastMonitorStreamSrc
-{
- MetaScreenCastStreamSrc parent;
-
- gboolean cursor_bitmap_invalid;
- gboolean hw_cursor_inhibited;
-
- GList *watches;
-
- gulong position_invalidated_handler_id;
- gulong cursor_changed_handler_id;
-};
-
-static void
-hw_cursor_inhibitor_iface_init (MetaHwCursorInhibitorInterface *iface);
-
-G_DEFINE_TYPE_WITH_CODE (MetaScreenCastMonitorStreamSrc,
- meta_screen_cast_monitor_stream_src,
- META_TYPE_SCREEN_CAST_STREAM_SRC,
- G_IMPLEMENT_INTERFACE (META_TYPE_HW_CURSOR_INHIBITOR,
- hw_cursor_inhibitor_iface_init))
-
-static ClutterStage *
-get_stage (MetaScreenCastMonitorStreamSrc *monitor_src)
-{
- MetaScreenCastStreamSrc *src;
- MetaScreenCastStream *stream;
- MetaScreenCastMonitorStream *monitor_stream;
-
- src = META_SCREEN_CAST_STREAM_SRC (monitor_src);
- stream = meta_screen_cast_stream_src_get_stream (src);
- monitor_stream = META_SCREEN_CAST_MONITOR_STREAM (stream);
-
- return meta_screen_cast_monitor_stream_get_stage (monitor_stream);
-}
-
-static MetaMonitor *
-get_monitor (MetaScreenCastMonitorStreamSrc *monitor_src)
-{
- MetaScreenCastStreamSrc *src;
- MetaScreenCastStream *stream;
- MetaScreenCastMonitorStream *monitor_stream;
-
- src = META_SCREEN_CAST_STREAM_SRC (monitor_src);
- stream = meta_screen_cast_stream_src_get_stream (src);
- monitor_stream = META_SCREEN_CAST_MONITOR_STREAM (stream);
-
- return meta_screen_cast_monitor_stream_get_monitor (monitor_stream);
-}
-
-static gboolean
-meta_screen_cast_monitor_stream_src_get_specs (MetaScreenCastStreamSrc *src,
- int *width,
- int *height,
- float *frame_rate)
-{
- MetaScreenCastMonitorStreamSrc *monitor_src =
- META_SCREEN_CAST_MONITOR_STREAM_SRC (src);
- MetaMonitor *monitor;
- MetaLogicalMonitor *logical_monitor;
- float scale;
- MetaMonitorMode *mode;
-
- monitor = get_monitor (monitor_src);
- logical_monitor = meta_monitor_get_logical_monitor (monitor);
- mode = meta_monitor_get_current_mode (monitor);
-
- if (meta_is_stage_views_scaled ())
- scale = logical_monitor->scale;
- else
- scale = 1.0;
-
- *width = (int) roundf (logical_monitor->rect.width * scale);
- *height = (int) roundf (logical_monitor->rect.height * scale);
- *frame_rate = meta_monitor_mode_get_refresh_rate (mode);
-
- return TRUE;
-}
-
-static void
-stage_painted (MetaStage *stage,
- ClutterStageView *view,
- ClutterPaintContext *paint_context,
- gpointer user_data)
-{
- MetaScreenCastStreamSrc *src = META_SCREEN_CAST_STREAM_SRC (user_data);
- MetaScreenCastRecordFlag flags;
-
- flags = META_SCREEN_CAST_RECORD_FLAG_NONE;
- meta_screen_cast_stream_src_maybe_record_frame (src, flags);
-}
-
-static void
-before_stage_painted (MetaStage *stage,
- ClutterStageView *view,
- ClutterPaintContext *paint_context,
- gpointer user_data)
-{
- MetaScreenCastStreamSrc *src = META_SCREEN_CAST_STREAM_SRC (user_data);
- CoglScanout *scanout;
-
- scanout = clutter_stage_view_peek_scanout (view);
- if (scanout)
- {
- MetaScreenCastRecordFlag flags;
-
- flags = META_SCREEN_CAST_RECORD_FLAG_NONE;
- meta_screen_cast_stream_src_maybe_record_frame (src, flags);
- }
-}
-
-static MetaBackend *
-get_backend (MetaScreenCastMonitorStreamSrc *monitor_src)
-{
- MetaScreenCastStreamSrc *src = META_SCREEN_CAST_STREAM_SRC (monitor_src);
- MetaScreenCastStream *stream = meta_screen_cast_stream_src_get_stream (src);
- MetaScreenCastSession *session = meta_screen_cast_stream_get_session (stream);
- MetaScreenCast *screen_cast =
- meta_screen_cast_session_get_screen_cast (session);
-
- return meta_screen_cast_get_backend (screen_cast);
-}
-
-static gboolean
-is_cursor_in_stream (MetaScreenCastMonitorStreamSrc *monitor_src)
-{
- MetaBackend *backend = get_backend (monitor_src);
- MetaCursorRenderer *cursor_renderer =
- meta_backend_get_cursor_renderer (backend);
- MetaMonitor *monitor;
- MetaLogicalMonitor *logical_monitor;
- MetaRectangle logical_monitor_layout;
- graphene_rect_t logical_monitor_rect;
- MetaCursorSprite *cursor_sprite;
-
- monitor = get_monitor (monitor_src);
- logical_monitor = meta_monitor_get_logical_monitor (monitor);
- logical_monitor_layout = meta_logical_monitor_get_layout (logical_monitor);
- logical_monitor_rect =
- meta_rectangle_to_graphene_rect (&logical_monitor_layout);
-
- cursor_sprite = meta_cursor_renderer_get_cursor (cursor_renderer);
- if (cursor_sprite)
- {
- graphene_rect_t cursor_rect;
-
- cursor_rect = meta_cursor_renderer_calculate_rect (cursor_renderer,
- cursor_sprite);
- return graphene_rect_intersection (&cursor_rect,
- &logical_monitor_rect,
- NULL);
- }
- else
- {
- MetaCursorTracker *cursor_tracker =
- meta_backend_get_cursor_tracker (backend);
- graphene_point_t cursor_position;
-
- meta_cursor_tracker_get_pointer (cursor_tracker, &cursor_position, NULL);
- return graphene_rect_contains_point (&logical_monitor_rect,
- &cursor_position);
- }
-}
-
-static gboolean
-is_redraw_queued (MetaScreenCastMonitorStreamSrc *monitor_src)
-{
- MetaBackend *backend = get_backend (monitor_src);
- MetaRenderer *renderer = meta_backend_get_renderer (backend);
- ClutterStage *stage = get_stage (monitor_src);
- MetaMonitor *monitor = get_monitor (monitor_src);
- g_autoptr (GList) views = NULL;
- GList *l;
-
- views = meta_renderer_get_views_for_monitor (renderer, monitor);
- for (l = views; l; l = l->next)
- {
- MetaRendererView *view = l->data;
-
- if (clutter_stage_is_redraw_queued_on_view (stage, CLUTTER_STAGE_VIEW (view)))
- return TRUE;
- }
-
- return FALSE;
-}
-
-static void
-sync_cursor_state (MetaScreenCastMonitorStreamSrc *monitor_src)
-{
- MetaScreenCastStreamSrc *src = META_SCREEN_CAST_STREAM_SRC (monitor_src);
- MetaScreenCastRecordFlag flags;
-
- if (is_redraw_queued (monitor_src))
- return;
-
- if (meta_screen_cast_stream_src_pending_follow_up_frame (src))
- return;
-
- flags = META_SCREEN_CAST_RECORD_FLAG_CURSOR_ONLY;
- meta_screen_cast_stream_src_maybe_record_frame (src, flags);
-}
-
-static void
-pointer_position_invalidated (MetaCursorTracker *cursor_tracker,
- MetaScreenCastMonitorStreamSrc *monitor_src)
-{
- sync_cursor_state (monitor_src);
-}
-
-static void
-cursor_changed (MetaCursorTracker *cursor_tracker,
- MetaScreenCastMonitorStreamSrc *monitor_src)
-{
- monitor_src->cursor_bitmap_invalid = TRUE;
- sync_cursor_state (monitor_src);
-}
-
-static void
-inhibit_hw_cursor (MetaScreenCastMonitorStreamSrc *monitor_src)
-{
- MetaHwCursorInhibitor *inhibitor;
- MetaBackend *backend;
-
- g_return_if_fail (!monitor_src->hw_cursor_inhibited);
-
- backend = get_backend (monitor_src);
- inhibitor = META_HW_CURSOR_INHIBITOR (monitor_src);
- meta_backend_add_hw_cursor_inhibitor (backend, inhibitor);
-
- monitor_src->hw_cursor_inhibited = TRUE;
-}
-
-static void
-uninhibit_hw_cursor (MetaScreenCastMonitorStreamSrc *monitor_src)
-{
- MetaHwCursorInhibitor *inhibitor;
- MetaBackend *backend;
-
- g_return_if_fail (monitor_src->hw_cursor_inhibited);
-
- backend = get_backend (monitor_src);
- inhibitor = META_HW_CURSOR_INHIBITOR (monitor_src);
- meta_backend_remove_hw_cursor_inhibitor (backend, inhibitor);
-
- monitor_src->hw_cursor_inhibited = FALSE;
-}
-
-static void
-add_view_watches (MetaScreenCastMonitorStreamSrc *monitor_src,
- MetaStageWatchPhase watch_phase,
- MetaStageWatchFunc callback)
-{
- MetaBackend *backend = get_backend (monitor_src);
- MetaRenderer *renderer = meta_backend_get_renderer (backend);
- ClutterStage *stage;
- MetaStage *meta_stage;
- MetaMonitor *monitor;
- MetaLogicalMonitor *logical_monitor;
- MetaRectangle logical_monitor_layout;
- GList *l;
-
- stage = get_stage (monitor_src);
- meta_stage = META_STAGE (stage);
- monitor = get_monitor (monitor_src);
- logical_monitor = meta_monitor_get_logical_monitor (monitor);
- logical_monitor_layout = meta_logical_monitor_get_layout (logical_monitor);
-
- for (l = meta_renderer_get_views (renderer); l; l = l->next)
- {
- MetaRendererView *view = l->data;
- MetaRectangle view_layout;
-
- clutter_stage_view_get_layout (CLUTTER_STAGE_VIEW (view), &view_layout);
- if (meta_rectangle_overlap (&logical_monitor_layout, &view_layout))
- {
- MetaStageWatch *watch;
-
- watch = meta_stage_watch_view (meta_stage,
- CLUTTER_STAGE_VIEW (view),
- watch_phase,
- callback,
- monitor_src);
-
- monitor_src->watches = g_list_prepend (monitor_src->watches, watch);
- }
- }
-}
-
-static void
-reattach_watches (MetaScreenCastMonitorStreamSrc *monitor_src)
-{
- MetaScreenCastStreamSrc *src = META_SCREEN_CAST_STREAM_SRC (monitor_src);
- MetaScreenCastStream *stream;
- ClutterStage *stage;
- GList *l;
-
- stream = meta_screen_cast_stream_src_get_stream (src);
- stage = get_stage (monitor_src);
-
- for (l = monitor_src->watches; l; l = l->next)
- meta_stage_remove_watch (META_STAGE (stage), l->data);
- g_clear_pointer (&monitor_src->watches, g_list_free);
-
- switch (meta_screen_cast_stream_get_cursor_mode (stream))
- {
- case META_SCREEN_CAST_CURSOR_MODE_METADATA:
- case META_SCREEN_CAST_CURSOR_MODE_HIDDEN:
- add_view_watches (monitor_src,
- META_STAGE_WATCH_BEFORE_PAINT,
- before_stage_painted);
- add_view_watches (monitor_src,
- META_STAGE_WATCH_AFTER_ACTOR_PAINT,
- stage_painted);
- break;
- case META_SCREEN_CAST_CURSOR_MODE_EMBEDDED:
- add_view_watches (monitor_src,
- META_STAGE_WATCH_AFTER_PAINT,
- stage_painted);
- break;
- }
-}
-
-static void
-on_monitors_changed (MetaMonitorManager *monitor_manager,
- MetaScreenCastMonitorStreamSrc *monitor_src)
-{
- reattach_watches (monitor_src);
-}
-
-static void
-meta_screen_cast_monitor_stream_src_enable (MetaScreenCastStreamSrc *src)
-{
- MetaScreenCastMonitorStreamSrc *monitor_src =
- META_SCREEN_CAST_MONITOR_STREAM_SRC (src);
- MetaBackend *backend = get_backend (monitor_src);
- MetaMonitorManager *monitor_manager =
- meta_backend_get_monitor_manager (backend);
- MetaCursorTracker *cursor_tracker = meta_backend_get_cursor_tracker (backend);
- MetaScreenCastStream *stream;
-
- stream = meta_screen_cast_stream_src_get_stream (src);
-
- switch (meta_screen_cast_stream_get_cursor_mode (stream))
- {
- case META_SCREEN_CAST_CURSOR_MODE_METADATA:
- monitor_src->position_invalidated_handler_id =
- g_signal_connect_after (cursor_tracker, "position-invalidated",
- G_CALLBACK (pointer_position_invalidated),
- monitor_src);
- monitor_src->cursor_changed_handler_id =
- g_signal_connect_after (cursor_tracker, "cursor-changed",
- G_CALLBACK (cursor_changed),
- monitor_src);
- meta_cursor_tracker_track_position (cursor_tracker);
- break;
- case META_SCREEN_CAST_CURSOR_MODE_HIDDEN:
- break;
- case META_SCREEN_CAST_CURSOR_MODE_EMBEDDED:
- inhibit_hw_cursor (monitor_src);
- meta_cursor_tracker_track_position (cursor_tracker);
- break;
- }
-
- reattach_watches (monitor_src);
- g_signal_connect_object (monitor_manager, "monitors-changed-internal",
- G_CALLBACK (on_monitors_changed),
- monitor_src, 0);
-
- clutter_actor_queue_redraw (CLUTTER_ACTOR (get_stage (monitor_src)));
-}
-
-static void
-meta_screen_cast_monitor_stream_src_disable (MetaScreenCastStreamSrc *src)
-{
- MetaScreenCastMonitorStreamSrc *monitor_src =
- META_SCREEN_CAST_MONITOR_STREAM_SRC (src);
- MetaScreenCastStream *stream = meta_screen_cast_stream_src_get_stream (src);
- MetaBackend *backend = get_backend (monitor_src);
- MetaCursorTracker *cursor_tracker = meta_backend_get_cursor_tracker (backend);
- ClutterStage *stage;
- MetaStage *meta_stage;
- GList *l;
-
- stage = get_stage (monitor_src);
- meta_stage = META_STAGE (stage);
-
- for (l = monitor_src->watches; l; l = l->next)
- {
- MetaStageWatch *watch = l->data;
-
- meta_stage_remove_watch (meta_stage, watch);
- }
- g_clear_pointer (&monitor_src->watches, g_list_free);
-
- if (monitor_src->hw_cursor_inhibited)
- uninhibit_hw_cursor (monitor_src);
-
- g_clear_signal_handler (&monitor_src->position_invalidated_handler_id,
- cursor_tracker);
- g_clear_signal_handler (&monitor_src->cursor_changed_handler_id,
- cursor_tracker);
-
- switch (meta_screen_cast_stream_get_cursor_mode (stream))
- {
- case META_SCREEN_CAST_CURSOR_MODE_METADATA:
- case META_SCREEN_CAST_CURSOR_MODE_EMBEDDED:
- meta_cursor_tracker_untrack_position (cursor_tracker);
- break;
- case META_SCREEN_CAST_CURSOR_MODE_HIDDEN:
- break;
- }
-}
-
-static void
-maybe_paint_cursor_sprite (MetaScreenCastMonitorStreamSrc *monitor_src,
- int width,
- int height,
- int stride,
- uint8_t *data)
-{
- MetaBackend *backend = get_backend (monitor_src);
- MetaCursorRenderer *cursor_renderer =
- meta_backend_get_cursor_renderer (backend);
- MetaCursorSprite *cursor_sprite;
- CoglTexture *sprite_texture;
- int sprite_width, sprite_height, sprite_stride;
- float sprite_scale;
- uint8_t *sprite_data;
- cairo_surface_t *sprite_surface;
- graphene_rect_t sprite_rect;
- cairo_surface_t *surface;
- cairo_t *cr;
-
- if (!is_cursor_in_stream (monitor_src))
- return;
-
- cursor_sprite = meta_cursor_renderer_get_cursor (cursor_renderer);
- if (!cursor_sprite)
- return;
-
- if (meta_cursor_renderer_is_overlay_visible (cursor_renderer))
- return;
-
- sprite_rect = meta_cursor_renderer_calculate_rect (cursor_renderer,
- cursor_sprite);
- sprite_texture = meta_cursor_sprite_get_cogl_texture (cursor_sprite);
- sprite_width = cogl_texture_get_width (sprite_texture);
- sprite_height = cogl_texture_get_height (sprite_texture);
- sprite_stride = sprite_width * 4;
- sprite_scale = meta_cursor_sprite_get_texture_scale (cursor_sprite);
- sprite_data = g_new0 (uint8_t, sprite_stride * sprite_height);
- cogl_texture_get_data (sprite_texture,
- CLUTTER_CAIRO_FORMAT_ARGB32,
- sprite_stride,
- sprite_data);
- sprite_surface = cairo_image_surface_create_for_data (sprite_data,
- CAIRO_FORMAT_ARGB32,
- sprite_width,
- sprite_height,
- sprite_stride);
- cairo_surface_set_device_scale (sprite_surface, sprite_scale, sprite_scale);
-
- surface = cairo_image_surface_create_for_data (data,
- CAIRO_FORMAT_ARGB32,
- width, height, stride);
-
- cr = cairo_create (surface);
- cairo_set_source_surface (cr, sprite_surface,
- sprite_rect.origin.x,
- sprite_rect.origin.y);
- cairo_paint (cr);
- cairo_destroy (cr);
- cairo_surface_destroy (sprite_surface);
- cairo_surface_destroy (surface);
- g_free (sprite_data);
-}
-
-static gboolean
-meta_screen_cast_monitor_stream_src_record_to_buffer (MetaScreenCastStreamSrc *src,
- int width,
- int height,
- int stride,
- uint8_t *data,
- GError **error)
-{
- MetaScreenCastMonitorStreamSrc *monitor_src =
- META_SCREEN_CAST_MONITOR_STREAM_SRC (src);
- MetaScreenCastStream *stream = meta_screen_cast_stream_src_get_stream (src);
- ClutterStage *stage;
- MetaMonitor *monitor;
- MetaLogicalMonitor *logical_monitor;
- float scale;
-
- monitor = get_monitor (monitor_src);
- logical_monitor = meta_monitor_get_logical_monitor (monitor);
- stage = get_stage (monitor_src);
-
- if (meta_is_stage_views_scaled ())
- scale = meta_logical_monitor_get_scale (logical_monitor);
- else
- scale = 1.0;
-
- clutter_stage_capture_into (stage, &logical_monitor->rect, scale, data, stride);
-
- switch (meta_screen_cast_stream_get_cursor_mode (stream))
- {
- case META_SCREEN_CAST_CURSOR_MODE_EMBEDDED:
- maybe_paint_cursor_sprite (monitor_src, width, height, stride, data);
- break;
- case META_SCREEN_CAST_CURSOR_MODE_METADATA:
- case META_SCREEN_CAST_CURSOR_MODE_HIDDEN:
- break;
- }
-
- return TRUE;
-}
-
-static gboolean
-meta_screen_cast_monitor_stream_src_record_to_framebuffer (MetaScreenCastStreamSrc *src,
- CoglFramebuffer *framebuffer,
- GError **error)
-{
- MetaScreenCastMonitorStreamSrc *monitor_src =
- META_SCREEN_CAST_MONITOR_STREAM_SRC (src);
- MetaBackend *backend = get_backend (monitor_src);
- MetaRenderer *renderer = meta_backend_get_renderer (backend);
- MetaMonitor *monitor;
- MetaLogicalMonitor *logical_monitor;
- MetaRectangle logical_monitor_layout;
- GList *l;
- float view_scale;
-
- monitor = get_monitor (monitor_src);
- logical_monitor = meta_monitor_get_logical_monitor (monitor);
- logical_monitor_layout = meta_logical_monitor_get_layout (logical_monitor);
-
- if (meta_is_stage_views_scaled ())
- view_scale = meta_logical_monitor_get_scale (logical_monitor);
- else
- view_scale = 1.0;
-
- for (l = meta_renderer_get_views (renderer); l; l = l->next)
- {
- ClutterStageView *view = CLUTTER_STAGE_VIEW (l->data);
- CoglFramebuffer *view_framebuffer;
- CoglScanout *scanout;
- MetaRectangle view_layout;
- int x, y;
-
- clutter_stage_view_get_layout (view, &view_layout);
-
- if (!meta_rectangle_overlap (&logical_monitor_layout, &view_layout))
- continue;
-
- x = (int) roundf ((view_layout.x - logical_monitor_layout.x) * view_scale);
- y = (int) roundf ((view_layout.y - logical_monitor_layout.y) * view_scale);
-
- scanout = clutter_stage_view_peek_scanout (view);
- if (scanout)
- {
- if (!cogl_scanout_blit_to_framebuffer (scanout,
- framebuffer,
- x, y,
- error))
- return FALSE;
- }
- else
- {
- view_framebuffer = clutter_stage_view_get_framebuffer (view);
- if (!cogl_blit_framebuffer (view_framebuffer,
- framebuffer,
- 0, 0,
- x, y,
- cogl_framebuffer_get_width (view_framebuffer),
- cogl_framebuffer_get_height (view_framebuffer),
- error))
- return FALSE;
- }
- }
-
- cogl_framebuffer_flush (framebuffer);
-
- return TRUE;
-}
-
-static void
-meta_screen_cast_monitor_stream_record_follow_up (MetaScreenCastStreamSrc *src)
-{
- MetaScreenCastMonitorStreamSrc *monitor_src =
- META_SCREEN_CAST_MONITOR_STREAM_SRC (src);
- MetaBackend *backend = get_backend (monitor_src);
- MetaRenderer *renderer = meta_backend_get_renderer (backend);
- ClutterStage *stage = get_stage (monitor_src);
- MetaMonitor *monitor;
- MetaLogicalMonitor *logical_monitor;
- MetaRectangle logical_monitor_layout;
- GList *l;
-
- monitor = get_monitor (monitor_src);
- logical_monitor = meta_monitor_get_logical_monitor (monitor);
- logical_monitor_layout = meta_logical_monitor_get_layout (logical_monitor);
-
- for (l = meta_renderer_get_views (renderer); l; l = l->next)
- {
- MetaRendererView *view = l->data;
- MetaRectangle view_layout;
- MetaRectangle damage;
-
- clutter_stage_view_get_layout (CLUTTER_STAGE_VIEW (view), &view_layout);
-
- if (!meta_rectangle_overlap (&logical_monitor_layout, &view_layout))
- continue;
-
- damage = (cairo_rectangle_int_t) {
- .x = view_layout.x,
- .y = view_layout.y,
- .width = 1,
- .height = 1,
- };
- clutter_actor_queue_redraw_with_clip (CLUTTER_ACTOR (stage), &damage);
- }
-}
-
-static void
-meta_screen_cast_monitor_stream_src_set_cursor_metadata (MetaScreenCastStreamSrc *src,
- struct spa_meta_cursor *spa_meta_cursor)
-{
- MetaScreenCastMonitorStreamSrc *monitor_src =
- META_SCREEN_CAST_MONITOR_STREAM_SRC (src);
- MetaBackend *backend = get_backend (monitor_src);
- MetaCursorRenderer *cursor_renderer =
- meta_backend_get_cursor_renderer (backend);
- MetaCursorTracker *cursor_tracker =
- meta_backend_get_cursor_tracker (backend);
- MetaCursorSprite *cursor_sprite;
- MetaMonitor *monitor;
- MetaLogicalMonitor *logical_monitor;
- MetaRectangle logical_monitor_layout;
- graphene_rect_t logical_monitor_rect;
- float view_scale;
- graphene_point_t cursor_position;
- int x, y;
-
- cursor_sprite = meta_cursor_renderer_get_cursor (cursor_renderer);
-
- if (!meta_cursor_tracker_get_pointer_visible (cursor_tracker) ||
- !is_cursor_in_stream (monitor_src))
- {
- meta_screen_cast_stream_src_unset_cursor_metadata (src,
- spa_meta_cursor);
- return;
- }
-
- monitor = get_monitor (monitor_src);
- logical_monitor = meta_monitor_get_logical_monitor (monitor);
- logical_monitor_layout = meta_logical_monitor_get_layout (logical_monitor);
- logical_monitor_rect =
- meta_rectangle_to_graphene_rect (&logical_monitor_layout);
-
- if (meta_is_stage_views_scaled ())
- view_scale = meta_logical_monitor_get_scale (logical_monitor);
- else
- view_scale = 1.0;
-
- meta_cursor_tracker_get_pointer (cursor_tracker, &cursor_position, NULL);
- cursor_position.x -= logical_monitor_rect.origin.x;
- cursor_position.y -= logical_monitor_rect.origin.y;
- cursor_position.x *= view_scale;
- cursor_position.y *= view_scale;
-
- x = (int) roundf (cursor_position.x);
- y = (int) roundf (cursor_position.y);
-
- if (monitor_src->cursor_bitmap_invalid)
- {
- if (cursor_sprite)
- {
- float cursor_scale;
- float scale;
-
- cursor_scale = meta_cursor_sprite_get_texture_scale (cursor_sprite);
- scale = view_scale * cursor_scale;
- meta_screen_cast_stream_src_set_cursor_sprite_metadata (src,
- spa_meta_cursor,
- cursor_sprite,
- x, y,
- scale);
- }
- else
- {
- meta_screen_cast_stream_src_set_empty_cursor_sprite_metadata (src,
- spa_meta_cursor,
- x, y);
- }
-
- monitor_src->cursor_bitmap_invalid = FALSE;
- }
- else
- {
- meta_screen_cast_stream_src_set_cursor_position_metadata (src,
- spa_meta_cursor,
- x, y);
- }
-}
-
-static gboolean
-meta_screen_cast_monitor_stream_src_is_cursor_inhibited (MetaHwCursorInhibitor *inhibitor)
-{
- MetaScreenCastMonitorStreamSrc *monitor_src =
- META_SCREEN_CAST_MONITOR_STREAM_SRC (inhibitor);
-
- return is_cursor_in_stream (monitor_src);
-}
-
-static void
-hw_cursor_inhibitor_iface_init (MetaHwCursorInhibitorInterface *iface)
-{
- iface->is_cursor_inhibited =
- meta_screen_cast_monitor_stream_src_is_cursor_inhibited;
-}
-
-MetaScreenCastMonitorStreamSrc *
-meta_screen_cast_monitor_stream_src_new (MetaScreenCastMonitorStream *monitor_stream,
- GError **error)
-{
- return g_initable_new (META_TYPE_SCREEN_CAST_MONITOR_STREAM_SRC, NULL, error,
- "stream", monitor_stream,
- NULL);
-}
-
-static void
-meta_screen_cast_monitor_stream_src_init (MetaScreenCastMonitorStreamSrc *monitor_src)
-{
- monitor_src->cursor_bitmap_invalid = TRUE;
-}
-
-static void
-meta_screen_cast_monitor_stream_src_class_init (MetaScreenCastMonitorStreamSrcClass *klass)
-{
- MetaScreenCastStreamSrcClass *src_class =
- META_SCREEN_CAST_STREAM_SRC_CLASS (klass);
-
- src_class->get_specs = meta_screen_cast_monitor_stream_src_get_specs;
- src_class->enable = meta_screen_cast_monitor_stream_src_enable;
- src_class->disable = meta_screen_cast_monitor_stream_src_disable;
- src_class->record_to_buffer =
- meta_screen_cast_monitor_stream_src_record_to_buffer;
- src_class->record_to_framebuffer =
- meta_screen_cast_monitor_stream_src_record_to_framebuffer;
- src_class->record_follow_up =
- meta_screen_cast_monitor_stream_record_follow_up;
- src_class->set_cursor_metadata =
- meta_screen_cast_monitor_stream_src_set_cursor_metadata;
-}
diff --git a/src/backends/meta-screen-cast-monitor-stream-src.h b/src/backends/meta-screen-cast-monitor-stream-src.h
deleted file mode 100644
index 7417a81e0..000000000
--- a/src/backends/meta-screen-cast-monitor-stream-src.h
+++ /dev/null
@@ -1,40 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2017 Red Hat Inc.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- */
-
-#ifndef META_SCREEN_CAST_MONITOR_STREAM_SRC_H
-#define META_SCREEN_CAST_MONITOR_STREAM_SRC_H
-
-#include "backends/meta-monitor-manager-private.h"
-#include "backends/meta-screen-cast-stream-src.h"
-
-typedef struct _MetaScreenCastMonitorStream MetaScreenCastMonitorStream;
-
-#define META_TYPE_SCREEN_CAST_MONITOR_STREAM_SRC (meta_screen_cast_monitor_stream_src_get_type ())
-G_DECLARE_FINAL_TYPE (MetaScreenCastMonitorStreamSrc,
- meta_screen_cast_monitor_stream_src,
- META, SCREEN_CAST_MONITOR_STREAM_SRC,
- MetaScreenCastStreamSrc)
-
-MetaScreenCastMonitorStreamSrc * meta_screen_cast_monitor_stream_src_new (MetaScreenCastMonitorStream *monitor_stream,
- GError **error);
-
-#endif /* META_SCREEN_CAST_MONITOR_STREAM_SRC_H */
diff --git a/src/backends/meta-screen-cast-monitor-stream.c b/src/backends/meta-screen-cast-monitor-stream.c
deleted file mode 100644
index ada9bc95f..000000000
--- a/src/backends/meta-screen-cast-monitor-stream.c
+++ /dev/null
@@ -1,295 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2017 Red Hat Inc.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- */
-
-#include "config.h"
-
-#include "backends/meta-screen-cast-monitor-stream.h"
-
-#include "backends/meta-logical-monitor.h"
-#include "backends/meta-screen-cast-monitor-stream-src.h"
-
-enum
-{
- PROP_0,
-
- PROP_MONITOR,
-};
-
-struct _MetaScreenCastMonitorStream
-{
- MetaScreenCastStream parent;
-
- ClutterStage *stage;
-
- MetaMonitor *monitor;
- MetaLogicalMonitor *logical_monitor;
-};
-
-G_DEFINE_TYPE (MetaScreenCastMonitorStream,
- meta_screen_cast_monitor_stream,
- META_TYPE_SCREEN_CAST_STREAM)
-
-static gboolean
-update_monitor (MetaScreenCastMonitorStream *monitor_stream,
- MetaMonitor *new_monitor)
-{
- MetaLogicalMonitor *new_logical_monitor;
-
- new_logical_monitor = meta_monitor_get_logical_monitor (new_monitor);
- if (!new_logical_monitor)
- return FALSE;
-
- if (!meta_rectangle_equal (&new_logical_monitor->rect,
- &monitor_stream->logical_monitor->rect))
- return FALSE;
-
- g_set_object (&monitor_stream->monitor, new_monitor);
- g_set_object (&monitor_stream->logical_monitor, new_logical_monitor);
-
- return TRUE;
-}
-
-static void
-on_monitors_changed (MetaMonitorManager *monitor_manager,
- MetaScreenCastMonitorStream *monitor_stream)
-{
- MetaMonitor *new_monitor = NULL;
- GList *monitors;
- GList *l;
-
- monitors = meta_monitor_manager_get_monitors (monitor_manager);
- for (l = monitors; l; l = l->next)
- {
- MetaMonitor *other_monitor = l->data;
-
- if (meta_monitor_is_same_as (monitor_stream->monitor, other_monitor))
- {
- new_monitor = other_monitor;
- break;
- }
- }
-
- if (!new_monitor || !update_monitor (monitor_stream, new_monitor))
- meta_screen_cast_stream_close (META_SCREEN_CAST_STREAM (monitor_stream));
-}
-
-ClutterStage *
-meta_screen_cast_monitor_stream_get_stage (MetaScreenCastMonitorStream *monitor_stream)
-{
- return monitor_stream->stage;
-}
-
-MetaMonitor *
-meta_screen_cast_monitor_stream_get_monitor (MetaScreenCastMonitorStream *monitor_stream)
-{
- return monitor_stream->monitor;
-}
-
-MetaScreenCastMonitorStream *
-meta_screen_cast_monitor_stream_new (MetaScreenCastSession *session,
- GDBusConnection *connection,
- MetaMonitor *monitor,
- ClutterStage *stage,
- MetaScreenCastCursorMode cursor_mode,
- MetaScreenCastFlag flags,
- GError **error)
-{
- MetaBackend *backend = meta_monitor_get_backend (monitor);
- MetaMonitorManager *monitor_manager =
- meta_backend_get_monitor_manager (backend);
- MetaScreenCastMonitorStream *monitor_stream;
-
- if (!meta_monitor_is_active (monitor))
- {
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Monitor not active");
- return NULL;
- }
-
- monitor_stream = g_initable_new (META_TYPE_SCREEN_CAST_MONITOR_STREAM,
- NULL,
- error,
- "session", session,
- "connection", connection,
- "cursor-mode", cursor_mode,
- "flags", flags,
- "monitor", monitor,
- NULL);
- if (!monitor_stream)
- return NULL;
-
- monitor_stream->stage = stage;
-
- g_signal_connect_object (monitor_manager, "monitors-changed-internal",
- G_CALLBACK (on_monitors_changed),
- monitor_stream, 0);
-
- return monitor_stream;
-}
-
-static MetaScreenCastStreamSrc *
-meta_screen_cast_monitor_stream_create_src (MetaScreenCastStream *stream,
- GError **error)
-{
- MetaScreenCastMonitorStream *monitor_stream =
- META_SCREEN_CAST_MONITOR_STREAM (stream);
- MetaScreenCastMonitorStreamSrc *monitor_stream_src;
-
- monitor_stream_src = meta_screen_cast_monitor_stream_src_new (monitor_stream,
- error);
- if (!monitor_stream_src)
- return NULL;
-
- return META_SCREEN_CAST_STREAM_SRC (monitor_stream_src);
-}
-
-static void
-meta_screen_cast_monitor_stream_set_parameters (MetaScreenCastStream *stream,
- GVariantBuilder *parameters_builder)
-{
- MetaScreenCastMonitorStream *monitor_stream =
- META_SCREEN_CAST_MONITOR_STREAM (stream);
- MetaRectangle logical_monitor_layout;
-
- logical_monitor_layout =
- meta_logical_monitor_get_layout (monitor_stream->logical_monitor);
-
- g_variant_builder_add (parameters_builder, "{sv}",
- "position",
- g_variant_new ("(ii)",
- logical_monitor_layout.x,
- logical_monitor_layout.y));
- g_variant_builder_add (parameters_builder, "{sv}",
- "size",
- g_variant_new ("(ii)",
- logical_monitor_layout.width,
- logical_monitor_layout.height));
-}
-
-static gboolean
-meta_screen_cast_monitor_stream_transform_position (MetaScreenCastStream *stream,
- double stream_x,
- double stream_y,
- double *x,
- double *y)
-{
- MetaScreenCastMonitorStream *monitor_stream =
- META_SCREEN_CAST_MONITOR_STREAM (stream);
- MetaRectangle logical_monitor_layout;
- double scale;
-
- logical_monitor_layout =
- meta_logical_monitor_get_layout (monitor_stream->logical_monitor);
-
- if (meta_is_stage_views_scaled ())
- scale = meta_logical_monitor_get_scale (monitor_stream->logical_monitor);
- else
- scale = 1.0;
-
- *x = logical_monitor_layout.x + stream_x / scale;
- *y = logical_monitor_layout.y + stream_y / scale;
-
- return TRUE;
-}
-
-static void
-meta_screen_cast_monitor_stream_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- MetaScreenCastMonitorStream *monitor_stream =
- META_SCREEN_CAST_MONITOR_STREAM (object);
- MetaLogicalMonitor *logical_monitor;
-
- switch (prop_id)
- {
- case PROP_MONITOR:
- g_set_object (&monitor_stream->monitor, g_value_get_object (value));
- logical_monitor = meta_monitor_get_logical_monitor (monitor_stream->monitor);
- g_set_object (&monitor_stream->logical_monitor, logical_monitor);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- }
-}
-
-static void
-meta_screen_cast_monitor_stream_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- MetaScreenCastMonitorStream *monitor_stream =
- META_SCREEN_CAST_MONITOR_STREAM (object);
-
- switch (prop_id)
- {
- case PROP_MONITOR:
- g_value_set_object (value, monitor_stream->monitor);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- }
-}
-
-static void
-meta_screen_cast_monitor_stream_finalize (GObject *object)
-{
- MetaScreenCastMonitorStream *monitor_stream =
- META_SCREEN_CAST_MONITOR_STREAM (object);
-
- g_clear_object (&monitor_stream->monitor);
- g_clear_object (&monitor_stream->logical_monitor);
-
- G_OBJECT_CLASS (meta_screen_cast_monitor_stream_parent_class)->finalize (object);
-}
-
-static void
-meta_screen_cast_monitor_stream_init (MetaScreenCastMonitorStream *monitor_stream)
-{
-}
-
-static void
-meta_screen_cast_monitor_stream_class_init (MetaScreenCastMonitorStreamClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
- MetaScreenCastStreamClass *stream_class =
- META_SCREEN_CAST_STREAM_CLASS (klass);
-
- object_class->set_property = meta_screen_cast_monitor_stream_set_property;
- object_class->get_property = meta_screen_cast_monitor_stream_get_property;
- object_class->finalize = meta_screen_cast_monitor_stream_finalize;
-
- stream_class->create_src = meta_screen_cast_monitor_stream_create_src;
- stream_class->set_parameters = meta_screen_cast_monitor_stream_set_parameters;
- stream_class->transform_position = meta_screen_cast_monitor_stream_transform_position;
-
- g_object_class_install_property (object_class,
- PROP_MONITOR,
- g_param_spec_object ("monitor",
- "monitor",
- "MetaMonitor",
- META_TYPE_MONITOR,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT_ONLY |
- G_PARAM_STATIC_STRINGS));
-}
diff --git a/src/backends/meta-screen-cast-monitor-stream.h b/src/backends/meta-screen-cast-monitor-stream.h
deleted file mode 100644
index 04c48e980..000000000
--- a/src/backends/meta-screen-cast-monitor-stream.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2017 Red Hat Inc.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- */
-
-#ifndef META_SCREEN_CAST_MONITOR_STREAM_H
-#define META_SCREEN_CAST_MONITOR_STREAM_H
-
-#include <glib-object.h>
-
-#include "backends/meta-monitor-manager-private.h"
-#include "backends/meta-screen-cast-stream.h"
-#include "backends/meta-screen-cast.h"
-
-#define META_TYPE_SCREEN_CAST_MONITOR_STREAM (meta_screen_cast_monitor_stream_get_type ())
-G_DECLARE_FINAL_TYPE (MetaScreenCastMonitorStream,
- meta_screen_cast_monitor_stream,
- META, SCREEN_CAST_MONITOR_STREAM,
- MetaScreenCastStream)
-
-MetaScreenCastMonitorStream * meta_screen_cast_monitor_stream_new (MetaScreenCastSession *session,
- GDBusConnection *connection,
- MetaMonitor *monitor,
- ClutterStage *stage,
- MetaScreenCastCursorMode cursor_mode,
- MetaScreenCastFlag flags,
- GError **error);
-
-ClutterStage * meta_screen_cast_monitor_stream_get_stage (MetaScreenCastMonitorStream *monitor_stream);
-
-MetaMonitor * meta_screen_cast_monitor_stream_get_monitor (MetaScreenCastMonitorStream *monitor_stream);
-
-#endif /* META_SCREEN_CAST_MONITOR_STREAM_H */
diff --git a/src/backends/meta-screen-cast-session.c b/src/backends/meta-screen-cast-session.c
deleted file mode 100644
index 60fffdea5..000000000
--- a/src/backends/meta-screen-cast-session.c
+++ /dev/null
@@ -1,825 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2015-2017 Red Hat Inc.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- */
-
-#include "config.h"
-
-#include "backends/meta-screen-cast-session.h"
-
-#include "backends/meta-backend-private.h"
-#include "backends/meta-dbus-session-watcher.h"
-#include "backends/meta-remote-access-controller-private.h"
-#include "backends/meta-screen-cast-area-stream.h"
-#include "backends/meta-screen-cast-monitor-stream.h"
-#include "backends/meta-screen-cast-stream.h"
-#include "backends/meta-screen-cast-virtual-stream.h"
-#include "backends/meta-screen-cast-window-stream.h"
-#include "core/display-private.h"
-
-#define META_SCREEN_CAST_SESSION_DBUS_PATH "/org/gnome/Mutter/ScreenCast/Session"
-
-struct _MetaScreenCastSession
-{
- MetaDBusScreenCastSessionSkeleton parent;
-
- MetaScreenCast *screen_cast;
-
- char *peer_name;
-
- MetaScreenCastSessionType session_type;
- char *object_path;
-
- GList *streams;
-
- MetaScreenCastSessionHandle *handle;
-
- gboolean disable_animations;
-};
-
-static void
-meta_screen_cast_session_init_iface (MetaDBusScreenCastSessionIface *iface);
-
-static void
-meta_dbus_session_init_iface (MetaDbusSessionInterface *iface);
-
-G_DEFINE_TYPE_WITH_CODE (MetaScreenCastSession,
- meta_screen_cast_session,
- META_DBUS_TYPE_SCREEN_CAST_SESSION_SKELETON,
- G_IMPLEMENT_INTERFACE (META_DBUS_TYPE_SCREEN_CAST_SESSION,
- meta_screen_cast_session_init_iface)
- G_IMPLEMENT_INTERFACE (META_TYPE_DBUS_SESSION,
- meta_dbus_session_init_iface))
-
-struct _MetaScreenCastSessionHandle
-{
- MetaRemoteAccessHandle parent;
-
- MetaScreenCastSession *session;
-};
-
-G_DEFINE_TYPE (MetaScreenCastSessionHandle,
- meta_screen_cast_session_handle,
- META_TYPE_REMOTE_ACCESS_HANDLE)
-
-static MetaScreenCastSessionHandle *
-meta_screen_cast_session_handle_new (MetaScreenCastSession *session);
-
-static void
-init_remote_access_handle (MetaScreenCastSession *session)
-{
- MetaBackend *backend = meta_get_backend ();
- MetaRemoteAccessController *remote_access_controller;
- MetaRemoteAccessHandle *remote_access_handle;
-
- session->handle = meta_screen_cast_session_handle_new (session);
-
- remote_access_controller = meta_backend_get_remote_access_controller (backend);
- remote_access_handle = META_REMOTE_ACCESS_HANDLE (session->handle);
-
- meta_remote_access_handle_set_disable_animations (remote_access_handle,
- session->disable_animations);
-
- meta_remote_access_controller_notify_new_handle (remote_access_controller,
- remote_access_handle);
-}
-
-gboolean
-meta_screen_cast_session_start (MetaScreenCastSession *session,
- GError **error)
-{
- GList *l;
-
- for (l = session->streams; l; l = l->next)
- {
- MetaScreenCastStream *stream = l->data;
-
- if (!meta_screen_cast_stream_start (stream, error))
- return FALSE;
- }
-
- init_remote_access_handle (session);
-
- return TRUE;
-}
-
-void
-meta_screen_cast_session_close (MetaScreenCastSession *session)
-{
- MetaDBusScreenCastSession *skeleton = META_DBUS_SCREEN_CAST_SESSION (session);
-
- g_list_free_full (session->streams, g_object_unref);
-
- meta_dbus_session_notify_closed (META_DBUS_SESSION (session));
-
- switch (session->session_type)
- {
- case META_SCREEN_CAST_SESSION_TYPE_NORMAL:
- meta_dbus_screen_cast_session_emit_closed (skeleton);
- break;
- case META_SCREEN_CAST_SESSION_TYPE_REMOTE_DESKTOP:
- break;
- }
-
- g_dbus_interface_skeleton_unexport (G_DBUS_INTERFACE_SKELETON (session));
-
- if (session->handle)
- {
- MetaRemoteAccessHandle *remote_access_handle =
- META_REMOTE_ACCESS_HANDLE (session->handle);
-
- meta_remote_access_handle_notify_stopped (remote_access_handle);
- }
-
- g_object_unref (session);
-}
-
-MetaScreenCastStream *
-meta_screen_cast_session_get_stream (MetaScreenCastSession *session,
- const char *path)
-{
- GList *l;
-
- for (l = session->streams; l; l = l->next)
- {
- MetaScreenCastStream *stream = l->data;
-
- if (g_strcmp0 (meta_screen_cast_stream_get_object_path (stream),
- path) == 0)
- return stream;
- }
-
- return NULL;
-}
-
-MetaScreenCast *
-meta_screen_cast_session_get_screen_cast (MetaScreenCastSession *session)
-{
- return session->screen_cast;
-}
-
-void
-meta_screen_cast_session_set_disable_animations (MetaScreenCastSession *session,
- gboolean disable_animations)
-{
- session->disable_animations = disable_animations;
-}
-
-char *
-meta_screen_cast_session_get_object_path (MetaScreenCastSession *session)
-{
- return session->object_path;
-}
-
-char *
-meta_screen_cast_session_get_peer_name (MetaScreenCastSession *session)
-{
- return session->peer_name;
-}
-
-MetaScreenCastSessionType
-meta_screen_cast_session_get_session_type (MetaScreenCastSession *session)
-{
- return session->session_type;
-}
-
-static gboolean
-check_permission (MetaScreenCastSession *session,
- GDBusMethodInvocation *invocation)
-{
- return g_strcmp0 (session->peer_name,
- g_dbus_method_invocation_get_sender (invocation)) == 0;
-}
-
-static gboolean
-handle_start (MetaDBusScreenCastSession *skeleton,
- GDBusMethodInvocation *invocation)
-{
- MetaScreenCastSession *session = META_SCREEN_CAST_SESSION (skeleton);
- GError *error = NULL;
-
- if (!check_permission (session, invocation))
- {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_ACCESS_DENIED,
- "Permission denied");
- return TRUE;
- }
-
- switch (session->session_type)
- {
- case META_SCREEN_CAST_SESSION_TYPE_NORMAL:
- break;
- case META_SCREEN_CAST_SESSION_TYPE_REMOTE_DESKTOP:
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_FAILED,
- "Must be started from remote desktop session");
- return TRUE;
- }
-
- if (!meta_screen_cast_session_start (session, &error))
- {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_FAILED,
- "Failed to start screen cast: %s",
- error->message);
- g_error_free (error);
-
- return TRUE;
- }
-
- meta_dbus_screen_cast_session_complete_start (skeleton, invocation);
-
- return TRUE;
-}
-
-static gboolean
-handle_stop (MetaDBusScreenCastSession *skeleton,
- GDBusMethodInvocation *invocation)
-{
- MetaScreenCastSession *session = META_SCREEN_CAST_SESSION (skeleton);
-
- if (!check_permission (session, invocation))
- {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_ACCESS_DENIED,
- "Permission denied");
- return TRUE;
- }
-
- switch (session->session_type)
- {
- case META_SCREEN_CAST_SESSION_TYPE_NORMAL:
- break;
- case META_SCREEN_CAST_SESSION_TYPE_REMOTE_DESKTOP:
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_FAILED,
- "Must be stopped from remote desktop session");
- return TRUE;
- }
-
- meta_screen_cast_session_close (session);
-
- meta_dbus_screen_cast_session_complete_stop (skeleton, invocation);
-
- return TRUE;
-}
-
-static void
-on_stream_closed (MetaScreenCastStream *stream,
- MetaScreenCastSession *session)
-{
- meta_screen_cast_session_close (session);
-}
-
-static gboolean
-is_valid_cursor_mode (MetaScreenCastCursorMode cursor_mode)
-{
- switch (cursor_mode)
- {
- case META_SCREEN_CAST_CURSOR_MODE_HIDDEN:
- case META_SCREEN_CAST_CURSOR_MODE_EMBEDDED:
- case META_SCREEN_CAST_CURSOR_MODE_METADATA:
- return TRUE;
- }
-
- return FALSE;
-}
-
-static gboolean
-handle_record_monitor (MetaDBusScreenCastSession *skeleton,
- GDBusMethodInvocation *invocation,
- const char *connector,
- GVariant *properties_variant)
-{
- MetaScreenCastSession *session = META_SCREEN_CAST_SESSION (skeleton);
- GDBusInterfaceSkeleton *interface_skeleton;
- GDBusConnection *connection;
- MetaBackend *backend = meta_get_backend ();
- MetaMonitorManager *monitor_manager =
- meta_backend_get_monitor_manager (backend);
- MetaMonitor *monitor;
- MetaScreenCastCursorMode cursor_mode;
- gboolean is_recording;
- MetaScreenCastFlag flags;
- ClutterStage *stage;
- GError *error = NULL;
- MetaScreenCastMonitorStream *monitor_stream;
- MetaScreenCastStream *stream;
- char *stream_path;
-
- if (!check_permission (session, invocation))
- {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_ACCESS_DENIED,
- "Permission denied");
- return TRUE;
- }
-
- interface_skeleton = G_DBUS_INTERFACE_SKELETON (skeleton);
- connection = g_dbus_interface_skeleton_get_connection (interface_skeleton);
-
- if (g_str_equal (connector, ""))
- monitor = meta_monitor_manager_get_primary_monitor (monitor_manager);
- else
- monitor = meta_monitor_manager_get_monitor_from_connector (monitor_manager,
- connector);
-
- if (!monitor)
- {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_FAILED,
- "Unknown monitor");
- return TRUE;
- }
-
- if (!g_variant_lookup (properties_variant, "cursor-mode", "u", &cursor_mode))
- {
- cursor_mode = META_SCREEN_CAST_CURSOR_MODE_HIDDEN;
- }
- else
- {
- if (!is_valid_cursor_mode (cursor_mode))
- {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_FAILED,
- "Unknown cursor mode");
- return TRUE;
- }
- }
-
- if (!g_variant_lookup (properties_variant, "is-recording", "b", &is_recording))
- is_recording = FALSE;
-
- stage = CLUTTER_STAGE (meta_backend_get_stage (backend));
-
- flags = META_SCREEN_CAST_FLAG_NONE;
- if (is_recording)
- flags |= META_SCREEN_CAST_FLAG_IS_RECORDING;
-
- monitor_stream = meta_screen_cast_monitor_stream_new (session,
- connection,
- monitor,
- stage,
- cursor_mode,
- flags,
- &error);
- if (!monitor_stream)
- {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_FAILED,
- "Failed to record monitor: %s",
- error->message);
- g_error_free (error);
- return TRUE;
- }
-
- stream = META_SCREEN_CAST_STREAM (monitor_stream);
- stream_path = meta_screen_cast_stream_get_object_path (stream);
-
- session->streams = g_list_append (session->streams, stream);
-
- g_signal_connect (stream, "closed", G_CALLBACK (on_stream_closed), session);
-
- meta_dbus_screen_cast_session_complete_record_monitor (skeleton,
- invocation,
- stream_path);
-
- return TRUE;
-}
-
-static gboolean
-handle_record_window (MetaDBusScreenCastSession *skeleton,
- GDBusMethodInvocation *invocation,
- GVariant *properties_variant)
-{
- MetaScreenCastSession *session = META_SCREEN_CAST_SESSION (skeleton);
- GDBusInterfaceSkeleton *interface_skeleton;
- GDBusConnection *connection;
- MetaWindow *window;
- MetaScreenCastCursorMode cursor_mode;
- gboolean is_recording;
- MetaScreenCastFlag flags;
- GError *error = NULL;
- MetaDisplay *display;
- GVariant *window_id_variant = NULL;
- MetaScreenCastWindowStream *window_stream;
- MetaScreenCastStream *stream;
- char *stream_path;
-
- if (!check_permission (session, invocation))
- {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_ACCESS_DENIED,
- "Permission denied");
- return TRUE;
- }
-
- if (properties_variant)
- window_id_variant = g_variant_lookup_value (properties_variant,
- "window-id",
- G_VARIANT_TYPE ("t"));
-
- display = meta_get_display ();
- if (window_id_variant)
- {
- uint64_t window_id;
-
- g_variant_get (window_id_variant, "t", &window_id);
- window = meta_display_get_window_from_id (display, window_id);
- }
- else
- {
- window = meta_display_get_focus_window (display);
- }
-
- if (!window)
- {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_FAILED,
- "Window not found");
- return TRUE;
- }
-
- if (!g_variant_lookup (properties_variant, "cursor-mode", "u", &cursor_mode))
- {
- cursor_mode = META_SCREEN_CAST_CURSOR_MODE_HIDDEN;
- }
- else
- {
- if (!is_valid_cursor_mode (cursor_mode))
- {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_FAILED,
- "Unknown cursor mode");
- return TRUE;
- }
- }
-
- if (!g_variant_lookup (properties_variant, "is-recording", "b", &is_recording))
- is_recording = FALSE;
-
- interface_skeleton = G_DBUS_INTERFACE_SKELETON (skeleton);
- connection = g_dbus_interface_skeleton_get_connection (interface_skeleton);
-
- flags = META_SCREEN_CAST_FLAG_NONE;
- if (is_recording)
- flags |= META_SCREEN_CAST_FLAG_IS_RECORDING;
-
- window_stream = meta_screen_cast_window_stream_new (session,
- connection,
- window,
- cursor_mode,
- flags,
- &error);
- if (!window_stream)
- {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_FAILED,
- "Failed to record window: %s",
- error->message);
- g_error_free (error);
- return TRUE;
- }
-
- stream = META_SCREEN_CAST_STREAM (window_stream);
- stream_path = meta_screen_cast_stream_get_object_path (stream);
-
- session->streams = g_list_append (session->streams, stream);
-
- g_signal_connect (stream, "closed", G_CALLBACK (on_stream_closed), session);
-
- meta_dbus_screen_cast_session_complete_record_window (skeleton,
- invocation,
- stream_path);
-
- return TRUE;
-}
-
-static gboolean
-handle_record_area (MetaDBusScreenCastSession *skeleton,
- GDBusMethodInvocation *invocation,
- int x,
- int y,
- int width,
- int height,
- GVariant *properties_variant)
-{
- MetaScreenCastSession *session = META_SCREEN_CAST_SESSION (skeleton);
- GDBusInterfaceSkeleton *interface_skeleton;
- GDBusConnection *connection;
- MetaBackend *backend;
- ClutterStage *stage;
- MetaScreenCastCursorMode cursor_mode;
- gboolean is_recording;
- MetaScreenCastFlag flags;
- g_autoptr (GError) error = NULL;
- MetaRectangle rect;
- MetaScreenCastAreaStream *area_stream;
- MetaScreenCastStream *stream;
- char *stream_path;
-
- if (!check_permission (session, invocation))
- {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_ACCESS_DENIED,
- "Permission denied");
- return TRUE;
- }
-
- if (!g_variant_lookup (properties_variant, "cursor-mode", "u", &cursor_mode))
- {
- cursor_mode = META_SCREEN_CAST_CURSOR_MODE_HIDDEN;
- }
- else
- {
- if (!is_valid_cursor_mode (cursor_mode))
- {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_FAILED,
- "Unknown cursor mode");
- return TRUE;
- }
- }
-
- if (!g_variant_lookup (properties_variant, "is-recording", "b", &is_recording))
- is_recording = FALSE;
-
- interface_skeleton = G_DBUS_INTERFACE_SKELETON (skeleton);
- connection = g_dbus_interface_skeleton_get_connection (interface_skeleton);
- backend = meta_screen_cast_get_backend (session->screen_cast);
- stage = CLUTTER_STAGE (meta_backend_get_stage (backend));
-
- flags = META_SCREEN_CAST_FLAG_NONE;
- if (is_recording)
- flags |= META_SCREEN_CAST_FLAG_IS_RECORDING;
-
- rect = (MetaRectangle) {
- .x = x,
- .y = y,
- .width = width,
- .height = height
- };
- area_stream = meta_screen_cast_area_stream_new (session,
- connection,
- &rect,
- stage,
- cursor_mode,
- flags,
- &error);
- if (!area_stream)
- {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_FAILED,
- "Failed to record area: %s",
- error->message);
- return TRUE;
- }
-
- stream = META_SCREEN_CAST_STREAM (area_stream);
- stream_path = meta_screen_cast_stream_get_object_path (stream);
-
- session->streams = g_list_append (session->streams, stream);
-
- g_signal_connect (stream, "closed", G_CALLBACK (on_stream_closed), session);
-
- meta_dbus_screen_cast_session_complete_record_area (skeleton,
- invocation,
- stream_path);
-
- return TRUE;
-}
-
-static gboolean
-handle_record_virtual (MetaDBusScreenCastSession *skeleton,
- GDBusMethodInvocation *invocation,
- GVariant *properties_variant)
-{
- MetaScreenCastSession *session = META_SCREEN_CAST_SESSION (skeleton);
- GDBusInterfaceSkeleton *interface_skeleton;
- GDBusConnection *connection;
- MetaScreenCastCursorMode cursor_mode;
- gboolean is_platform;
- MetaScreenCastFlag flags;
- g_autoptr (GError) error = NULL;
- MetaScreenCastVirtualStream *virtual_stream;
- MetaScreenCastStream *stream;
- char *stream_path;
-
- if (!check_permission (session, invocation))
- {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_ACCESS_DENIED,
- "Permission denied");
- return TRUE;
- }
-
- if (!g_variant_lookup (properties_variant, "cursor-mode", "u", &cursor_mode))
- {
- cursor_mode = META_SCREEN_CAST_CURSOR_MODE_HIDDEN;
- }
- else
- {
- if (!is_valid_cursor_mode (cursor_mode))
- {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_FAILED,
- "Unknown cursor mode");
- return TRUE;
- }
- }
-
- if (!g_variant_lookup (properties_variant, "is-platform", "b", &is_platform))
- is_platform = FALSE;
-
- interface_skeleton = G_DBUS_INTERFACE_SKELETON (skeleton);
- connection = g_dbus_interface_skeleton_get_connection (interface_skeleton);
-
- flags = META_SCREEN_CAST_FLAG_NONE;
- if (is_platform)
- flags |= META_SCREEN_CAST_FLAG_IS_PLATFORM;
-
- virtual_stream = meta_screen_cast_virtual_stream_new (session,
- connection,
- cursor_mode,
- flags,
- &error);
- if (!virtual_stream)
- {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_FAILED,
- "Failed to record virtual: %s",
- error->message);
- return TRUE;
- }
-
- stream = META_SCREEN_CAST_STREAM (virtual_stream);
- stream_path = meta_screen_cast_stream_get_object_path (stream);
-
- session->streams = g_list_append (session->streams, stream);
-
- g_signal_connect (stream, "closed", G_CALLBACK (on_stream_closed), session);
-
- meta_dbus_screen_cast_session_complete_record_virtual (skeleton,
- invocation,
- stream_path);
-
- return TRUE;
-}
-
-static void
-meta_screen_cast_session_init_iface (MetaDBusScreenCastSessionIface *iface)
-{
- iface->handle_start = handle_start;
- iface->handle_stop = handle_stop;
- iface->handle_record_monitor = handle_record_monitor;
- iface->handle_record_window = handle_record_window;
- iface->handle_record_area = handle_record_area;
- iface->handle_record_virtual = handle_record_virtual;
-}
-
-static void
-meta_screen_cast_session_client_vanished (MetaDbusSession *dbus_session)
-{
- meta_screen_cast_session_close (META_SCREEN_CAST_SESSION (dbus_session));
-}
-
-static void
-meta_dbus_session_init_iface (MetaDbusSessionInterface *iface)
-{
- iface->client_vanished = meta_screen_cast_session_client_vanished;
-}
-
-MetaScreenCastSession *
-meta_screen_cast_session_new (MetaScreenCast *screen_cast,
- MetaScreenCastSessionType session_type,
- const char *peer_name,
- GError **error)
-{
- GDBusInterfaceSkeleton *interface_skeleton;
- MetaScreenCastSession *session;
- GDBusConnection *connection;
- static unsigned int global_session_number = 0;
-
- session = g_object_new (META_TYPE_SCREEN_CAST_SESSION, NULL);
- session->screen_cast = screen_cast;
- session->session_type = session_type;
- session->peer_name = g_strdup (peer_name);
- session->object_path =
- g_strdup_printf (META_SCREEN_CAST_SESSION_DBUS_PATH "/u%u",
- ++global_session_number);
-
- interface_skeleton = G_DBUS_INTERFACE_SKELETON (session);
- connection = meta_screen_cast_get_connection (screen_cast);
- if (!g_dbus_interface_skeleton_export (interface_skeleton,
- connection,
- session->object_path,
- error))
- return NULL;
-
- return session;
-}
-
-static void
-meta_screen_cast_session_finalize (GObject *object)
-{
- MetaScreenCastSession *session = META_SCREEN_CAST_SESSION (object);
-
- g_clear_object (&session->handle);
- g_free (session->peer_name);
- g_free (session->object_path);
-
- G_OBJECT_CLASS (meta_screen_cast_session_parent_class)->finalize (object);
-}
-
-static void
-meta_screen_cast_session_init (MetaScreenCastSession *session)
-{
-}
-
-static void
-meta_screen_cast_session_class_init (MetaScreenCastSessionClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- object_class->finalize = meta_screen_cast_session_finalize;
-}
-
-static gboolean
-meta_screen_cast_session_is_recording (MetaScreenCastSession *session)
-{
- GList *l;
-
- if (!session->streams)
- return FALSE;
-
- for (l = session->streams; l; l = l->next)
- {
- MetaScreenCastStream *stream = l->data;
- MetaScreenCastFlag flags;
-
- flags = meta_screen_cast_stream_get_flags (stream);
- if (!(flags & META_SCREEN_CAST_FLAG_IS_RECORDING))
- return FALSE;
- }
-
- return TRUE;
-}
-
-static MetaScreenCastSessionHandle *
-meta_screen_cast_session_handle_new (MetaScreenCastSession *session)
-{
- MetaScreenCastSessionHandle *handle;
- gboolean is_recording;
-
- is_recording = meta_screen_cast_session_is_recording (session);
- handle = g_object_new (META_TYPE_SCREEN_CAST_SESSION_HANDLE,
- "is-recording", is_recording,
- NULL);
- handle->session = session;
-
- return handle;
-}
-
-static void
-meta_screen_cast_session_handle_stop (MetaRemoteAccessHandle *handle)
-{
- MetaScreenCastSession *session;
-
- session = META_SCREEN_CAST_SESSION_HANDLE (handle)->session;
- if (!session)
- return;
-
- meta_screen_cast_session_close (session);
-}
-
-static void
-meta_screen_cast_session_handle_init (MetaScreenCastSessionHandle *handle)
-{
-}
-
-static void
-meta_screen_cast_session_handle_class_init (MetaScreenCastSessionHandleClass *klass)
-{
- MetaRemoteAccessHandleClass *remote_access_handle_class =
- META_REMOTE_ACCESS_HANDLE_CLASS (klass);
-
- remote_access_handle_class->stop = meta_screen_cast_session_handle_stop;
-}
diff --git a/src/backends/meta-screen-cast-session.h b/src/backends/meta-screen-cast-session.h
deleted file mode 100644
index 46bde5eb9..000000000
--- a/src/backends/meta-screen-cast-session.h
+++ /dev/null
@@ -1,72 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2015-2017 Red Hat Inc.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- */
-
-#ifndef META_SCREEN_CAST_SESSION_H
-#define META_SCREEN_CAST_SESSION_H
-
-#include "backends/meta-screen-cast.h"
-
-#include "backends/meta-screen-cast-stream.h"
-#include "meta/meta-remote-access-controller.h"
-
-typedef enum _MetaScreenCastSessionType
-{
- META_SCREEN_CAST_SESSION_TYPE_NORMAL,
- META_SCREEN_CAST_SESSION_TYPE_REMOTE_DESKTOP,
-} MetaScreenCastSessionType;
-
-#define META_TYPE_SCREEN_CAST_SESSION (meta_screen_cast_session_get_type ())
-G_DECLARE_FINAL_TYPE (MetaScreenCastSession, meta_screen_cast_session,
- META, SCREEN_CAST_SESSION,
- MetaDBusScreenCastSessionSkeleton)
-
-#define META_TYPE_SCREEN_CAST_SESSION_HANDLE (meta_screen_cast_session_handle_get_type ())
-G_DECLARE_FINAL_TYPE (MetaScreenCastSessionHandle,
- meta_screen_cast_session_handle,
- META, SCREEN_CAST_SESSION_HANDLE,
- MetaRemoteAccessHandle)
-
-char * meta_screen_cast_session_get_object_path (MetaScreenCastSession *session);
-
-char * meta_screen_cast_session_get_peer_name (MetaScreenCastSession *session);
-
-MetaScreenCastSessionType meta_screen_cast_session_get_session_type (MetaScreenCastSession *session);
-
-MetaScreenCastSession * meta_screen_cast_session_new (MetaScreenCast *screen_cast,
- MetaScreenCastSessionType session_type,
- const char *peer_name,
- GError **error);
-
-gboolean meta_screen_cast_session_start (MetaScreenCastSession *session,
- GError **error);
-
-void meta_screen_cast_session_close (MetaScreenCastSession *session);
-
-MetaScreenCastStream * meta_screen_cast_session_get_stream (MetaScreenCastSession *session,
- const char *path);
-
-MetaScreenCast * meta_screen_cast_session_get_screen_cast (MetaScreenCastSession *session);
-
-void meta_screen_cast_session_set_disable_animations (MetaScreenCastSession *session,
- gboolean disable_animations);
-
-#endif /* META_SCREEN_CAST_SESSION_H */
diff --git a/src/backends/meta-screen-cast-stream-src.c b/src/backends/meta-screen-cast-stream-src.c
deleted file mode 100644
index c3ede8aea..000000000
--- a/src/backends/meta-screen-cast-stream-src.c
+++ /dev/null
@@ -1,1237 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2015-2017 Red Hat Inc.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- */
-
-#include "config.h"
-
-#include "backends/meta-screen-cast-stream-src.h"
-
-#include <errno.h>
-#include <fcntl.h>
-#include <pipewire/pipewire.h>
-#include <spa/param/props.h>
-#include <spa/param/format-utils.h>
-#include <spa/param/video/format-utils.h>
-#include <spa/utils/result.h>
-#include <stdint.h>
-#include <sys/mman.h>
-
-#include "backends/meta-screen-cast-session.h"
-#include "backends/meta-screen-cast-stream.h"
-#include "clutter/clutter-mutter.h"
-#include "core/meta-fraction.h"
-#include "meta/boxes.h"
-
-#define PRIVATE_OWNER_FROM_FIELD(TypeName, field_ptr, field_name) \
- (TypeName *)((guint8 *)(field_ptr) - G_PRIVATE_OFFSET (TypeName, field_name))
-
-#define CURSOR_META_SIZE(width, height) \
- (sizeof (struct spa_meta_cursor) + \
- sizeof (struct spa_meta_bitmap) + width * height * 4)
-
-#define DEFAULT_SIZE SPA_RECTANGLE (1280, 720)
-#define MIN_SIZE SPA_RECTANGLE (1, 1)
-#define MAX_SIZE SPA_RECTANGLE (16384, 16386)
-
-#define DEFAULT_FRAME_RATE SPA_FRACTION (60, 1)
-#define MIN_FRAME_RATE SPA_FRACTION (1, 1)
-#define MAX_FRAME_RATE SPA_FRACTION (1000, 1)
-
-enum
-{
- PROP_0,
-
- PROP_STREAM,
-};
-
-enum
-{
- READY,
- CLOSED,
-
- N_SIGNALS
-};
-
-static guint signals[N_SIGNALS];
-
-typedef struct _MetaPipeWireSource
-{
- GSource base;
-
- MetaScreenCastStreamSrc *src;
- struct pw_loop *pipewire_loop;
-} MetaPipeWireSource;
-
-typedef struct _MetaScreenCastStreamSrcPrivate
-{
- MetaScreenCastStream *stream;
-
- struct pw_context *pipewire_context;
- struct pw_core *pipewire_core;
- MetaPipeWireSource *pipewire_source;
- struct spa_hook pipewire_core_listener;
-
- gboolean is_enabled;
- gboolean emit_closed_after_dispatch;
-
- struct pw_stream *pipewire_stream;
- struct spa_hook pipewire_stream_listener;
- uint32_t node_id;
-
- struct spa_video_info_raw video_format;
- int video_stride;
-
- int64_t last_frame_timestamp_us;
- guint follow_up_frame_source_id;
-
- GHashTable *dmabuf_handles;
-} MetaScreenCastStreamSrcPrivate;
-
-static void
-meta_screen_cast_stream_src_init_initable_iface (GInitableIface *iface);
-
-G_DEFINE_TYPE_WITH_CODE (MetaScreenCastStreamSrc,
- meta_screen_cast_stream_src,
- G_TYPE_OBJECT,
- G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE,
- meta_screen_cast_stream_src_init_initable_iface)
- G_ADD_PRIVATE (MetaScreenCastStreamSrc))
-
-static gboolean
-meta_screen_cast_stream_src_get_specs (MetaScreenCastStreamSrc *src,
- int *width,
- int *height,
- float *frame_rate)
-{
- MetaScreenCastStreamSrcClass *klass =
- META_SCREEN_CAST_STREAM_SRC_GET_CLASS (src);
-
- return klass->get_specs (src, width, height, frame_rate);
-}
-
-static gboolean
-meta_screen_cast_stream_src_get_videocrop (MetaScreenCastStreamSrc *src,
- MetaRectangle *crop_rect)
-{
- MetaScreenCastStreamSrcClass *klass =
- META_SCREEN_CAST_STREAM_SRC_GET_CLASS (src);
-
- if (klass->get_videocrop)
- return klass->get_videocrop (src, crop_rect);
-
- return FALSE;
-}
-
-static gboolean
-meta_screen_cast_stream_src_record_to_buffer (MetaScreenCastStreamSrc *src,
- int width,
- int height,
- int stride,
- uint8_t *data,
- GError **error)
-{
- MetaScreenCastStreamSrcClass *klass =
- META_SCREEN_CAST_STREAM_SRC_GET_CLASS (src);
-
- return klass->record_to_buffer (src, width, height, stride, data, error);
-}
-
-static gboolean
-meta_screen_cast_stream_src_record_to_framebuffer (MetaScreenCastStreamSrc *src,
- CoglFramebuffer *framebuffer,
- GError **error)
-{
- MetaScreenCastStreamSrcClass *klass =
- META_SCREEN_CAST_STREAM_SRC_GET_CLASS (src);
-
- return klass->record_to_framebuffer (src, framebuffer, error);
-}
-
-static void
-meta_screen_cast_stream_src_record_follow_up (MetaScreenCastStreamSrc *src)
-{
- MetaScreenCastStreamSrcClass *klass =
- META_SCREEN_CAST_STREAM_SRC_GET_CLASS (src);
-
- klass->record_follow_up (src);
-}
-
-static void
-meta_screen_cast_stream_src_set_cursor_metadata (MetaScreenCastStreamSrc *src,
- struct spa_meta_cursor *spa_meta_cursor)
-{
- MetaScreenCastStreamSrcClass *klass =
- META_SCREEN_CAST_STREAM_SRC_GET_CLASS (src);
-
- if (klass->set_cursor_metadata)
- klass->set_cursor_metadata (src, spa_meta_cursor);
-}
-
-static gboolean
-draw_cursor_sprite_via_offscreen (MetaScreenCastStreamSrc *src,
- CoglTexture *cursor_texture,
- int bitmap_width,
- int bitmap_height,
- uint8_t *bitmap_data,
- GError **error)
-{
- MetaScreenCastStream *stream = meta_screen_cast_stream_src_get_stream (src);
- MetaScreenCastSession *session = meta_screen_cast_stream_get_session (stream);
- MetaScreenCast *screen_cast =
- meta_screen_cast_session_get_screen_cast (session);
- MetaBackend *backend = meta_screen_cast_get_backend (screen_cast);
- ClutterBackend *clutter_backend = meta_backend_get_clutter_backend (backend);
- CoglContext *cogl_context =
- clutter_backend_get_cogl_context (clutter_backend);
- CoglTexture2D *bitmap_texture;
- CoglOffscreen *offscreen;
- CoglFramebuffer *fb;
- CoglPipeline *pipeline;
- CoglColor clear_color;
-
- bitmap_texture = cogl_texture_2d_new_with_size (cogl_context,
- bitmap_width, bitmap_height);
- cogl_primitive_texture_set_auto_mipmap (COGL_PRIMITIVE_TEXTURE (bitmap_texture),
- FALSE);
- if (!cogl_texture_allocate (COGL_TEXTURE (bitmap_texture), error))
- {
- cogl_object_unref (bitmap_texture);
- return FALSE;
- }
-
- offscreen = cogl_offscreen_new_with_texture (COGL_TEXTURE (bitmap_texture));
- fb = COGL_FRAMEBUFFER (offscreen);
- cogl_object_unref (bitmap_texture);
- if (!cogl_framebuffer_allocate (fb, error))
- {
- g_object_unref (fb);
- return FALSE;
- }
-
- pipeline = cogl_pipeline_new (cogl_context);
- cogl_pipeline_set_layer_texture (pipeline, 0, cursor_texture);
- cogl_pipeline_set_layer_filters (pipeline, 0,
- COGL_PIPELINE_FILTER_LINEAR,
- COGL_PIPELINE_FILTER_LINEAR);
- cogl_color_init_from_4ub (&clear_color, 0, 0, 0, 0);
- cogl_framebuffer_clear (fb, COGL_BUFFER_BIT_COLOR, &clear_color);
- cogl_framebuffer_draw_rectangle (fb, pipeline,
- -1, 1, 1, -1);
- cogl_object_unref (pipeline);
-
- cogl_framebuffer_read_pixels (fb,
- 0, 0,
- bitmap_width, bitmap_height,
- COGL_PIXEL_FORMAT_RGBA_8888_PRE,
- bitmap_data);
- g_object_unref (fb);
-
- return TRUE;
-}
-
-gboolean
-meta_screen_cast_stream_src_draw_cursor_into (MetaScreenCastStreamSrc *src,
- CoglTexture *cursor_texture,
- float scale,
- uint8_t *data,
- GError **error)
-{
- int texture_width, texture_height;
- int width, height;
-
- texture_width = cogl_texture_get_width (cursor_texture);
- texture_height = cogl_texture_get_height (cursor_texture);
- width = texture_width * scale;
- height = texture_height * scale;
-
- if (texture_width == width &&
- texture_height == height)
- {
- cogl_texture_get_data (cursor_texture,
- COGL_PIXEL_FORMAT_RGBA_8888_PRE,
- texture_width * 4,
- data);
- }
- else
- {
- if (!draw_cursor_sprite_via_offscreen (src,
- cursor_texture,
- width,
- height,
- data,
- error))
- return FALSE;
- }
-
- return TRUE;
-}
-
-void
-meta_screen_cast_stream_src_unset_cursor_metadata (MetaScreenCastStreamSrc *src,
- struct spa_meta_cursor *spa_meta_cursor)
-{
- spa_meta_cursor->id = 0;
-}
-
-void
-meta_screen_cast_stream_src_set_cursor_position_metadata (MetaScreenCastStreamSrc *src,
- struct spa_meta_cursor *spa_meta_cursor,
- int x,
- int y)
-{
- spa_meta_cursor->id = 1;
- spa_meta_cursor->position.x = x;
- spa_meta_cursor->position.y = y;
- spa_meta_cursor->hotspot.x = 0;
- spa_meta_cursor->hotspot.y = 0;
- spa_meta_cursor->bitmap_offset = 0;
-}
-
-void
-meta_screen_cast_stream_src_set_empty_cursor_sprite_metadata (MetaScreenCastStreamSrc *src,
- struct spa_meta_cursor *spa_meta_cursor,
- int x,
- int y)
-{
- struct spa_meta_bitmap *spa_meta_bitmap;
-
- spa_meta_cursor->id = 1;
- spa_meta_cursor->position.x = x;
- spa_meta_cursor->position.y = y;
-
- spa_meta_cursor->bitmap_offset = sizeof (struct spa_meta_cursor);
-
- spa_meta_bitmap = SPA_MEMBER (spa_meta_cursor,
- spa_meta_cursor->bitmap_offset,
- struct spa_meta_bitmap);
- spa_meta_bitmap->format = SPA_VIDEO_FORMAT_RGBA;
- spa_meta_bitmap->offset = sizeof (struct spa_meta_bitmap);
-
- spa_meta_cursor->hotspot.x = 0;
- spa_meta_cursor->hotspot.y = 0;
-
- *spa_meta_bitmap = (struct spa_meta_bitmap) { 0 };
-}
-
-void
-meta_screen_cast_stream_src_set_cursor_sprite_metadata (MetaScreenCastStreamSrc *src,
- struct spa_meta_cursor *spa_meta_cursor,
- MetaCursorSprite *cursor_sprite,
- int x,
- int y,
- float scale)
-{
- CoglTexture *cursor_texture;
- struct spa_meta_bitmap *spa_meta_bitmap;
- int hotspot_x, hotspot_y;
- int texture_width, texture_height;
- int bitmap_width, bitmap_height;
- uint8_t *bitmap_data;
- GError *error = NULL;
-
- cursor_texture = meta_cursor_sprite_get_cogl_texture (cursor_sprite);
- if (!cursor_texture)
- {
- meta_screen_cast_stream_src_set_empty_cursor_sprite_metadata (src,
- spa_meta_cursor,
- x, y);
- return;
- }
-
- spa_meta_cursor->id = 1;
- spa_meta_cursor->position.x = x;
- spa_meta_cursor->position.y = y;
-
- spa_meta_cursor->bitmap_offset = sizeof (struct spa_meta_cursor);
-
- spa_meta_bitmap = SPA_MEMBER (spa_meta_cursor,
- spa_meta_cursor->bitmap_offset,
- struct spa_meta_bitmap);
- spa_meta_bitmap->format = SPA_VIDEO_FORMAT_RGBA;
- spa_meta_bitmap->offset = sizeof (struct spa_meta_bitmap);
-
- meta_cursor_sprite_get_hotspot (cursor_sprite, &hotspot_x, &hotspot_y);
- spa_meta_cursor->hotspot.x = (int32_t) roundf (hotspot_x * scale);
- spa_meta_cursor->hotspot.y = (int32_t) roundf (hotspot_y * scale);
-
- texture_width = cogl_texture_get_width (cursor_texture);
- texture_height = cogl_texture_get_height (cursor_texture);
- bitmap_width = texture_width * scale;
- bitmap_height = texture_height * scale;
-
- spa_meta_bitmap->size.width = bitmap_width;
- spa_meta_bitmap->size.height = bitmap_height;
- spa_meta_bitmap->stride = bitmap_width * 4;
-
- bitmap_data = SPA_MEMBER (spa_meta_bitmap,
- spa_meta_bitmap->offset,
- uint8_t);
-
- if (!meta_screen_cast_stream_src_draw_cursor_into (src,
- cursor_texture,
- scale,
- bitmap_data,
- &error))
- {
- g_warning ("Failed to draw cursor: %s", error->message);
- g_error_free (error);
- spa_meta_cursor->id = 0;
- }
-}
-
-static void
-add_cursor_metadata (MetaScreenCastStreamSrc *src,
- struct spa_buffer *spa_buffer)
-{
- struct spa_meta_cursor *spa_meta_cursor;
-
- spa_meta_cursor = spa_buffer_find_meta_data (spa_buffer, SPA_META_Cursor,
- sizeof (*spa_meta_cursor));
- if (spa_meta_cursor)
- meta_screen_cast_stream_src_set_cursor_metadata (src, spa_meta_cursor);
-}
-
-static void
-maybe_record_cursor (MetaScreenCastStreamSrc *src,
- struct spa_buffer *spa_buffer)
-{
- MetaScreenCastStream *stream = meta_screen_cast_stream_src_get_stream (src);
-
- switch (meta_screen_cast_stream_get_cursor_mode (stream))
- {
- case META_SCREEN_CAST_CURSOR_MODE_HIDDEN:
- case META_SCREEN_CAST_CURSOR_MODE_EMBEDDED:
- return;
- case META_SCREEN_CAST_CURSOR_MODE_METADATA:
- add_cursor_metadata (src, spa_buffer);
- return;
- }
-
- g_assert_not_reached ();
-}
-
-static gboolean
-do_record_frame (MetaScreenCastStreamSrc *src,
- struct spa_buffer *spa_buffer,
- uint8_t *data,
- GError **error)
-{
- MetaScreenCastStreamSrcPrivate *priv =
- meta_screen_cast_stream_src_get_instance_private (src);
-
- if (spa_buffer->datas[0].data ||
- spa_buffer->datas[0].type == SPA_DATA_MemFd)
- {
- int width = priv->video_format.size.width;
- int height = priv->video_format.size.height;
- int stride = priv->video_stride;
-
- return meta_screen_cast_stream_src_record_to_buffer (src,
- width,
- height,
- stride,
- data,
- error);
- }
- else if (spa_buffer->datas[0].type == SPA_DATA_DmaBuf)
- {
- CoglDmaBufHandle *dmabuf_handle =
- g_hash_table_lookup (priv->dmabuf_handles,
- GINT_TO_POINTER (spa_buffer->datas[0].fd));
- CoglFramebuffer *dmabuf_fbo =
- cogl_dma_buf_handle_get_framebuffer (dmabuf_handle);
-
- return meta_screen_cast_stream_src_record_to_framebuffer (src,
- dmabuf_fbo,
- error);
- }
-
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- "Unknown SPA buffer type %u", spa_buffer->datas[0].type);
- return FALSE;
-}
-
-gboolean
-meta_screen_cast_stream_src_pending_follow_up_frame (MetaScreenCastStreamSrc *src)
-{
- MetaScreenCastStreamSrcPrivate *priv =
- meta_screen_cast_stream_src_get_instance_private (src);
-
- return priv->follow_up_frame_source_id != 0;
-}
-
-static gboolean
-follow_up_frame_cb (gpointer user_data)
-{
- MetaScreenCastStreamSrc *src = user_data;
- MetaScreenCastStreamSrcPrivate *priv =
- meta_screen_cast_stream_src_get_instance_private (src);
-
- priv->follow_up_frame_source_id = 0;
- meta_screen_cast_stream_src_record_follow_up (src);
-
- return G_SOURCE_REMOVE;
-}
-
-static void
-maybe_schedule_follow_up_frame (MetaScreenCastStreamSrc *src,
- int64_t timeout_us)
-{
- MetaScreenCastStreamSrcPrivate *priv =
- meta_screen_cast_stream_src_get_instance_private (src);
-
- if (priv->follow_up_frame_source_id)
- return;
-
- priv->follow_up_frame_source_id = g_timeout_add (us2ms (timeout_us),
- follow_up_frame_cb,
- src);
-}
-
-void
-meta_screen_cast_stream_src_maybe_record_frame (MetaScreenCastStreamSrc *src,
- MetaScreenCastRecordFlag flags)
-{
- MetaScreenCastStreamSrcPrivate *priv =
- meta_screen_cast_stream_src_get_instance_private (src);
- MetaRectangle crop_rect;
- struct pw_buffer *buffer;
- struct spa_buffer *spa_buffer;
- uint8_t *data = NULL;
- uint64_t now_us;
- g_autoptr (GError) error = NULL;
-
- now_us = g_get_monotonic_time ();
- if (priv->video_format.max_framerate.num > 0 &&
- priv->last_frame_timestamp_us != 0)
- {
- int64_t min_interval_us;
- int64_t time_since_last_frame_us;
-
- min_interval_us =
- ((G_USEC_PER_SEC * priv->video_format.max_framerate.denom) /
- priv->video_format.max_framerate.num);
-
- time_since_last_frame_us = now_us - priv->last_frame_timestamp_us;
- if (time_since_last_frame_us < min_interval_us)
- {
- int64_t timeout_us;
-
- timeout_us = min_interval_us - time_since_last_frame_us;
- maybe_schedule_follow_up_frame (src, timeout_us);
- return;
- }
- }
-
- if (!priv->pipewire_stream)
- return;
-
- buffer = pw_stream_dequeue_buffer (priv->pipewire_stream);
- if (!buffer)
- {
- meta_topic (META_DEBUG_SCREEN_CAST,
- "Couldn't dequeue a buffer from pipewire stream (node id %u), "
- "maybe your encoding is too slow?",
- pw_stream_get_node_id (priv->pipewire_stream));
- return;
- }
-
- spa_buffer = buffer->buffer;
- data = spa_buffer->datas[0].data;
-
- if (spa_buffer->datas[0].type != SPA_DATA_DmaBuf && !data)
- {
- g_critical ("Invalid buffer data");
- return;
- }
-
- if (!(flags & META_SCREEN_CAST_RECORD_FLAG_CURSOR_ONLY))
- {
- g_clear_handle_id (&priv->follow_up_frame_source_id, g_source_remove);
- if (do_record_frame (src, spa_buffer, data, &error))
- {
- struct spa_meta_region *spa_meta_video_crop;
-
- spa_buffer->datas[0].chunk->size = spa_buffer->datas[0].maxsize;
- spa_buffer->datas[0].chunk->stride = priv->video_stride;
-
- /* Update VideoCrop if needed */
- spa_meta_video_crop =
- spa_buffer_find_meta_data (spa_buffer, SPA_META_VideoCrop,
- sizeof (*spa_meta_video_crop));
- if (spa_meta_video_crop)
- {
- if (meta_screen_cast_stream_src_get_videocrop (src, &crop_rect))
- {
- spa_meta_video_crop->region.position.x = crop_rect.x;
- spa_meta_video_crop->region.position.y = crop_rect.y;
- spa_meta_video_crop->region.size.width = crop_rect.width;
- spa_meta_video_crop->region.size.height = crop_rect.height;
- }
- else
- {
- spa_meta_video_crop->region.position.x = 0;
- spa_meta_video_crop->region.position.y = 0;
- spa_meta_video_crop->region.size.width =
- priv->video_format.size.width;
- spa_meta_video_crop->region.size.height =
- priv->video_format.size.height;
- }
- }
- }
- else
- {
- g_warning ("Failed to record screen cast frame: %s", error->message);
- spa_buffer->datas[0].chunk->size = 0;
- }
- }
- else
- {
- spa_buffer->datas[0].chunk->size = 0;
- }
-
- maybe_record_cursor (src, spa_buffer);
-
- priv->last_frame_timestamp_us = now_us;
-
- pw_stream_queue_buffer (priv->pipewire_stream, buffer);
-}
-
-static gboolean
-meta_screen_cast_stream_src_is_enabled (MetaScreenCastStreamSrc *src)
-{
- MetaScreenCastStreamSrcPrivate *priv =
- meta_screen_cast_stream_src_get_instance_private (src);
-
- return priv->is_enabled;
-}
-
-static void
-meta_screen_cast_stream_src_enable (MetaScreenCastStreamSrc *src)
-{
- MetaScreenCastStreamSrcPrivate *priv =
- meta_screen_cast_stream_src_get_instance_private (src);
-
- META_SCREEN_CAST_STREAM_SRC_GET_CLASS (src)->enable (src);
-
- priv->is_enabled = TRUE;
-}
-
-static void
-meta_screen_cast_stream_src_disable (MetaScreenCastStreamSrc *src)
-{
- MetaScreenCastStreamSrcPrivate *priv =
- meta_screen_cast_stream_src_get_instance_private (src);
-
- META_SCREEN_CAST_STREAM_SRC_GET_CLASS (src)->disable (src);
-
- g_clear_handle_id (&priv->follow_up_frame_source_id, g_source_remove);
-
- priv->is_enabled = FALSE;
-}
-
-void
-meta_screen_cast_stream_src_close (MetaScreenCastStreamSrc *src)
-{
- MetaScreenCastStreamSrcPrivate *priv =
- meta_screen_cast_stream_src_get_instance_private (src);
-
- if (meta_screen_cast_stream_src_is_enabled (src))
- meta_screen_cast_stream_src_disable (src);
- priv->emit_closed_after_dispatch = TRUE;
-}
-
-static void
-on_stream_state_changed (void *data,
- enum pw_stream_state old,
- enum pw_stream_state state,
- const char *error_message)
-{
- MetaScreenCastStreamSrc *src = data;
- MetaScreenCastStreamSrcPrivate *priv =
- meta_screen_cast_stream_src_get_instance_private (src);
-
- switch (state)
- {
- case PW_STREAM_STATE_ERROR:
- g_warning ("pipewire stream error: %s", error_message);
- meta_screen_cast_stream_src_close (src);
- break;
- case PW_STREAM_STATE_PAUSED:
- if (priv->node_id == SPA_ID_INVALID && priv->pipewire_stream)
- {
- priv->node_id = pw_stream_get_node_id (priv->pipewire_stream);
- g_signal_emit (src, signals[READY], 0, (unsigned int) priv->node_id);
- }
- if (meta_screen_cast_stream_src_is_enabled (src))
- meta_screen_cast_stream_src_disable (src);
- break;
- case PW_STREAM_STATE_STREAMING:
- if (!meta_screen_cast_stream_src_is_enabled (src))
- meta_screen_cast_stream_src_enable (src);
- break;
- case PW_STREAM_STATE_UNCONNECTED:
- case PW_STREAM_STATE_CONNECTING:
- break;
- }
-}
-
-static void
-on_stream_param_changed (void *data,
- uint32_t id,
- const struct spa_pod *format)
-{
- MetaScreenCastStreamSrc *src = data;
- MetaScreenCastStreamSrcPrivate *priv =
- meta_screen_cast_stream_src_get_instance_private (src);
- MetaScreenCastStreamSrcClass *klass =
- META_SCREEN_CAST_STREAM_SRC_GET_CLASS (src);
- uint8_t params_buffer[1024];
- int32_t width, height, stride, size;
- struct spa_pod_builder pod_builder;
- const struct spa_pod *params[3];
- const int bpp = 4;
-
- if (!format || id != SPA_PARAM_Format)
- return;
-
- spa_format_video_raw_parse (format,
- &priv->video_format);
-
- width = priv->video_format.size.width;
- height = priv->video_format.size.height;
- stride = SPA_ROUND_UP_N (width * bpp, 4);
- size = height * stride;
-
- priv->video_stride = stride;
-
- pod_builder = SPA_POD_BUILDER_INIT (params_buffer, sizeof (params_buffer));
-
- params[0] = spa_pod_builder_add_object (
- &pod_builder,
- SPA_TYPE_OBJECT_ParamBuffers, SPA_PARAM_Buffers,
- SPA_PARAM_BUFFERS_buffers, SPA_POD_CHOICE_RANGE_Int (16, 2, 16),
- SPA_PARAM_BUFFERS_blocks, SPA_POD_Int (1),
- SPA_PARAM_BUFFERS_size, SPA_POD_Int (size),
- SPA_PARAM_BUFFERS_stride, SPA_POD_Int (stride),
- SPA_PARAM_BUFFERS_align, SPA_POD_Int (16));
-
- params[1] = spa_pod_builder_add_object (
- &pod_builder,
- SPA_TYPE_OBJECT_ParamMeta, SPA_PARAM_Meta,
- SPA_PARAM_META_type, SPA_POD_Id (SPA_META_VideoCrop),
- SPA_PARAM_META_size, SPA_POD_Int (sizeof (struct spa_meta_region)));
-
- params[2] = spa_pod_builder_add_object (
- &pod_builder,
- SPA_TYPE_OBJECT_ParamMeta, SPA_PARAM_Meta,
- SPA_PARAM_META_type, SPA_POD_Id (SPA_META_Cursor),
- SPA_PARAM_META_size, SPA_POD_Int (CURSOR_META_SIZE (384, 384)));
-
- pw_stream_update_params (priv->pipewire_stream, params, G_N_ELEMENTS (params));
-
- if (klass->notify_params_updated)
- klass->notify_params_updated (src, &priv->video_format);
-}
-
-static void
-on_stream_add_buffer (void *data,
- struct pw_buffer *buffer)
-{
- MetaScreenCastStreamSrc *src = data;
- MetaScreenCastStreamSrcPrivate *priv =
- meta_screen_cast_stream_src_get_instance_private (src);
- MetaScreenCastStream *stream = meta_screen_cast_stream_src_get_stream (src);
- MetaScreenCastSession *session = meta_screen_cast_stream_get_session (stream);
- MetaScreenCast *screen_cast =
- meta_screen_cast_session_get_screen_cast (session);
- CoglDmaBufHandle *dmabuf_handle;
- struct spa_buffer *spa_buffer = buffer->buffer;
- struct spa_data *spa_data = spa_buffer->datas;
- const int bpp = 4;
- int stride;
-
- stride = SPA_ROUND_UP_N (priv->video_format.size.width * bpp, 4);
-
- spa_data[0].mapoffset = 0;
- spa_data[0].maxsize = stride * priv->video_format.size.height;
- spa_data[0].data = NULL;
-
- if (spa_data[0].type & (1 << SPA_DATA_DmaBuf))
- {
- dmabuf_handle =
- meta_screen_cast_create_dma_buf_handle (screen_cast,
- priv->video_format.size.width,
- priv->video_format.size.height);
- }
- else
- {
- dmabuf_handle = NULL;
- }
-
- if (dmabuf_handle)
- {
- spa_data[0].type = SPA_DATA_DmaBuf;
- spa_data[0].flags = SPA_DATA_FLAG_READWRITE;
- spa_data[0].fd = cogl_dma_buf_handle_get_fd (dmabuf_handle);
-
- g_hash_table_insert (priv->dmabuf_handles,
- GINT_TO_POINTER (spa_data[0].fd),
- dmabuf_handle);
- }
- else
- {
- unsigned int seals;
-
- if (!(spa_data[0].type & (1 << SPA_DATA_MemFd)))
- {
- g_critical ("No supported PipeWire stream buffer data type could "
- "be negotiated");
- return;
- }
-
- /* Fallback to a memfd buffer */
- spa_data[0].type = SPA_DATA_MemFd;
- spa_data[0].flags = SPA_DATA_FLAG_READWRITE;
- spa_data[0].fd = memfd_create ("mutter-screen-cast-memfd",
- MFD_CLOEXEC | MFD_ALLOW_SEALING);
- if (spa_data[0].fd == -1)
- {
- g_critical ("Can't create memfd: %m");
- return;
- }
- spa_data[0].mapoffset = 0;
- spa_data[0].maxsize = stride * priv->video_format.size.height;
-
- if (ftruncate (spa_data[0].fd, spa_data[0].maxsize) < 0)
- {
- close (spa_data[0].fd);
- spa_data[0].fd = -1;
- g_critical ("Can't truncate to %d: %m", spa_data[0].maxsize);
- return;
- }
-
- seals = F_SEAL_GROW | F_SEAL_SHRINK | F_SEAL_SEAL;
- if (fcntl (spa_data[0].fd, F_ADD_SEALS, seals) == -1)
- g_warning ("Failed to add seals: %m");
-
- spa_data[0].data = mmap (NULL,
- spa_data[0].maxsize,
- PROT_READ | PROT_WRITE,
- MAP_SHARED,
- spa_data[0].fd,
- spa_data[0].mapoffset);
- if (spa_data[0].data == MAP_FAILED)
- {
- close (spa_data[0].fd);
- spa_data[0].fd = -1;
- g_critical ("Failed to mmap memory: %m");
- return;
- }
- }
-}
-
-static void
-on_stream_remove_buffer (void *data,
- struct pw_buffer *buffer)
-{
- MetaScreenCastStreamSrc *src = data;
- MetaScreenCastStreamSrcPrivate *priv =
- meta_screen_cast_stream_src_get_instance_private (src);
- struct spa_buffer *spa_buffer = buffer->buffer;
- struct spa_data *spa_data = spa_buffer->datas;
-
- if (spa_data[0].type == SPA_DATA_DmaBuf)
- {
- if (!g_hash_table_remove (priv->dmabuf_handles, GINT_TO_POINTER (spa_data[0].fd)))
- g_critical ("Failed to remove non-exported DMA buffer");
- }
- else if (spa_data[0].type == SPA_DATA_MemFd)
- {
- g_warn_if_fail (spa_data[0].fd > 0 || !spa_data[0].data);
-
- if (spa_data[0].fd > 0)
- {
- munmap (spa_data[0].data, spa_data[0].maxsize);
- close (spa_data[0].fd);
- }
- }
-}
-
-static const struct pw_stream_events stream_events = {
- PW_VERSION_STREAM_EVENTS,
- .state_changed = on_stream_state_changed,
- .param_changed = on_stream_param_changed,
- .add_buffer = on_stream_add_buffer,
- .remove_buffer = on_stream_remove_buffer,
-};
-
-static struct pw_stream *
-create_pipewire_stream (MetaScreenCastStreamSrc *src,
- GError **error)
-{
- MetaScreenCastStreamSrcPrivate *priv =
- meta_screen_cast_stream_src_get_instance_private (src);
- struct pw_stream *pipewire_stream;
- uint8_t buffer[1024];
- struct spa_pod_builder pod_builder =
- SPA_POD_BUILDER_INIT (buffer, sizeof (buffer));
- int width;
- int height;
- float frame_rate;
- const struct spa_pod *params[1];
- int result;
-
- priv->node_id = SPA_ID_INVALID;
-
- pipewire_stream = pw_stream_new (priv->pipewire_core,
- "meta-screen-cast-src",
- NULL);
- if (!pipewire_stream)
- {
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- "Failed to create PipeWire stream: %s",
- strerror (errno));
- return NULL;
- }
-
- if (meta_screen_cast_stream_src_get_specs (src, &width, &height, &frame_rate))
- {
- MetaFraction frame_rate_fraction;
- struct spa_fraction max_framerate;
- struct spa_fraction min_framerate;
-
- frame_rate_fraction = meta_fraction_from_double (frame_rate);
-
- min_framerate = SPA_FRACTION (1, 1);
- max_framerate = SPA_FRACTION (frame_rate_fraction.num,
- frame_rate_fraction.denom);
-
- params[0] = spa_pod_builder_add_object (
- &pod_builder,
- SPA_TYPE_OBJECT_Format, SPA_PARAM_EnumFormat,
- SPA_FORMAT_mediaType, SPA_POD_Id (SPA_MEDIA_TYPE_video),
- SPA_FORMAT_mediaSubtype, SPA_POD_Id (SPA_MEDIA_SUBTYPE_raw),
- SPA_FORMAT_VIDEO_format, SPA_POD_Id (SPA_VIDEO_FORMAT_BGRx),
- SPA_FORMAT_VIDEO_size, SPA_POD_Rectangle (&SPA_RECTANGLE (width,
- height)),
- SPA_FORMAT_VIDEO_framerate, SPA_POD_Fraction (&SPA_FRACTION (0, 1)),
- SPA_FORMAT_VIDEO_maxFramerate,
- SPA_POD_CHOICE_RANGE_Fraction (&max_framerate,
- &min_framerate,
- &max_framerate));
- }
- else
- {
- params[0] = spa_pod_builder_add_object (
- &pod_builder,
- SPA_TYPE_OBJECT_Format, SPA_PARAM_EnumFormat,
- SPA_FORMAT_mediaType, SPA_POD_Id (SPA_MEDIA_TYPE_video),
- SPA_FORMAT_mediaSubtype, SPA_POD_Id (SPA_MEDIA_SUBTYPE_raw),
- SPA_FORMAT_VIDEO_format, SPA_POD_Id (SPA_VIDEO_FORMAT_BGRx),
- SPA_FORMAT_VIDEO_size, SPA_POD_CHOICE_RANGE_Rectangle (&DEFAULT_SIZE,
- &MIN_SIZE,
- &MAX_SIZE),
- SPA_FORMAT_VIDEO_framerate, SPA_POD_Fraction (&SPA_FRACTION (0, 1)),
- SPA_FORMAT_VIDEO_maxFramerate,
- SPA_POD_CHOICE_RANGE_Fraction (&DEFAULT_FRAME_RATE,
- &MIN_FRAME_RATE,
- &MAX_FRAME_RATE));
- }
-
- pw_stream_add_listener (pipewire_stream,
- &priv->pipewire_stream_listener,
- &stream_events,
- src);
-
- result = pw_stream_connect (pipewire_stream,
- PW_DIRECTION_OUTPUT,
- SPA_ID_INVALID,
- (PW_STREAM_FLAG_DRIVER |
- PW_STREAM_FLAG_ALLOC_BUFFERS),
- params, G_N_ELEMENTS (params));
- if (result != 0)
- {
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- "Could not connect: %s", spa_strerror (result));
- return NULL;
- }
-
- return pipewire_stream;
-}
-
-static void
-on_core_error (void *data,
- uint32_t id,
- int seq,
- int res,
- const char *message)
-{
- MetaScreenCastStreamSrc *src = data;
-
- g_warning ("pipewire remote error: id:%u %s", id, message);
-
- if (id == PW_ID_CORE && res == -EPIPE)
- meta_screen_cast_stream_src_close (src);
-}
-
-static gboolean
-pipewire_loop_source_prepare (GSource *base,
- int *timeout)
-{
- *timeout = -1;
- return FALSE;
-}
-
-static gboolean
-pipewire_loop_source_dispatch (GSource *source,
- GSourceFunc callback,
- gpointer user_data)
-{
- MetaPipeWireSource *pipewire_source = (MetaPipeWireSource *) source;
- MetaScreenCastStreamSrc *src = pipewire_source->src;
- MetaScreenCastStreamSrcPrivate *priv =
- meta_screen_cast_stream_src_get_instance_private (src);
- int result;
-
- result = pw_loop_iterate (pipewire_source->pipewire_loop, 0);
- if (result < 0)
- g_warning ("pipewire_loop_iterate failed: %s", spa_strerror (result));
-
- if (priv->emit_closed_after_dispatch)
- g_signal_emit (src, signals[CLOSED], 0);
-
- return TRUE;
-}
-
-static void
-pipewire_loop_source_finalize (GSource *source)
-{
- MetaPipeWireSource *pipewire_source = (MetaPipeWireSource *) source;
-
- pw_loop_leave (pipewire_source->pipewire_loop);
- pw_loop_destroy (pipewire_source->pipewire_loop);
-}
-
-static GSourceFuncs pipewire_source_funcs =
-{
- pipewire_loop_source_prepare,
- NULL,
- pipewire_loop_source_dispatch,
- pipewire_loop_source_finalize
-};
-
-static MetaPipeWireSource *
-create_pipewire_source (MetaScreenCastStreamSrc *src)
-{
- MetaPipeWireSource *pipewire_source;
-
- pipewire_source =
- (MetaPipeWireSource *) g_source_new (&pipewire_source_funcs,
- sizeof (MetaPipeWireSource));
- pipewire_source->src = src;
- pipewire_source->pipewire_loop = pw_loop_new (NULL);
- if (!pipewire_source->pipewire_loop)
- {
- g_source_unref ((GSource *) pipewire_source);
- return NULL;
- }
-
- g_source_add_unix_fd (&pipewire_source->base,
- pw_loop_get_fd (pipewire_source->pipewire_loop),
- G_IO_IN | G_IO_ERR);
-
- pw_loop_enter (pipewire_source->pipewire_loop);
- g_source_attach (&pipewire_source->base, NULL);
-
- return pipewire_source;
-}
-
-static const struct pw_core_events core_events = {
- PW_VERSION_CORE_EVENTS,
- .error = on_core_error,
-};
-
-static gboolean
-meta_screen_cast_stream_src_initable_init (GInitable *initable,
- GCancellable *cancellable,
- GError **error)
-{
- MetaScreenCastStreamSrc *src = META_SCREEN_CAST_STREAM_SRC (initable);
- MetaScreenCastStreamSrcPrivate *priv =
- meta_screen_cast_stream_src_get_instance_private (src);
-
- priv->pipewire_source = create_pipewire_source (src);
- if (!priv->pipewire_source)
- {
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- "Failed to create PipeWire source");
- return FALSE;
- }
-
- priv->pipewire_context = pw_context_new (priv->pipewire_source->pipewire_loop,
- NULL, 0);
- if (!priv->pipewire_context)
- {
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- "Failed to create pipewire context");
- return FALSE;
- }
-
- priv->pipewire_core = pw_context_connect (priv->pipewire_context, NULL, 0);
- if (!priv->pipewire_core)
- {
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- "Couldn't connect pipewire context");
- return FALSE;
- }
-
- pw_core_add_listener (priv->pipewire_core,
- &priv->pipewire_core_listener,
- &core_events,
- src);
-
- priv->pipewire_stream = create_pipewire_stream (src, error);
- if (!priv->pipewire_stream)
- return FALSE;
-
- return TRUE;
-}
-
-static void
-meta_screen_cast_stream_src_init_initable_iface (GInitableIface *iface)
-{
- iface->init = meta_screen_cast_stream_src_initable_init;
-}
-
-MetaScreenCastStream *
-meta_screen_cast_stream_src_get_stream (MetaScreenCastStreamSrc *src)
-{
- MetaScreenCastStreamSrcPrivate *priv =
- meta_screen_cast_stream_src_get_instance_private (src);
-
- return priv->stream;
-}
-
-static void
-meta_screen_cast_stream_src_finalize (GObject *object)
-{
- MetaScreenCastStreamSrc *src = META_SCREEN_CAST_STREAM_SRC (object);
- MetaScreenCastStreamSrcPrivate *priv =
- meta_screen_cast_stream_src_get_instance_private (src);
-
- if (meta_screen_cast_stream_src_is_enabled (src))
- meta_screen_cast_stream_src_disable (src);
-
- g_clear_pointer (&priv->pipewire_stream, pw_stream_destroy);
- g_clear_pointer (&priv->dmabuf_handles, g_hash_table_destroy);
- g_clear_pointer (&priv->pipewire_core, pw_core_disconnect);
- g_clear_pointer (&priv->pipewire_context, pw_context_destroy);
- g_source_destroy (&priv->pipewire_source->base);
- g_source_unref (&priv->pipewire_source->base);
-
- G_OBJECT_CLASS (meta_screen_cast_stream_src_parent_class)->finalize (object);
-}
-
-static void
-meta_screen_cast_stream_src_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- MetaScreenCastStreamSrc *src = META_SCREEN_CAST_STREAM_SRC (object);
- MetaScreenCastStreamSrcPrivate *priv =
- meta_screen_cast_stream_src_get_instance_private (src);
-
- switch (prop_id)
- {
- case PROP_STREAM:
- priv->stream = g_value_get_object (value);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- }
-}
-
-static void
-meta_screen_cast_stream_src_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- MetaScreenCastStreamSrc *src = META_SCREEN_CAST_STREAM_SRC (object);
- MetaScreenCastStreamSrcPrivate *priv =
- meta_screen_cast_stream_src_get_instance_private (src);
-
- switch (prop_id)
- {
- case PROP_STREAM:
- g_value_set_object (value, priv->stream);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- }
-}
-
-static void
-meta_screen_cast_stream_src_init (MetaScreenCastStreamSrc *src)
-{
- MetaScreenCastStreamSrcPrivate *priv =
- meta_screen_cast_stream_src_get_instance_private (src);
-
- priv->dmabuf_handles =
- g_hash_table_new_full (NULL, NULL, NULL,
- (GDestroyNotify) cogl_dma_buf_handle_free);
-}
-
-static void
-meta_screen_cast_stream_src_class_init (MetaScreenCastStreamSrcClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- object_class->finalize = meta_screen_cast_stream_src_finalize;
- object_class->set_property = meta_screen_cast_stream_src_set_property;
- object_class->get_property = meta_screen_cast_stream_src_get_property;
-
- g_object_class_install_property (object_class,
- PROP_STREAM,
- g_param_spec_object ("stream",
- "stream",
- "MetaScreenCastStream",
- META_TYPE_SCREEN_CAST_STREAM,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT_ONLY |
- G_PARAM_STATIC_STRINGS));
-
- signals[READY] = g_signal_new ("ready",
- G_TYPE_FROM_CLASS (klass),
- G_SIGNAL_RUN_LAST,
- 0,
- NULL, NULL, NULL,
- G_TYPE_NONE, 1,
- G_TYPE_UINT);
- signals[CLOSED] = g_signal_new ("closed",
- G_TYPE_FROM_CLASS (klass),
- G_SIGNAL_RUN_LAST,
- 0,
- NULL, NULL, NULL,
- G_TYPE_NONE, 0);
-}
diff --git a/src/backends/meta-screen-cast-stream-src.h b/src/backends/meta-screen-cast-stream-src.h
deleted file mode 100644
index 456b5bd97..000000000
--- a/src/backends/meta-screen-cast-stream-src.h
+++ /dev/null
@@ -1,117 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2015-2017 Red Hat Inc.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- */
-
-#ifndef META_SCREEN_CAST_STREAM_SRC_H
-#define META_SCREEN_CAST_STREAM_SRC_H
-
-#include <glib-object.h>
-#include <spa/param/video/format-utils.h>
-#include <spa/buffer/meta.h>
-
-#include "backends/meta-backend-private.h"
-#include "backends/meta-cursor-renderer.h"
-#include "backends/meta-cursor.h"
-#include "backends/meta-renderer.h"
-#include "clutter/clutter.h"
-#include "cogl/cogl.h"
-#include "meta/boxes.h"
-
-typedef struct _MetaScreenCastStream MetaScreenCastStream;
-
-typedef enum _MetaScreenCastRecordFlag
-{
- META_SCREEN_CAST_RECORD_FLAG_NONE = 0,
- META_SCREEN_CAST_RECORD_FLAG_CURSOR_ONLY = 1 << 0,
-} MetaScreenCastRecordFlag;
-
-#define META_TYPE_SCREEN_CAST_STREAM_SRC (meta_screen_cast_stream_src_get_type ())
-G_DECLARE_DERIVABLE_TYPE (MetaScreenCastStreamSrc,
- meta_screen_cast_stream_src,
- META, SCREEN_CAST_STREAM_SRC,
- GObject)
-
-struct _MetaScreenCastStreamSrcClass
-{
- GObjectClass parent_class;
-
- gboolean (* get_specs) (MetaScreenCastStreamSrc *src,
- int *width,
- int *height,
- float *frame_rate);
- void (* enable) (MetaScreenCastStreamSrc *src);
- void (* disable) (MetaScreenCastStreamSrc *src);
- gboolean (* record_to_buffer) (MetaScreenCastStreamSrc *src,
- int width,
- int height,
- int stride,
- uint8_t *data,
- GError **error);
- gboolean (* record_to_framebuffer) (MetaScreenCastStreamSrc *src,
- CoglFramebuffer *framebuffer,
- GError **error);
- void (* record_follow_up) (MetaScreenCastStreamSrc *src);
-
- gboolean (* get_videocrop) (MetaScreenCastStreamSrc *src,
- MetaRectangle *crop_rect);
- void (* set_cursor_metadata) (MetaScreenCastStreamSrc *src,
- struct spa_meta_cursor *spa_meta_cursor);
-
- void (* notify_params_updated) (MetaScreenCastStreamSrc *src,
- struct spa_video_info_raw *video_format);
-};
-
-void meta_screen_cast_stream_src_close (MetaScreenCastStreamSrc *src);
-
-void meta_screen_cast_stream_src_maybe_record_frame (MetaScreenCastStreamSrc *src,
- MetaScreenCastRecordFlag flags);
-
-gboolean meta_screen_cast_stream_src_pending_follow_up_frame (MetaScreenCastStreamSrc *src);
-
-MetaScreenCastStream * meta_screen_cast_stream_src_get_stream (MetaScreenCastStreamSrc *src);
-
-gboolean meta_screen_cast_stream_src_draw_cursor_into (MetaScreenCastStreamSrc *src,
- CoglTexture *cursor_texture,
- float scale,
- uint8_t *data,
- GError **error);
-
-void meta_screen_cast_stream_src_unset_cursor_metadata (MetaScreenCastStreamSrc *src,
- struct spa_meta_cursor *spa_meta_cursor);
-
-void meta_screen_cast_stream_src_set_cursor_position_metadata (MetaScreenCastStreamSrc *src,
- struct spa_meta_cursor *spa_meta_cursor,
- int x,
- int y);
-
-void meta_screen_cast_stream_src_set_empty_cursor_sprite_metadata (MetaScreenCastStreamSrc *src,
- struct spa_meta_cursor *spa_meta_cursor,
- int x,
- int y);
-
-void meta_screen_cast_stream_src_set_cursor_sprite_metadata (MetaScreenCastStreamSrc *src,
- struct spa_meta_cursor *spa_meta_cursor,
- MetaCursorSprite *cursor_sprite,
- int x,
- int y,
- float scale);
-
-#endif /* META_SCREEN_CAST_STREAM_SRC_H */
diff --git a/src/backends/meta-screen-cast-stream.c b/src/backends/meta-screen-cast-stream.c
deleted file mode 100644
index b8ab5abd5..000000000
--- a/src/backends/meta-screen-cast-stream.c
+++ /dev/null
@@ -1,383 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2017 Red Hat Inc.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- */
-
-#include "config.h"
-
-#include "backends/meta-screen-cast-stream.h"
-
-#include "backends/meta-screen-cast-session.h"
-
-#include "meta-private-enum-types.h"
-
-#define META_SCREEN_CAST_STREAM_DBUS_IFACE "org.gnome.Mutter.ScreenCast.Stream"
-#define META_SCREEN_CAST_STREAM_DBUS_PATH "/org/gnome/Mutter/ScreenCast/Stream"
-
-enum
-{
- PROP_0,
-
- PROP_SESSION,
- PROP_CONNECTION,
- PROP_CURSOR_MODE,
- PROP_FLAGS,
-};
-
-enum
-{
- CLOSED,
-
- N_SIGNALS
-};
-
-static guint signals[N_SIGNALS];
-
-typedef struct _MetaScreenCastStreamPrivate
-{
- MetaScreenCastSession *session;
-
- GDBusConnection *connection;
- char *object_path;
-
- MetaScreenCastCursorMode cursor_mode;
- MetaScreenCastFlag flags;
-
- MetaScreenCastStreamSrc *src;
-} MetaScreenCastStreamPrivate;
-
-static void
-meta_screen_cast_stream_init_initable_iface (GInitableIface *iface);
-
-G_DEFINE_TYPE_WITH_CODE (MetaScreenCastStream,
- meta_screen_cast_stream,
- META_DBUS_TYPE_SCREEN_CAST_STREAM_SKELETON,
- G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE,
- meta_screen_cast_stream_init_initable_iface)
- G_ADD_PRIVATE (MetaScreenCastStream))
-
-static MetaScreenCastStreamSrc *
-meta_screen_cast_stream_create_src (MetaScreenCastStream *stream,
- GError **error)
-{
- return META_SCREEN_CAST_STREAM_GET_CLASS (stream)->create_src (stream,
- error);
-}
-
-static void
-meta_screen_cast_stream_set_parameters (MetaScreenCastStream *stream,
- GVariantBuilder *parameters_builder)
-{
- META_SCREEN_CAST_STREAM_GET_CLASS (stream)->set_parameters (stream,
- parameters_builder);
-}
-
-static void
-on_stream_src_closed (MetaScreenCastStreamSrc *src,
- MetaScreenCastStream *stream)
-{
- MetaScreenCastStreamPrivate *priv =
- meta_screen_cast_stream_get_instance_private (stream);
-
- if (priv->src)
- meta_screen_cast_stream_close (stream);
-}
-
-static void
-on_stream_src_ready (MetaScreenCastStreamSrc *src,
- uint32_t node_id,
- MetaScreenCastStream *stream)
-{
- MetaScreenCastStreamPrivate *priv =
- meta_screen_cast_stream_get_instance_private (stream);
- GDBusConnection *connection = priv->connection;
- char *peer_name;
-
- peer_name = meta_screen_cast_session_get_peer_name (priv->session);
- g_dbus_connection_emit_signal (connection,
- peer_name,
- priv->object_path,
- META_SCREEN_CAST_STREAM_DBUS_IFACE,
- "PipeWireStreamAdded",
- g_variant_new ("(u)", node_id),
- NULL);
-}
-
-MetaScreenCastSession *
-meta_screen_cast_stream_get_session (MetaScreenCastStream *stream)
-{
- MetaScreenCastStreamPrivate *priv =
- meta_screen_cast_stream_get_instance_private (stream);
-
- return priv->session;
-}
-
-gboolean
-meta_screen_cast_stream_start (MetaScreenCastStream *stream,
- GError **error)
-{
- MetaScreenCastStreamPrivate *priv =
- meta_screen_cast_stream_get_instance_private (stream);
- MetaScreenCastStreamSrc *src;
-
- src = meta_screen_cast_stream_create_src (stream, error);
- if (!src)
- return FALSE;
-
- priv->src = src;
- g_signal_connect (src, "ready", G_CALLBACK (on_stream_src_ready), stream);
- g_signal_connect (src, "closed", G_CALLBACK (on_stream_src_closed), stream);
-
- return TRUE;
-}
-
-void
-meta_screen_cast_stream_close (MetaScreenCastStream *stream)
-{
- MetaScreenCastStreamPrivate *priv =
- meta_screen_cast_stream_get_instance_private (stream);
-
- g_clear_object (&priv->src);
-
- g_signal_emit (stream, signals[CLOSED], 0);
-}
-
-char *
-meta_screen_cast_stream_get_object_path (MetaScreenCastStream *stream)
-{
- MetaScreenCastStreamPrivate *priv =
- meta_screen_cast_stream_get_instance_private (stream);
-
- return priv->object_path;
-}
-
-MetaScreenCastStreamSrc *
-meta_screen_cast_stream_get_src (MetaScreenCastStream *stream)
-{
- MetaScreenCastStreamPrivate *priv =
- meta_screen_cast_stream_get_instance_private (stream);
-
- return priv->src;
-}
-
-gboolean
-meta_screen_cast_stream_transform_position (MetaScreenCastStream *stream,
- double stream_x,
- double stream_y,
- double *x,
- double *y)
-{
- MetaScreenCastStreamClass *klass = META_SCREEN_CAST_STREAM_GET_CLASS (stream);
-
- return klass->transform_position (stream, stream_x, stream_y, x, y);
-}
-
-MetaScreenCastCursorMode
-meta_screen_cast_stream_get_cursor_mode (MetaScreenCastStream *stream)
-{
- MetaScreenCastStreamPrivate *priv =
- meta_screen_cast_stream_get_instance_private (stream);
-
- return priv->cursor_mode;
-}
-
-MetaScreenCastFlag
-meta_screen_cast_stream_get_flags (MetaScreenCastStream *stream)
-{
- MetaScreenCastStreamPrivate *priv =
- meta_screen_cast_stream_get_instance_private (stream);
-
- return priv->flags;
-}
-
-static void
-meta_screen_cast_stream_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- MetaScreenCastStream *stream = META_SCREEN_CAST_STREAM (object);
- MetaScreenCastStreamPrivate *priv =
- meta_screen_cast_stream_get_instance_private (stream);
-
- switch (prop_id)
- {
- case PROP_SESSION:
- priv->session = g_value_get_object (value);
- break;
- case PROP_CONNECTION:
- priv->connection = g_value_get_object (value);
- break;
- case PROP_CURSOR_MODE:
- priv->cursor_mode = g_value_get_uint (value);
- break;
- case PROP_FLAGS:
- priv->flags = g_value_get_flags (value);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- }
-}
-
-static void
-meta_screen_cast_stream_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- MetaScreenCastStream *stream = META_SCREEN_CAST_STREAM (object);
- MetaScreenCastStreamPrivate *priv =
- meta_screen_cast_stream_get_instance_private (stream);
-
- switch (prop_id)
- {
- case PROP_SESSION:
- g_value_set_object (value, priv->session);
- break;
- case PROP_CONNECTION:
- g_value_set_object (value, priv->connection);
- break;
- case PROP_CURSOR_MODE:
- g_value_set_uint (value, priv->cursor_mode);
- break;
- case PROP_FLAGS:
- g_value_set_flags (value, priv->flags);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- }
-}
-
-static void
-meta_screen_cast_stream_finalize (GObject *object)
-{
- MetaScreenCastStream *stream = META_SCREEN_CAST_STREAM (object);
- MetaScreenCastStreamPrivate *priv =
- meta_screen_cast_stream_get_instance_private (stream);
-
- if (priv->src)
- meta_screen_cast_stream_close (stream);
-
- g_clear_pointer (&priv->object_path, g_free);
-
- G_OBJECT_CLASS (meta_screen_cast_stream_parent_class)->finalize (object);
-}
-
-static gboolean
-meta_screen_cast_stream_initable_init (GInitable *initable,
- GCancellable *cancellable,
- GError **error)
-{
- MetaScreenCastStream *stream = META_SCREEN_CAST_STREAM (initable);
- MetaDBusScreenCastStream *skeleton = META_DBUS_SCREEN_CAST_STREAM (stream);
- MetaScreenCastStreamPrivate *priv =
- meta_screen_cast_stream_get_instance_private (stream);
- GVariantBuilder parameters_builder;
- GVariant *parameters_variant;
- static unsigned int global_stream_number = 0;
-
- g_variant_builder_init (&parameters_builder, G_VARIANT_TYPE_VARDICT);
- meta_screen_cast_stream_set_parameters (stream, &parameters_builder);
-
- parameters_variant = g_variant_builder_end (&parameters_builder);
- meta_dbus_screen_cast_stream_set_parameters (skeleton, parameters_variant);
-
- priv->object_path =
- g_strdup_printf (META_SCREEN_CAST_STREAM_DBUS_PATH "/u%u",
- ++global_stream_number);
- if (!g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (stream),
- priv->connection,
- priv->object_path,
- error))
- return FALSE;
-
- return TRUE;
-}
-
-static void
-meta_screen_cast_stream_init_initable_iface (GInitableIface *iface)
-{
- iface->init = meta_screen_cast_stream_initable_init;
-}
-
-static void
-meta_screen_cast_stream_init (MetaScreenCastStream *stream)
-{
-}
-
-static void
-meta_screen_cast_stream_class_init (MetaScreenCastStreamClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- object_class->finalize = meta_screen_cast_stream_finalize;
- object_class->set_property = meta_screen_cast_stream_set_property;
- object_class->get_property = meta_screen_cast_stream_get_property;
-
- g_object_class_install_property (object_class,
- PROP_SESSION,
- g_param_spec_object ("session",
- "session",
- "MetaScreenSession",
- META_TYPE_SCREEN_CAST_SESSION,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT_ONLY |
- G_PARAM_STATIC_STRINGS));
-
- g_object_class_install_property (object_class,
- PROP_CONNECTION,
- g_param_spec_object ("connection",
- "connection",
- "GDBus connection",
- G_TYPE_DBUS_CONNECTION,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT_ONLY |
- G_PARAM_STATIC_STRINGS));
-
- g_object_class_install_property (object_class,
- PROP_CURSOR_MODE,
- g_param_spec_uint ("cursor-mode",
- "cursor-mode",
- "Cursor mode",
- META_SCREEN_CAST_CURSOR_MODE_HIDDEN,
- META_SCREEN_CAST_CURSOR_MODE_METADATA,
- META_SCREEN_CAST_CURSOR_MODE_HIDDEN,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT_ONLY |
- G_PARAM_STATIC_STRINGS));
-
- g_object_class_install_property (object_class,
- PROP_FLAGS,
- g_param_spec_flags ("flags",
- "flags",
- "Screen cast flags",
- META_TYPE_SCREEN_CAST_FLAG,
- META_SCREEN_CAST_FLAG_NONE,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT_ONLY |
- G_PARAM_STATIC_STRINGS));
-
- signals[CLOSED] = g_signal_new ("closed",
- G_TYPE_FROM_CLASS (klass),
- G_SIGNAL_RUN_LAST,
- 0,
- NULL, NULL, NULL,
- G_TYPE_NONE, 0);
-}
diff --git a/src/backends/meta-screen-cast-stream.h b/src/backends/meta-screen-cast-stream.h
deleted file mode 100644
index 3424def20..000000000
--- a/src/backends/meta-screen-cast-stream.h
+++ /dev/null
@@ -1,74 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2017 Red Hat Inc.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- */
-
-#ifndef META_SCREEN_CAST_STREAM_H
-#define META_SCREEN_CAST_STREAM_H
-
-#include <glib-object.h>
-
-#include "backends/meta-screen-cast-stream-src.h"
-#include "backends/meta-screen-cast.h"
-
-#include "meta-dbus-screen-cast.h"
-
-#define META_TYPE_SCREEN_CAST_STREAM (meta_screen_cast_stream_get_type ())
-G_DECLARE_DERIVABLE_TYPE (MetaScreenCastStream, meta_screen_cast_stream,
- META, SCREEN_CAST_STREAM,
- MetaDBusScreenCastStreamSkeleton)
-
-struct _MetaScreenCastStreamClass
-{
- MetaDBusScreenCastStreamSkeletonClass parent_class;
-
- MetaScreenCastStreamSrc * (* create_src) (MetaScreenCastStream *stream,
- GError **error);
- void (* set_parameters) (MetaScreenCastStream *stream,
- GVariantBuilder *parameters_builder);
- gboolean (* transform_position) (MetaScreenCastStream *stream,
- double stream_x,
- double stream_y,
- double *x,
- double *y);
-};
-
-MetaScreenCastSession * meta_screen_cast_stream_get_session (MetaScreenCastStream *stream);
-
-gboolean meta_screen_cast_stream_start (MetaScreenCastStream *stream,
- GError **error);
-
-void meta_screen_cast_stream_close (MetaScreenCastStream *stream);
-
-char * meta_screen_cast_stream_get_object_path (MetaScreenCastStream *stream);
-
-MetaScreenCastStreamSrc * meta_screen_cast_stream_get_src (MetaScreenCastStream *stream);
-
-gboolean meta_screen_cast_stream_transform_position (MetaScreenCastStream *stream,
- double stream_x,
- double stream_y,
- double *x,
- double *y);
-
-MetaScreenCastCursorMode meta_screen_cast_stream_get_cursor_mode (MetaScreenCastStream *stream);
-
-MetaScreenCastFlag meta_screen_cast_stream_get_flags (MetaScreenCastStream *stream);
-
-#endif /* META_SCREEN_CAST_STREAM_H */
diff --git a/src/backends/meta-screen-cast-virtual-stream-src.c b/src/backends/meta-screen-cast-virtual-stream-src.c
deleted file mode 100644
index 47a917da9..000000000
--- a/src/backends/meta-screen-cast-virtual-stream-src.c
+++ /dev/null
@@ -1,612 +0,0 @@
-/*
- * Copyright (C) 2021 Red Hat Inc.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- */
-
-#include "config.h"
-
-#include "backends/meta-screen-cast-virtual-stream-src.h"
-
-#include "backends/meta-crtc-mode.h"
-#include "backends/meta-cursor-tracker-private.h"
-#include "backends/meta-screen-cast-session.h"
-#include "backends/meta-stage-private.h"
-#include "backends/meta-virtual-monitor.h"
-#include "core/boxes-private.h"
-
-struct _MetaScreenCastVirtualStreamSrc
-{
- MetaScreenCastStreamSrc parent;
-
- MetaVirtualMonitor *virtual_monitor;
-
- gboolean cursor_bitmap_invalid;
- gboolean hw_cursor_inhibited;
-
- MetaStageWatch *watch;
-
- gulong position_invalidated_handler_id;
- gulong cursor_changed_handler_id;
-
- gulong monitors_changed_handler_id;
-};
-
-static void
-hw_cursor_inhibitor_iface_init (MetaHwCursorInhibitorInterface *iface);
-
-G_DEFINE_TYPE_WITH_CODE (MetaScreenCastVirtualStreamSrc,
- meta_screen_cast_virtual_stream_src,
- META_TYPE_SCREEN_CAST_STREAM_SRC,
- G_IMPLEMENT_INTERFACE (META_TYPE_HW_CURSOR_INHIBITOR,
- hw_cursor_inhibitor_iface_init))
-
-static gboolean
-meta_screen_cast_virtual_stream_src_get_specs (MetaScreenCastStreamSrc *src,
- int *width,
- int *height,
- float *frame_rate)
-{
- return FALSE;
-}
-
-static MetaBackend *
-backend_from_src (MetaScreenCastStreamSrc *src)
-{
- MetaScreenCastStream *stream = meta_screen_cast_stream_src_get_stream (src);
- MetaScreenCastSession *session = meta_screen_cast_stream_get_session (stream);
- MetaScreenCast *screen_cast =
- meta_screen_cast_session_get_screen_cast (session);
-
- return meta_screen_cast_get_backend (screen_cast);
-}
-
-static ClutterStageView *
-view_from_src (MetaScreenCastStreamSrc *src)
-{
- MetaScreenCastVirtualStreamSrc *virtual_src =
- META_SCREEN_CAST_VIRTUAL_STREAM_SRC (src);
- MetaVirtualMonitor *virtual_monitor = virtual_src->virtual_monitor;
- MetaCrtc *crtc = meta_virtual_monitor_get_crtc (virtual_monitor);
- MetaRenderer *renderer = meta_backend_get_renderer (backend_from_src (src));
- MetaRendererView *view = meta_renderer_get_view_for_crtc (renderer, crtc);
-
- return CLUTTER_STAGE_VIEW (view);
-}
-
-static ClutterStage *
-stage_from_src (MetaScreenCastStreamSrc *src)
-{
- return CLUTTER_STAGE (meta_backend_get_stage (backend_from_src (src)));
-}
-
-static gboolean
-is_redraw_queued (MetaScreenCastVirtualStreamSrc *virtual_src)
-{
- MetaScreenCastStreamSrc *src = META_SCREEN_CAST_STREAM_SRC (virtual_src);
-
- return clutter_stage_is_redraw_queued_on_view (stage_from_src (src),
- view_from_src (src));
-}
-
-ClutterStageView *
-meta_screen_cast_virtual_stream_src_get_view (MetaScreenCastVirtualStreamSrc *virtual_src)
-{
- return view_from_src (META_SCREEN_CAST_STREAM_SRC (virtual_src));
-}
-
-static void
-sync_cursor_state (MetaScreenCastVirtualStreamSrc *virtual_src)
-{
- MetaScreenCastStreamSrc *src = META_SCREEN_CAST_STREAM_SRC (virtual_src);
- MetaScreenCastRecordFlag flags;
-
- if (is_redraw_queued (virtual_src))
- return;
-
- if (meta_screen_cast_stream_src_pending_follow_up_frame (src))
- return;
-
- flags = META_SCREEN_CAST_RECORD_FLAG_CURSOR_ONLY;
- meta_screen_cast_stream_src_maybe_record_frame (src, flags);
-}
-
-static void
-pointer_position_invalidated (MetaCursorTracker *cursor_tracker,
- MetaScreenCastVirtualStreamSrc *virtual_src)
-{
- sync_cursor_state (virtual_src);
-}
-
-static void
-cursor_changed (MetaCursorTracker *cursor_tracker,
- MetaScreenCastVirtualStreamSrc *virtual_src)
-{
- virtual_src->cursor_bitmap_invalid = TRUE;
- sync_cursor_state (virtual_src);
-}
-
-static void
-inhibit_hw_cursor (MetaScreenCastVirtualStreamSrc *virtual_src)
-{
- MetaHwCursorInhibitor *inhibitor;
- MetaBackend *backend;
-
- g_return_if_fail (!virtual_src->hw_cursor_inhibited);
-
- backend = backend_from_src (META_SCREEN_CAST_STREAM_SRC (virtual_src));
- inhibitor = META_HW_CURSOR_INHIBITOR (virtual_src);
- meta_backend_add_hw_cursor_inhibitor (backend, inhibitor);
-
- virtual_src->hw_cursor_inhibited = TRUE;
-}
-
-static void
-uninhibit_hw_cursor (MetaScreenCastVirtualStreamSrc *virtual_src)
-{
- MetaHwCursorInhibitor *inhibitor;
- MetaBackend *backend;
-
- g_return_if_fail (virtual_src->hw_cursor_inhibited);
-
- backend = backend_from_src (META_SCREEN_CAST_STREAM_SRC (virtual_src));
- inhibitor = META_HW_CURSOR_INHIBITOR (virtual_src);
- meta_backend_remove_hw_cursor_inhibitor (backend, inhibitor);
-
- virtual_src->hw_cursor_inhibited = FALSE;
-}
-
-static void
-actors_painted (MetaStage *stage,
- ClutterStageView *view,
- ClutterPaintContext *paint_context,
- gpointer user_data)
-{
- MetaScreenCastStreamSrc *src = META_SCREEN_CAST_STREAM_SRC (user_data);
- MetaScreenCastRecordFlag flags;
-
- flags = META_SCREEN_CAST_RECORD_FLAG_NONE;
- meta_screen_cast_stream_src_maybe_record_frame (src, flags);
-}
-
-static void
-add_watch (MetaScreenCastVirtualStreamSrc *virtual_src)
-{
- MetaScreenCastStreamSrc *src = META_SCREEN_CAST_STREAM_SRC (virtual_src);
- MetaStage *meta_stage = META_STAGE (stage_from_src (src));
-
- g_return_if_fail (!virtual_src->watch);
-
- virtual_src->watch = meta_stage_watch_view (meta_stage,
- view_from_src (src),
- META_STAGE_WATCH_AFTER_PAINT,
- actors_painted,
- virtual_src);
-}
-
-static void
-on_monitors_changed (MetaMonitorManager *monitor_manager,
- MetaScreenCastVirtualStreamSrc *virtual_src)
-{
- MetaScreenCastStreamSrc *src = META_SCREEN_CAST_STREAM_SRC (virtual_src);
- MetaStage *stage = META_STAGE (stage_from_src (src));
-
- meta_stage_remove_watch (stage, virtual_src->watch);
- virtual_src->watch = NULL;
- add_watch (virtual_src);
-}
-
-static void
-init_record_callbacks (MetaScreenCastVirtualStreamSrc *virtual_src)
-{
- MetaScreenCastStreamSrc *src = META_SCREEN_CAST_STREAM_SRC (virtual_src);
- MetaScreenCastStream *stream = meta_screen_cast_stream_src_get_stream (src);
- MetaBackend *backend = backend_from_src (src);
- MetaMonitorManager *monitor_manager =
- meta_backend_get_monitor_manager (backend);
- MetaCursorTracker *cursor_tracker =
- meta_backend_get_cursor_tracker (backend);
-
- switch (meta_screen_cast_stream_get_cursor_mode (stream))
- {
- case META_SCREEN_CAST_CURSOR_MODE_METADATA:
- virtual_src->position_invalidated_handler_id =
- g_signal_connect_after (cursor_tracker, "position-invalidated",
- G_CALLBACK (pointer_position_invalidated),
- virtual_src);
- virtual_src->cursor_changed_handler_id =
- g_signal_connect_after (cursor_tracker, "cursor-changed",
- G_CALLBACK (cursor_changed),
- virtual_src);
- G_GNUC_FALLTHROUGH;
- case META_SCREEN_CAST_CURSOR_MODE_EMBEDDED:
- case META_SCREEN_CAST_CURSOR_MODE_HIDDEN:
- add_watch (virtual_src);
- break;
- }
-
- if (meta_screen_cast_stream_get_cursor_mode (stream) ==
- META_SCREEN_CAST_CURSOR_MODE_EMBEDDED)
- inhibit_hw_cursor (virtual_src);
-
- virtual_src->monitors_changed_handler_id =
- g_signal_connect (monitor_manager, "monitors-changed-internal",
- G_CALLBACK (on_monitors_changed),
- virtual_src);
-}
-
-static void
-meta_screen_cast_virtual_stream_src_enable (MetaScreenCastStreamSrc *src)
-{
- MetaScreenCastVirtualStreamSrc *virtual_src =
- META_SCREEN_CAST_VIRTUAL_STREAM_SRC (src);
- MetaScreenCastStream *stream = meta_screen_cast_stream_src_get_stream (src);
- MetaBackend *backend = backend_from_src (src);
- MetaCursorTracker *cursor_tracker = meta_backend_get_cursor_tracker (backend);
-
- switch (meta_screen_cast_stream_get_cursor_mode (stream))
- {
- case META_SCREEN_CAST_CURSOR_MODE_METADATA:
- case META_SCREEN_CAST_CURSOR_MODE_EMBEDDED:
- meta_cursor_tracker_track_position (cursor_tracker);
- break;
- case META_SCREEN_CAST_CURSOR_MODE_HIDDEN:
- break;
- }
-
- init_record_callbacks (virtual_src);
- clutter_actor_queue_redraw_with_clip (CLUTTER_ACTOR (stage_from_src (src)),
- NULL);
- clutter_stage_schedule_update (stage_from_src (src));
-}
-
-static void
-meta_screen_cast_virtual_stream_src_disable (MetaScreenCastStreamSrc *src)
-{
- MetaScreenCastVirtualStreamSrc *virtual_src =
- META_SCREEN_CAST_VIRTUAL_STREAM_SRC (src);
- MetaScreenCastStream *stream = meta_screen_cast_stream_src_get_stream (src);
- MetaBackend *backend = backend_from_src (src);
- MetaCursorTracker *cursor_tracker = meta_backend_get_cursor_tracker (backend);
- MetaMonitorManager *monitor_manager =
- meta_backend_get_monitor_manager (backend);
-
- if (virtual_src->hw_cursor_inhibited)
- uninhibit_hw_cursor (virtual_src);
-
- if (virtual_src->watch)
- {
- meta_stage_remove_watch (META_STAGE (stage_from_src (src)),
- virtual_src->watch);
- virtual_src->watch = NULL;
- }
-
- g_clear_signal_handler (&virtual_src->position_invalidated_handler_id,
- cursor_tracker);
- g_clear_signal_handler (&virtual_src->cursor_changed_handler_id,
- cursor_tracker);
-
- g_clear_signal_handler (&virtual_src->monitors_changed_handler_id,
- monitor_manager);
-
- switch (meta_screen_cast_stream_get_cursor_mode (stream))
- {
- case META_SCREEN_CAST_CURSOR_MODE_METADATA:
- case META_SCREEN_CAST_CURSOR_MODE_EMBEDDED:
- meta_cursor_tracker_untrack_position (cursor_tracker);
- break;
- case META_SCREEN_CAST_CURSOR_MODE_HIDDEN:
- break;
- }
-
- g_clear_object (&virtual_src->virtual_monitor);
-}
-
-static gboolean
-meta_screen_cast_virtual_stream_src_record_to_buffer (MetaScreenCastStreamSrc *src,
- int width,
- int height,
- int stride,
- uint8_t *data,
- GError **error)
-{
- clutter_stage_capture_view_into (stage_from_src (src),
- view_from_src (src),
- NULL,
- data,
- stride);
-
- return TRUE;
-}
-
-static gboolean
-meta_screen_cast_virtual_stream_src_record_to_framebuffer (MetaScreenCastStreamSrc *src,
- CoglFramebuffer *framebuffer,
- GError **error)
-{
- ClutterStageView *view;
- CoglFramebuffer *view_framebuffer;
-
- view = view_from_src (src);
- view_framebuffer = clutter_stage_view_get_framebuffer (view);
- if (!cogl_blit_framebuffer (view_framebuffer,
- framebuffer,
- 0, 0,
- 0, 0,
- cogl_framebuffer_get_width (view_framebuffer),
- cogl_framebuffer_get_height (view_framebuffer),
- error))
- return FALSE;
-
- cogl_framebuffer_flush (framebuffer);
- return TRUE;
-}
-
-static void
-meta_screen_cast_virtual_stream_record_follow_up (MetaScreenCastStreamSrc *src)
-{
- MetaRectangle damage;
-
- clutter_stage_view_get_layout (view_from_src (src), &damage);
- damage.width = 1;
- damage.height = 1;
-
- clutter_actor_queue_redraw_with_clip (CLUTTER_ACTOR (stage_from_src (src)),
- &damage);
-}
-
-static gboolean
-is_cursor_in_stream (MetaScreenCastVirtualStreamSrc *virtual_src)
-{
- MetaScreenCastStreamSrc *src = META_SCREEN_CAST_STREAM_SRC (virtual_src);
- MetaBackend *backend = backend_from_src (src);
- MetaCursorRenderer *cursor_renderer =
- meta_backend_get_cursor_renderer (backend);
- ClutterStageView *stage_view = view_from_src (src);
- MetaRectangle view_layout;
- graphene_rect_t view_rect;
- MetaCursorSprite *cursor_sprite;
-
- clutter_stage_view_get_layout (stage_view, &view_layout);
- view_rect = meta_rectangle_to_graphene_rect (&view_layout);
-
- cursor_sprite = meta_cursor_renderer_get_cursor (cursor_renderer);
- if (cursor_sprite)
- {
- graphene_rect_t cursor_rect;
-
- cursor_rect = meta_cursor_renderer_calculate_rect (cursor_renderer,
- cursor_sprite);
- return graphene_rect_intersection (&cursor_rect, &view_rect, NULL);
- }
- else
- {
- MetaCursorTracker *cursor_tracker =
- meta_backend_get_cursor_tracker (backend);
- graphene_point_t cursor_position;
-
- meta_cursor_tracker_get_pointer (cursor_tracker, &cursor_position, NULL);
- return graphene_rect_contains_point (&view_rect,
- &cursor_position);
- }
-}
-
-static void
-meta_screen_cast_virtual_stream_src_set_cursor_metadata (MetaScreenCastStreamSrc *src,
- struct spa_meta_cursor *spa_meta_cursor)
-{
- MetaScreenCastVirtualStreamSrc *virtual_src =
- META_SCREEN_CAST_VIRTUAL_STREAM_SRC (src);
- MetaBackend *backend = backend_from_src (src);
- MetaCursorRenderer *cursor_renderer =
- meta_backend_get_cursor_renderer (backend);
- MetaCursorTracker *cursor_tracker =
- meta_backend_get_cursor_tracker (backend);
- MetaCursorSprite *cursor_sprite;
- ClutterStageView *stage_view;
- MetaRectangle view_layout;
- float view_scale;
- graphene_rect_t view_rect;
- graphene_point_t cursor_position;
- int x, y;
-
- cursor_sprite = meta_cursor_renderer_get_cursor (cursor_renderer);
-
- if (!meta_cursor_tracker_get_pointer_visible (cursor_tracker) ||
- !is_cursor_in_stream (virtual_src))
- {
- meta_screen_cast_stream_src_unset_cursor_metadata (src,
- spa_meta_cursor);
- return;
- }
-
- stage_view = view_from_src (src);
- clutter_stage_view_get_layout (stage_view, &view_layout);
- view_rect = meta_rectangle_to_graphene_rect (&view_layout);
- view_scale = clutter_stage_view_get_scale (stage_view);
-
- meta_cursor_tracker_get_pointer (cursor_tracker, &cursor_position, NULL);
- cursor_position.x -= view_rect.origin.x;
- cursor_position.y -= view_rect.origin.y;
- cursor_position.x *= view_scale;
- cursor_position.y *= view_scale;
-
- x = (int) roundf (cursor_position.x);
- y = (int) roundf (cursor_position.y);
-
- if (virtual_src->cursor_bitmap_invalid)
- {
- if (cursor_sprite)
- {
- float cursor_scale;
- float scale;
-
- cursor_scale = meta_cursor_sprite_get_texture_scale (cursor_sprite);
- scale = view_scale * cursor_scale;
- meta_screen_cast_stream_src_set_cursor_sprite_metadata (src,
- spa_meta_cursor,
- cursor_sprite,
- x, y,
- scale);
- }
- else
- {
- meta_screen_cast_stream_src_set_empty_cursor_sprite_metadata (src,
- spa_meta_cursor,
- x, y);
- }
-
- virtual_src->cursor_bitmap_invalid = FALSE;
- }
- else
- {
- meta_screen_cast_stream_src_set_cursor_position_metadata (src,
- spa_meta_cursor,
- x, y);
- }
-}
-
-static MetaVirtualMonitor *
-create_virtual_monitor (MetaScreenCastVirtualStreamSrc *virtual_src,
- struct spa_video_info_raw *video_format,
- GError **error)
-{
- MetaScreenCastStreamSrc *src = META_SCREEN_CAST_STREAM_SRC (virtual_src);
- MetaBackend *backend = backend_from_src (src);
- MetaMonitorManager *monitor_manager =
- meta_backend_get_monitor_manager (backend);
- static int virtual_monitor_src_seq = 0;
- int width, height;
- float refresh_rate;
- g_autofree char *serial = NULL;
- g_autoptr (MetaVirtualMonitorInfo) info = NULL;
-
- width = video_format->size.width;
- height = video_format->size.height;
- refresh_rate = ((float) video_format->max_framerate.num /
- video_format->max_framerate.denom);
- serial = g_strdup_printf ("0x%.6x", ++virtual_monitor_src_seq);
- info = meta_virtual_monitor_info_new (width, height, refresh_rate,
- "MetaVendor",
- "Virtual remote monitor",
- serial);
- return meta_monitor_manager_create_virtual_monitor (monitor_manager,
- info,
- error);
-}
-
-static void
-ensure_virtual_monitor (MetaScreenCastVirtualStreamSrc *virtual_src,
- struct spa_video_info_raw *video_format)
-{
- MetaScreenCastStreamSrc *src = META_SCREEN_CAST_STREAM_SRC (virtual_src);
- MetaBackend *backend = backend_from_src (src);
- MetaMonitorManager *monitor_manager =
- meta_backend_get_monitor_manager (backend);
- g_autoptr (GError) error = NULL;
- MetaVirtualMonitor *virtual_monitor;
-
- virtual_monitor = virtual_src->virtual_monitor;
- if (virtual_monitor)
- {
- MetaCrtcMode *crtc_mode =
- meta_virtual_monitor_get_crtc_mode (virtual_monitor);
- const MetaCrtcModeInfo *mode_info = meta_crtc_mode_get_info (crtc_mode);
-
- if (mode_info->width == video_format->size.width &&
- mode_info->height == video_format->size.height)
- return;
-
- g_clear_object (&virtual_src->virtual_monitor);
- }
-
- virtual_monitor = create_virtual_monitor (virtual_src, video_format, &error);
- if (!virtual_monitor)
- {
- MetaScreenCastStreamSrc *src = META_SCREEN_CAST_STREAM_SRC (virtual_src);
-
- g_warning ("Failed to create virtual monitor with size %dx%d: %s",
- video_format->size.width, video_format->size.height,
- error->message);
- meta_screen_cast_stream_src_close (src);
- return;
- }
- virtual_src->virtual_monitor = virtual_monitor;
-
- meta_monitor_manager_reload (monitor_manager);
-}
-
-static void
-meta_screen_cast_virtual_stream_src_notify_params_updated (MetaScreenCastStreamSrc *src,
- struct spa_video_info_raw *video_format)
-{
- MetaScreenCastVirtualStreamSrc *virtual_src =
- META_SCREEN_CAST_VIRTUAL_STREAM_SRC (src);
-
- ensure_virtual_monitor (virtual_src, video_format);
-}
-
-MetaScreenCastVirtualStreamSrc *
-meta_screen_cast_virtual_stream_src_new (MetaScreenCastVirtualStream *virtual_stream,
- GError **error)
-{
- return g_initable_new (META_TYPE_SCREEN_CAST_VIRTUAL_STREAM_SRC, NULL, error,
- "stream", virtual_stream,
- NULL);
-}
-
-static gboolean
-meta_screen_cast_virtual_stream_src_is_cursor_inhibited (MetaHwCursorInhibitor *inhibitor)
-{
- MetaScreenCastVirtualStreamSrc *virtual_src =
- META_SCREEN_CAST_VIRTUAL_STREAM_SRC (inhibitor);
-
- return is_cursor_in_stream (virtual_src);
-}
-
-static void
-hw_cursor_inhibitor_iface_init (MetaHwCursorInhibitorInterface *iface)
-{
- iface->is_cursor_inhibited =
- meta_screen_cast_virtual_stream_src_is_cursor_inhibited;
-}
-
-static void
-meta_screen_cast_virtual_stream_src_init (MetaScreenCastVirtualStreamSrc *virtual_src)
-{
-}
-
-static void
-meta_screen_cast_virtual_stream_src_class_init (MetaScreenCastVirtualStreamSrcClass *klass)
-{
- MetaScreenCastStreamSrcClass *src_class =
- META_SCREEN_CAST_STREAM_SRC_CLASS (klass);
-
- src_class->get_specs = meta_screen_cast_virtual_stream_src_get_specs;
- src_class->enable = meta_screen_cast_virtual_stream_src_enable;
- src_class->disable = meta_screen_cast_virtual_stream_src_disable;
- src_class->record_to_buffer =
- meta_screen_cast_virtual_stream_src_record_to_buffer;
- src_class->record_to_framebuffer =
- meta_screen_cast_virtual_stream_src_record_to_framebuffer;
- src_class->record_follow_up =
- meta_screen_cast_virtual_stream_record_follow_up;
- src_class->set_cursor_metadata =
- meta_screen_cast_virtual_stream_src_set_cursor_metadata;
- src_class->notify_params_updated =
- meta_screen_cast_virtual_stream_src_notify_params_updated;
-}
diff --git a/src/backends/meta-screen-cast-virtual-stream-src.h b/src/backends/meta-screen-cast-virtual-stream-src.h
deleted file mode 100644
index a891166bd..000000000
--- a/src/backends/meta-screen-cast-virtual-stream-src.h
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright (C) 2021 Red Hat Inc.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- */
-
-#ifndef META_SCREEN_CAST_VIRTUAL_STREAM_SRC_H
-#define META_SCREEN_CAST_VIRTUAL_STREAM_SRC_H
-
-#include "backends/meta-screen-cast-stream-src.h"
-#include "backends/meta-screen-cast-virtual-stream.h"
-
-#define META_TYPE_SCREEN_CAST_VIRTUAL_STREAM_SRC (meta_screen_cast_virtual_stream_src_get_type ())
-G_DECLARE_FINAL_TYPE (MetaScreenCastVirtualStreamSrc,
- meta_screen_cast_virtual_stream_src,
- META, SCREEN_CAST_VIRTUAL_STREAM_SRC,
- MetaScreenCastStreamSrc)
-
-MetaScreenCastVirtualStreamSrc * meta_screen_cast_virtual_stream_src_new (MetaScreenCastVirtualStream *virtual_stream,
- GError **error);
-
-ClutterStageView * meta_screen_cast_virtual_stream_src_get_view (MetaScreenCastVirtualStreamSrc *virtual_src);
-
-#endif /* META_SCREEN_CAST_VIRTUAL_STREAM_SRC_H */
diff --git a/src/backends/meta-screen-cast-virtual-stream.c b/src/backends/meta-screen-cast-virtual-stream.c
deleted file mode 100644
index 34dd2a00c..000000000
--- a/src/backends/meta-screen-cast-virtual-stream.c
+++ /dev/null
@@ -1,121 +0,0 @@
-/*
- * Copyright (C) 2021 Red Hat Inc.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- */
-
-#include "config.h"
-
-#include "backends/meta-screen-cast-virtual-stream.h"
-
-#include "backends/meta-screen-cast-virtual-stream-src.h"
-#include "backends/meta-virtual-monitor.h"
-
-
-struct _MetaScreenCastVirtualStream
-{
- MetaScreenCastStream parent;
-};
-
-G_DEFINE_TYPE (MetaScreenCastVirtualStream,
- meta_screen_cast_virtual_stream,
- META_TYPE_SCREEN_CAST_STREAM)
-
-MetaScreenCastVirtualStream *
-meta_screen_cast_virtual_stream_new (MetaScreenCastSession *session,
- GDBusConnection *connection,
- MetaScreenCastCursorMode cursor_mode,
- MetaScreenCastFlag flags,
- GError **error)
-{
- MetaScreenCastVirtualStream *virtual_stream;
-
- virtual_stream = g_initable_new (META_TYPE_SCREEN_CAST_VIRTUAL_STREAM,
- NULL,
- error,
- "session", session,
- "connection", connection,
- "cursor-mode", cursor_mode,
- "flags", flags,
- NULL);
- if (!virtual_stream)
- return NULL;
-
- return virtual_stream;
-}
-
-static MetaScreenCastStreamSrc *
-meta_screen_cast_virtual_stream_create_src (MetaScreenCastStream *stream,
- GError **error)
-{
- MetaScreenCastVirtualStream *virtual_stream =
- META_SCREEN_CAST_VIRTUAL_STREAM (stream);
- MetaScreenCastVirtualStreamSrc *virtual_stream_src;
-
- virtual_stream_src = meta_screen_cast_virtual_stream_src_new (virtual_stream,
- error);
- if (!virtual_stream_src)
- return NULL;
-
- return META_SCREEN_CAST_STREAM_SRC (virtual_stream_src);
-}
-
-static void
-meta_screen_cast_virtual_stream_set_parameters (MetaScreenCastStream *stream,
- GVariantBuilder *parameters_builder)
-{
-}
-
-static gboolean
-meta_screen_cast_virtual_stream_transform_position (MetaScreenCastStream *stream,
- double stream_x,
- double stream_y,
- double *x,
- double *y)
-{
- MetaScreenCastStreamSrc *src = meta_screen_cast_stream_get_src (stream);
- MetaScreenCastVirtualStreamSrc *virtual_src =
- META_SCREEN_CAST_VIRTUAL_STREAM_SRC (src);
- ClutterStageView *view;
- MetaRectangle view_layout;
-
- view = meta_screen_cast_virtual_stream_src_get_view (virtual_src);
- if (!view)
- return FALSE;
-
- clutter_stage_view_get_layout (view, &view_layout);
- *x = stream_x + view_layout.x;
- *y = stream_y + view_layout.y;
-
- return TRUE;
-}
-
-static void
-meta_screen_cast_virtual_stream_init (MetaScreenCastVirtualStream *virtual_stream)
-{
-}
-
-static void
-meta_screen_cast_virtual_stream_class_init (MetaScreenCastVirtualStreamClass *klass)
-{
- MetaScreenCastStreamClass *stream_class =
- META_SCREEN_CAST_STREAM_CLASS (klass);
-
- stream_class->create_src = meta_screen_cast_virtual_stream_create_src;
- stream_class->set_parameters = meta_screen_cast_virtual_stream_set_parameters;
- stream_class->transform_position = meta_screen_cast_virtual_stream_transform_position;
-}
diff --git a/src/backends/meta-screen-cast-virtual-stream.h b/src/backends/meta-screen-cast-virtual-stream.h
deleted file mode 100644
index 422db5e26..000000000
--- a/src/backends/meta-screen-cast-virtual-stream.h
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright (C) 2021 Red Hat Inc.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- */
-
-#ifndef META_SCREEN_CAST_VIRTUAL_STREAM_H
-#define META_SCREEN_CAST_VIRTUAL_STREAM_H
-
-#include "backends/meta-screen-cast-stream.h"
-
-#define META_TYPE_SCREEN_CAST_VIRTUAL_STREAM (meta_screen_cast_virtual_stream_get_type ())
-G_DECLARE_FINAL_TYPE (MetaScreenCastVirtualStream,
- meta_screen_cast_virtual_stream,
- META, SCREEN_CAST_VIRTUAL_STREAM,
- MetaScreenCastStream)
-
-MetaScreenCastVirtualStream * meta_screen_cast_virtual_stream_new (MetaScreenCastSession *session,
- GDBusConnection *connection,
- MetaScreenCastCursorMode cursor_mode,
- MetaScreenCastFlag flags,
- GError **error);
-
-MetaVirtualMonitor * meta_screen_cast_virtual_stream_get_virtual_monitor (MetaScreenCastVirtualStream *virtual_stream);
-
-#endif /* META_SCREEN_CAST_VIRTUAL_STREAM_H */
diff --git a/src/backends/meta-screen-cast-window-stream-src.c b/src/backends/meta-screen-cast-window-stream-src.c
deleted file mode 100644
index 3fa932b4b..000000000
--- a/src/backends/meta-screen-cast-window-stream-src.c
+++ /dev/null
@@ -1,614 +0,0 @@
-/*
- * Copyright (C) 2018 Red Hat Inc.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- */
-
-#include "config.h"
-
-#include "backends/meta-screen-cast-window-stream-src.h"
-
-#include "backends/meta-backend-private.h"
-#include "backends/meta-cursor-tracker-private.h"
-#include "backends/meta-screen-cast-session.h"
-#include "backends/meta-screen-cast-window.h"
-#include "backends/meta-screen-cast-window-stream.h"
-#include "compositor/meta-window-actor-private.h"
-
-struct _MetaScreenCastWindowStreamSrc
-{
- MetaScreenCastStreamSrc parent;
-
- MetaScreenCastWindow *screen_cast_window;
-
- unsigned long screen_cast_window_damaged_handler_id;
- unsigned long screen_cast_window_destroyed_handler_id;
- unsigned long position_invalidated_handler_id;
- unsigned long cursor_changed_handler_id;
-
- gboolean cursor_bitmap_invalid;
-};
-
-G_DEFINE_TYPE (MetaScreenCastWindowStreamSrc,
- meta_screen_cast_window_stream_src,
- META_TYPE_SCREEN_CAST_STREAM_SRC)
-
-static MetaBackend *
-get_backend (MetaScreenCastWindowStreamSrc *window_src)
-{
- MetaScreenCastStreamSrc *src = META_SCREEN_CAST_STREAM_SRC (window_src);
- MetaScreenCastStream *stream = meta_screen_cast_stream_src_get_stream (src);
- MetaScreenCastSession *session = meta_screen_cast_stream_get_session (stream);
- MetaScreenCast *screen_cast =
- meta_screen_cast_session_get_screen_cast (session);
-
- return meta_screen_cast_get_backend (screen_cast);
-}
-
-static MetaScreenCastWindowStream *
-get_window_stream (MetaScreenCastWindowStreamSrc *window_src)
-{
- MetaScreenCastStreamSrc *src;
- MetaScreenCastStream *stream;
-
- src = META_SCREEN_CAST_STREAM_SRC (window_src);
- stream = meta_screen_cast_stream_src_get_stream (src);
-
- return META_SCREEN_CAST_WINDOW_STREAM (stream);
-}
-
-static MetaWindow *
-get_window (MetaScreenCastWindowStreamSrc *window_src)
-{
- MetaScreenCastWindowStream *window_stream;
-
- window_stream = get_window_stream (window_src);
-
- return meta_screen_cast_window_stream_get_window (window_stream);
-}
-
-static int
-get_stream_width (MetaScreenCastWindowStreamSrc *window_src)
-{
- MetaScreenCastWindowStream *window_stream;
-
- window_stream = get_window_stream (window_src);
-
- return meta_screen_cast_window_stream_get_width (window_stream);
-}
-
-static int
-get_stream_height (MetaScreenCastWindowStreamSrc *window_src)
-{
- MetaScreenCastWindowStream *window_stream;
-
- window_stream = get_window_stream (window_src);
-
- return meta_screen_cast_window_stream_get_height (window_stream);
-}
-
-static void
-maybe_draw_cursor_sprite (MetaScreenCastWindowStreamSrc *window_src,
- uint8_t *data,
- MetaRectangle *stream_rect)
-{
- MetaScreenCastStreamSrc *src = META_SCREEN_CAST_STREAM_SRC (window_src);
- MetaBackend *backend = get_backend (window_src);
- MetaCursorRenderer *cursor_renderer =
- meta_backend_get_cursor_renderer (backend);
- MetaCursorTracker *cursor_tracker =
- meta_backend_get_cursor_tracker (backend);
- MetaCursorSprite *cursor_sprite;
- CoglTexture *cursor_texture;
- MetaScreenCastWindow *screen_cast_window;
- graphene_point_t cursor_position;
- graphene_point_t relative_cursor_position;
- cairo_surface_t *cursor_surface;
- uint8_t *cursor_surface_data;
- GError *error = NULL;
- cairo_surface_t *stream_surface;
- int width, height;
- float scale;
- int hotspot_x, hotspot_y;
- cairo_t *cr;
-
- cursor_sprite = meta_cursor_renderer_get_cursor (cursor_renderer);
- if (!cursor_sprite)
- return;
-
- cursor_texture = meta_cursor_sprite_get_cogl_texture (cursor_sprite);
- if (!cursor_texture)
- return;
-
- screen_cast_window = window_src->screen_cast_window;
- meta_cursor_tracker_get_pointer (cursor_tracker, &cursor_position, NULL);
- if (!meta_screen_cast_window_transform_cursor_position (screen_cast_window,
- cursor_sprite,
- &cursor_position,
- &scale,
- &relative_cursor_position))
- return;
-
- meta_cursor_sprite_get_hotspot (cursor_sprite, &hotspot_x, &hotspot_y);
-
- width = cogl_texture_get_width (cursor_texture) * scale;
- height = cogl_texture_get_height (cursor_texture) * scale;
- cursor_surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
- width, height);
-
- cursor_surface_data = cairo_image_surface_get_data (cursor_surface);
- if (!meta_screen_cast_stream_src_draw_cursor_into (src,
- cursor_texture,
- scale,
- cursor_surface_data,
- &error))
- {
- g_warning ("Failed to draw cursor: %s", error->message);
- g_error_free (error);
- cairo_surface_destroy (cursor_surface);
- return;
- }
-
- stream_surface =
- cairo_image_surface_create_for_data (data, CAIRO_FORMAT_ARGB32,
- stream_rect->width,
- stream_rect->height,
- stream_rect->width * 4);
-
- cr = cairo_create (stream_surface);
- cairo_surface_mark_dirty (cursor_surface);
- cairo_surface_flush (cursor_surface);
- cairo_set_source_surface (cr, cursor_surface,
- relative_cursor_position.x - hotspot_x * scale,
- relative_cursor_position.y - hotspot_y * scale);
- cairo_paint (cr);
- cairo_destroy (cr);
- cairo_surface_destroy (stream_surface);
- cairo_surface_destroy (cursor_surface);
-}
-
-static void
-maybe_blit_cursor_sprite (MetaScreenCastWindowStreamSrc *window_src,
- CoglFramebuffer *framebuffer,
- MetaRectangle *stream_rect)
-{
- MetaBackend *backend = get_backend (window_src);
- CoglContext *cogl_context =
- clutter_backend_get_cogl_context (clutter_get_default_backend ());
- MetaCursorRenderer *cursor_renderer =
- meta_backend_get_cursor_renderer (backend);
- MetaCursorTracker *cursor_tracker =
- meta_backend_get_cursor_tracker (backend);
- MetaScreenCastWindow *screen_cast_window;
- MetaCursorSprite *cursor_sprite;
- graphene_point_t relative_cursor_position;
- graphene_point_t cursor_position;
- CoglTexture *cursor_texture;
- CoglPipeline *pipeline;
- int width, height;
- float scale;
- int hotspot_x, hotspot_y;
- float x, y;
-
- cursor_sprite = meta_cursor_renderer_get_cursor (cursor_renderer);
- if (!cursor_sprite)
- return;
-
- cursor_texture = meta_cursor_sprite_get_cogl_texture (cursor_sprite);
- if (!cursor_texture)
- return;
-
- screen_cast_window = window_src->screen_cast_window;
- meta_cursor_tracker_get_pointer (cursor_tracker, &cursor_position, NULL);
- if (!meta_screen_cast_window_transform_cursor_position (screen_cast_window,
- cursor_sprite,
- &cursor_position,
- &scale,
- &relative_cursor_position))
- return;
-
- meta_cursor_sprite_get_hotspot (cursor_sprite, &hotspot_x, &hotspot_y);
-
- x = (relative_cursor_position.x - hotspot_x) * scale;
- y = (relative_cursor_position.y - hotspot_y) * scale;
- width = cogl_texture_get_width (cursor_texture);
- height = cogl_texture_get_height (cursor_texture);
-
- pipeline = cogl_pipeline_new (cogl_context);
- cogl_pipeline_set_layer_texture (pipeline, 0, cursor_texture);
- cogl_pipeline_set_layer_filters (pipeline, 0,
- COGL_PIPELINE_FILTER_LINEAR,
- COGL_PIPELINE_FILTER_LINEAR);
-
- cogl_framebuffer_draw_rectangle (framebuffer,
- pipeline,
- x, y,
- x + width, y + height);
-
- cogl_object_unref (pipeline);
-}
-
-static gboolean
-capture_into (MetaScreenCastWindowStreamSrc *window_src,
- int width,
- int height,
- int stride,
- uint8_t *data)
-{
- MetaScreenCastStreamSrc *src = META_SCREEN_CAST_STREAM_SRC (window_src);
- MetaRectangle stream_rect;
- MetaScreenCastStream *stream;
-
- stream_rect = (MetaRectangle) {
- .width = width,
- .height = height,
- };
-
- meta_screen_cast_window_capture_into (window_src->screen_cast_window,
- &stream_rect, data);
-
- stream = meta_screen_cast_stream_src_get_stream (src);
- switch (meta_screen_cast_stream_get_cursor_mode (stream))
- {
- case META_SCREEN_CAST_CURSOR_MODE_EMBEDDED:
- maybe_draw_cursor_sprite (window_src, data, &stream_rect);
- break;
- case META_SCREEN_CAST_CURSOR_MODE_METADATA:
- case META_SCREEN_CAST_CURSOR_MODE_HIDDEN:
- break;
- }
-
- return TRUE;
-}
-
-static gboolean
-meta_screen_cast_window_stream_src_get_specs (MetaScreenCastStreamSrc *src,
- int *width,
- int *height,
- float *frame_rate)
-{
- MetaScreenCastWindowStreamSrc *window_src =
- META_SCREEN_CAST_WINDOW_STREAM_SRC (src);
-
- *width = get_stream_width (window_src);
- *height = get_stream_height (window_src);
- *frame_rate = 60.0f;
-
- return TRUE;
-}
-
-static gboolean
-meta_screen_cast_window_stream_src_get_videocrop (MetaScreenCastStreamSrc *src,
- MetaRectangle *crop_rect)
-{
- MetaScreenCastWindowStreamSrc *window_src =
- META_SCREEN_CAST_WINDOW_STREAM_SRC (src);
- MetaRectangle stream_rect;
-
- meta_screen_cast_window_get_buffer_bounds (window_src->screen_cast_window,
- crop_rect);
-
- stream_rect.x = 0;
- stream_rect.y = 0;
- stream_rect.width = get_stream_width (window_src);
- stream_rect.height = get_stream_height (window_src);
-
- meta_rectangle_intersect (crop_rect, &stream_rect, crop_rect);
-
- return TRUE;
-}
-
-static void
-meta_screen_cast_window_stream_src_stop (MetaScreenCastWindowStreamSrc *window_src)
-
-{
- MetaScreenCastStreamSrc *src = META_SCREEN_CAST_STREAM_SRC (window_src);
- MetaScreenCastStream *stream = meta_screen_cast_stream_src_get_stream (src);
- MetaBackend *backend = get_backend (window_src);
- MetaCursorTracker *cursor_tracker = meta_backend_get_cursor_tracker (backend);
-
- if (!window_src->screen_cast_window)
- return;
-
- g_clear_signal_handler (&window_src->screen_cast_window_damaged_handler_id,
- window_src->screen_cast_window);
- g_clear_signal_handler (&window_src->screen_cast_window_destroyed_handler_id,
- window_src->screen_cast_window);
- g_clear_signal_handler (&window_src->position_invalidated_handler_id,
- cursor_tracker);
- g_clear_signal_handler (&window_src->cursor_changed_handler_id,
- cursor_tracker);
-
- switch (meta_screen_cast_stream_get_cursor_mode (stream))
- {
- case META_SCREEN_CAST_CURSOR_MODE_METADATA:
- case META_SCREEN_CAST_CURSOR_MODE_EMBEDDED:
- meta_cursor_tracker_untrack_position (cursor_tracker);
- break;
- case META_SCREEN_CAST_CURSOR_MODE_HIDDEN:
- break;
- }
-}
-
-static void
-screen_cast_window_damaged (MetaWindowActor *actor,
- MetaScreenCastWindowStreamSrc *window_src)
-{
- MetaScreenCastStreamSrc *src = META_SCREEN_CAST_STREAM_SRC (window_src);
- MetaScreenCastRecordFlag flags;
-
- flags = META_SCREEN_CAST_RECORD_FLAG_NONE;
- meta_screen_cast_stream_src_maybe_record_frame (src, flags);
-}
-
-static void
-screen_cast_window_destroyed (MetaWindowActor *actor,
- MetaScreenCastWindowStreamSrc *window_src)
-{
- meta_screen_cast_window_stream_src_stop (window_src);
- window_src->screen_cast_window = NULL;
-}
-
-static void
-sync_cursor_state (MetaScreenCastWindowStreamSrc *window_src)
-{
- MetaScreenCastStreamSrc *src = META_SCREEN_CAST_STREAM_SRC (window_src);
- MetaScreenCastRecordFlag flags;
-
- if (meta_screen_cast_window_has_damage (window_src->screen_cast_window))
- return;
-
- flags = META_SCREEN_CAST_RECORD_FLAG_CURSOR_ONLY;
- meta_screen_cast_stream_src_maybe_record_frame (src, flags);
-}
-
-static void
-pointer_position_invalidated (MetaCursorTracker *cursor_tracker,
- MetaScreenCastWindowStreamSrc *window_src)
-{
- sync_cursor_state (window_src);
-}
-
-static void
-cursor_changed (MetaCursorTracker *cursor_tracker,
- MetaScreenCastWindowStreamSrc *window_src)
-{
- window_src->cursor_bitmap_invalid = TRUE;
- sync_cursor_state (window_src);
-}
-
-static void
-meta_screen_cast_window_stream_src_enable (MetaScreenCastStreamSrc *src)
-{
- MetaScreenCastWindowStreamSrc *window_src =
- META_SCREEN_CAST_WINDOW_STREAM_SRC (src);
- MetaBackend *backend = get_backend (window_src);
- MetaCursorTracker *cursor_tracker = meta_backend_get_cursor_tracker (backend);
- MetaWindowActor *window_actor;
- MetaScreenCastStream *stream;
- MetaScreenCastRecordFlag flags;
-
- window_actor = meta_window_actor_from_window (get_window (window_src));
- if (!window_actor)
- return;
-
- window_src->screen_cast_window = META_SCREEN_CAST_WINDOW (window_actor);
-
- window_src->screen_cast_window_damaged_handler_id =
- g_signal_connect (window_src->screen_cast_window,
- "damaged",
- G_CALLBACK (screen_cast_window_damaged),
- window_src);
-
- window_src->screen_cast_window_destroyed_handler_id =
- g_signal_connect (window_src->screen_cast_window,
- "destroy",
- G_CALLBACK (screen_cast_window_destroyed),
- window_src);
-
- stream = meta_screen_cast_stream_src_get_stream (src);
- switch (meta_screen_cast_stream_get_cursor_mode (stream))
- {
- case META_SCREEN_CAST_CURSOR_MODE_METADATA:
- case META_SCREEN_CAST_CURSOR_MODE_EMBEDDED:
- window_src->position_invalidated_handler_id =
- g_signal_connect_after (cursor_tracker, "position-invalidated",
- G_CALLBACK (pointer_position_invalidated),
- window_src);
- window_src->cursor_changed_handler_id =
- g_signal_connect_after (cursor_tracker, "cursor-changed",
- G_CALLBACK (cursor_changed),
- window_src);
- meta_cursor_tracker_track_position (cursor_tracker);
- break;
- case META_SCREEN_CAST_CURSOR_MODE_HIDDEN:
- break;
- }
-
- flags = META_SCREEN_CAST_RECORD_FLAG_NONE;
- meta_screen_cast_stream_src_maybe_record_frame (src, flags);
-}
-
-static void
-meta_screen_cast_window_stream_src_disable (MetaScreenCastStreamSrc *src)
-{
- MetaScreenCastWindowStreamSrc *window_src =
- META_SCREEN_CAST_WINDOW_STREAM_SRC (src);
-
- meta_screen_cast_window_stream_src_stop (window_src);
-}
-
-static gboolean
-meta_screen_cast_window_stream_src_record_to_buffer (MetaScreenCastStreamSrc *src,
- int width,
- int height,
- int stride,
- uint8_t *data,
- GError **error)
-{
- MetaScreenCastWindowStreamSrc *window_src =
- META_SCREEN_CAST_WINDOW_STREAM_SRC (src);
-
- capture_into (window_src, width, height, stride, data);
-
- return TRUE;
-}
-
-static gboolean
-meta_screen_cast_window_stream_src_record_to_framebuffer (MetaScreenCastStreamSrc *src,
- CoglFramebuffer *framebuffer,
- GError **error)
-{
- MetaScreenCastWindowStreamSrc *window_src =
- META_SCREEN_CAST_WINDOW_STREAM_SRC (src);
- MetaScreenCastStream *stream;
- MetaRectangle stream_rect;
-
- stream_rect.x = 0;
- stream_rect.y = 0;
- stream_rect.width = cogl_framebuffer_get_width (framebuffer);
- stream_rect.height = cogl_framebuffer_get_height (framebuffer);
-
- if (!meta_screen_cast_window_blit_to_framebuffer (window_src->screen_cast_window,
- &stream_rect,
- framebuffer))
- {
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- "Failed to blit window content to framebuffer");
- return FALSE;
- }
-
- stream = meta_screen_cast_stream_src_get_stream (src);
- switch (meta_screen_cast_stream_get_cursor_mode (stream))
- {
- case META_SCREEN_CAST_CURSOR_MODE_EMBEDDED:
- maybe_blit_cursor_sprite (window_src, framebuffer, &stream_rect);
- break;
- case META_SCREEN_CAST_CURSOR_MODE_METADATA:
- case META_SCREEN_CAST_CURSOR_MODE_HIDDEN:
- break;
- }
-
- cogl_framebuffer_flush (framebuffer);
-
- return TRUE;
-}
-
-static void
-meta_screen_cast_window_stream_record_follow_up (MetaScreenCastStreamSrc *src)
-{
- MetaScreenCastRecordFlag flags;
-
- flags = META_SCREEN_CAST_RECORD_FLAG_NONE;
- meta_screen_cast_stream_src_maybe_record_frame (src, flags);
-}
-
-static void
-meta_screen_cast_window_stream_src_set_cursor_metadata (MetaScreenCastStreamSrc *src,
- struct spa_meta_cursor *spa_meta_cursor)
-{
- MetaScreenCastWindowStreamSrc *window_src =
- META_SCREEN_CAST_WINDOW_STREAM_SRC (src);
- MetaBackend *backend = get_backend (window_src);
- MetaCursorRenderer *cursor_renderer =
- meta_backend_get_cursor_renderer (backend);
- MetaCursorTracker *cursor_tracker =
- meta_backend_get_cursor_tracker (backend);
- MetaScreenCastWindow *screen_cast_window = window_src->screen_cast_window;
- MetaCursorSprite *cursor_sprite;
- graphene_point_t cursor_position;
- float scale;
- graphene_point_t relative_cursor_position;
- int x, y;
-
- cursor_sprite = meta_cursor_renderer_get_cursor (cursor_renderer);
- meta_cursor_tracker_get_pointer (cursor_tracker, &cursor_position, NULL);
-
- if (!meta_cursor_tracker_get_pointer_visible (cursor_tracker) ||
- !meta_screen_cast_window_transform_cursor_position (screen_cast_window,
- cursor_sprite,
- &cursor_position,
- &scale,
- &relative_cursor_position))
- {
- meta_screen_cast_stream_src_unset_cursor_metadata (src,
- spa_meta_cursor);
- return;
- }
-
- x = (int) roundf (relative_cursor_position.x);
- y = (int) roundf (relative_cursor_position.y);
-
- if (window_src->cursor_bitmap_invalid)
- {
- if (cursor_sprite)
- {
- meta_screen_cast_stream_src_set_cursor_sprite_metadata (src,
- spa_meta_cursor,
- cursor_sprite,
- x, y,
- scale);
- }
- else
- {
- meta_screen_cast_stream_src_set_empty_cursor_sprite_metadata (src,
- spa_meta_cursor,
- x, y);
- }
- window_src->cursor_bitmap_invalid = FALSE;
- }
- else
- {
- meta_screen_cast_stream_src_set_cursor_position_metadata (src,
- spa_meta_cursor,
- x, y);
- }
-}
-
-MetaScreenCastWindowStreamSrc *
-meta_screen_cast_window_stream_src_new (MetaScreenCastWindowStream *window_stream,
- GError **error)
-{
- return g_initable_new (META_TYPE_SCREEN_CAST_WINDOW_STREAM_SRC, NULL, error,
- "stream", window_stream,
- NULL);
-}
-
-static void
-meta_screen_cast_window_stream_src_init (MetaScreenCastWindowStreamSrc *window_src)
-{
- window_src->cursor_bitmap_invalid = TRUE;
-}
-
-static void
-meta_screen_cast_window_stream_src_class_init (MetaScreenCastWindowStreamSrcClass *klass)
-{
- MetaScreenCastStreamSrcClass *src_class =
- META_SCREEN_CAST_STREAM_SRC_CLASS (klass);
-
- src_class->get_specs = meta_screen_cast_window_stream_src_get_specs;
- src_class->enable = meta_screen_cast_window_stream_src_enable;
- src_class->disable = meta_screen_cast_window_stream_src_disable;
- src_class->record_to_buffer =
- meta_screen_cast_window_stream_src_record_to_buffer;
- src_class->record_to_framebuffer =
- meta_screen_cast_window_stream_src_record_to_framebuffer;
- src_class->record_follow_up =
- meta_screen_cast_window_stream_record_follow_up;
- src_class->get_videocrop = meta_screen_cast_window_stream_src_get_videocrop;
- src_class->set_cursor_metadata = meta_screen_cast_window_stream_src_set_cursor_metadata;
-}
diff --git a/src/backends/meta-screen-cast-window-stream-src.h b/src/backends/meta-screen-cast-window-stream-src.h
deleted file mode 100644
index 37f786979..000000000
--- a/src/backends/meta-screen-cast-window-stream-src.h
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Copyright (C) 2018 Red Hat Inc.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- */
-
-#ifndef META_SCREEN_CAST_WINDOW_STREAM_SRC_H
-#define META_SCREEN_CAST_WINDOW_STREAM_SRC_H
-
-#include "backends/meta-screen-cast-stream-src.h"
-
-typedef struct _MetaScreenCastWindowStream MetaScreenCastWindowStream;
-
-#define META_TYPE_SCREEN_CAST_WINDOW_STREAM_SRC (meta_screen_cast_window_stream_src_get_type ())
-G_DECLARE_FINAL_TYPE (MetaScreenCastWindowStreamSrc,
- meta_screen_cast_window_stream_src,
- META, SCREEN_CAST_WINDOW_STREAM_SRC,
- MetaScreenCastStreamSrc)
-
-MetaScreenCastWindowStreamSrc * meta_screen_cast_window_stream_src_new (MetaScreenCastWindowStream *window_stream,
- GError **error);
-
-#endif /* META_SCREEN_CAST_WINDOW_STREAM_SRC_H */
diff --git a/src/backends/meta-screen-cast-window-stream.c b/src/backends/meta-screen-cast-window-stream.c
deleted file mode 100644
index 6f42a446e..000000000
--- a/src/backends/meta-screen-cast-window-stream.c
+++ /dev/null
@@ -1,285 +0,0 @@
-/*
- * Copyright (C) 2018 Red Hat Inc.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- */
-
-#include "config.h"
-
-#include "backends/meta-screen-cast-window-stream.h"
-
-#include "backends/meta-logical-monitor.h"
-#include "backends/meta-monitor-manager-private.h"
-#include "backends/meta-screen-cast-window.h"
-#include "backends/meta-screen-cast-window-stream-src.h"
-#include "compositor/meta-window-actor-private.h"
-#include "core/window-private.h"
-
-enum
-{
- PROP_0,
-
- PROP_WINDOW,
-};
-
-struct _MetaScreenCastWindowStream
-{
- MetaScreenCastStream parent;
-
- MetaWindow *window;
-
- int stream_width;
- int stream_height;
- int logical_width;
- int logical_height;
-
- unsigned long window_unmanaged_handler_id;
-};
-
-static GInitableIface *initable_parent_iface;
-
-static void
-meta_screen_cast_window_stream_init_initable_iface (GInitableIface *iface);
-
-G_DEFINE_TYPE_WITH_CODE (MetaScreenCastWindowStream,
- meta_screen_cast_window_stream,
- META_TYPE_SCREEN_CAST_STREAM,
- G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE,
- meta_screen_cast_window_stream_init_initable_iface))
-
-MetaWindow *
-meta_screen_cast_window_stream_get_window (MetaScreenCastWindowStream *window_stream)
-{
- return window_stream->window;
-}
-
-int
-meta_screen_cast_window_stream_get_width (MetaScreenCastWindowStream *window_stream)
-{
- return window_stream->stream_width;
-}
-
-int
-meta_screen_cast_window_stream_get_height (MetaScreenCastWindowStream *window_stream)
-{
- return window_stream->stream_height;
-}
-
-MetaScreenCastWindowStream *
-meta_screen_cast_window_stream_new (MetaScreenCastSession *session,
- GDBusConnection *connection,
- MetaWindow *window,
- MetaScreenCastCursorMode cursor_mode,
- MetaScreenCastFlag flags,
- GError **error)
-{
- return g_initable_new (META_TYPE_SCREEN_CAST_WINDOW_STREAM,
- NULL,
- error,
- "session", session,
- "connection", connection,
- "cursor-mode", cursor_mode,
- "flags", flags,
- "window", window,
- NULL);
-}
-
-static MetaScreenCastStreamSrc *
-meta_screen_cast_window_stream_create_src (MetaScreenCastStream *stream,
- GError **error)
-{
- MetaScreenCastWindowStream *window_stream =
- META_SCREEN_CAST_WINDOW_STREAM (stream);
- MetaScreenCastWindowStreamSrc *window_stream_src;
-
- window_stream_src = meta_screen_cast_window_stream_src_new (window_stream,
- error);
- if (!window_stream_src)
- return NULL;
-
- return META_SCREEN_CAST_STREAM_SRC (window_stream_src);
-}
-
-static void
-meta_screen_cast_window_stream_set_parameters (MetaScreenCastStream *stream,
- GVariantBuilder *parameters_builder)
-{
- MetaScreenCastWindowStream *window_stream =
- META_SCREEN_CAST_WINDOW_STREAM (stream);
-
- g_variant_builder_add (parameters_builder, "{sv}",
- "size",
- g_variant_new ("(ii)",
- window_stream->logical_width,
- window_stream->logical_height));
-}
-
-static gboolean
-meta_screen_cast_window_stream_transform_position (MetaScreenCastStream *stream,
- double stream_x,
- double stream_y,
- double *x,
- double *y)
-{
- MetaScreenCastWindowStream *window_stream =
- META_SCREEN_CAST_WINDOW_STREAM (stream);
- MetaScreenCastWindow *screen_cast_window =
- META_SCREEN_CAST_WINDOW (meta_window_actor_from_window (window_stream->window));
-
- meta_screen_cast_window_transform_relative_position (screen_cast_window,
- stream_x,
- stream_y,
- x,
- y);
- return TRUE;
-}
-
-static void
-on_window_unmanaged (MetaScreenCastWindowStream *window_stream)
-{
- meta_screen_cast_stream_close (META_SCREEN_CAST_STREAM (window_stream));
-}
-
-static void
-meta_screen_cast_window_stream_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- MetaScreenCastWindowStream *window_stream =
- META_SCREEN_CAST_WINDOW_STREAM (object);
-
- switch (prop_id)
- {
- case PROP_WINDOW:
- window_stream->window = g_value_get_object (value);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- }
-}
-
-static void
-meta_screen_cast_window_stream_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- MetaScreenCastWindowStream *window_stream =
- META_SCREEN_CAST_WINDOW_STREAM (object);
-
- switch (prop_id)
- {
- case PROP_WINDOW:
- g_value_set_object (value, window_stream->window);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- }
-}
-
-static void
-meta_screen_cast_window_stream_finalize (GObject *object)
-{
- MetaScreenCastWindowStream *window_stream =
- META_SCREEN_CAST_WINDOW_STREAM (object);
-
- g_clear_signal_handler (&window_stream->window_unmanaged_handler_id,
- window_stream->window);
-
- G_OBJECT_CLASS (meta_screen_cast_window_stream_parent_class)->finalize (object);
-}
-
-static gboolean
-meta_screen_cast_window_stream_initable_init (GInitable *initable,
- GCancellable *cancellable,
- GError **error)
-{
- MetaScreenCastWindowStream *window_stream =
- META_SCREEN_CAST_WINDOW_STREAM (initable);
- MetaWindow *window = window_stream->window;
- MetaLogicalMonitor *logical_monitor;
- int scale;
-
- logical_monitor = meta_window_get_main_logical_monitor (window);
- if (!logical_monitor)
- {
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- "Main logical monitor not found");
- return FALSE;
- }
-
- window_stream->window_unmanaged_handler_id =
- g_signal_connect_swapped (window, "unmanaged",
- G_CALLBACK (on_window_unmanaged),
- window_stream);
-
- if (meta_is_stage_views_scaled ())
- scale = (int) ceilf (meta_logical_monitor_get_scale (logical_monitor));
- else
- scale = 1;
-
- /* We cannot set the stream size to the exact size of the window, because
- * windows can be resized, whereas streams cannot.
- * So we set a size equals to the size of the logical monitor for the window.
- */
- window_stream->logical_width = logical_monitor->rect.width;
- window_stream->logical_height = logical_monitor->rect.height;
- window_stream->stream_width = logical_monitor->rect.width * scale;
- window_stream->stream_height = logical_monitor->rect.height * scale;
-
- return initable_parent_iface->init (initable, cancellable, error);
-}
-
-static void
-meta_screen_cast_window_stream_init_initable_iface (GInitableIface *iface)
-{
- initable_parent_iface = g_type_interface_peek_parent (iface);
-
- iface->init = meta_screen_cast_window_stream_initable_init;
-}
-
-static void
-meta_screen_cast_window_stream_init (MetaScreenCastWindowStream *window_stream)
-{
-}
-
-static void
-meta_screen_cast_window_stream_class_init (MetaScreenCastWindowStreamClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
- MetaScreenCastStreamClass *stream_class =
- META_SCREEN_CAST_STREAM_CLASS (klass);
-
- object_class->set_property = meta_screen_cast_window_stream_set_property;
- object_class->get_property = meta_screen_cast_window_stream_get_property;
- object_class->finalize = meta_screen_cast_window_stream_finalize;
-
- stream_class->create_src = meta_screen_cast_window_stream_create_src;
- stream_class->set_parameters = meta_screen_cast_window_stream_set_parameters;
- stream_class->transform_position = meta_screen_cast_window_stream_transform_position;
-
- g_object_class_install_property (object_class,
- PROP_WINDOW,
- g_param_spec_object ("window",
- "window",
- "MetaWindow",
- META_TYPE_WINDOW,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT_ONLY |
- G_PARAM_STATIC_STRINGS));
-}
diff --git a/src/backends/meta-screen-cast-window-stream.h b/src/backends/meta-screen-cast-window-stream.h
deleted file mode 100644
index 0acceaac6..000000000
--- a/src/backends/meta-screen-cast-window-stream.h
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Copyright (C) 2018 Red Hat Inc.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- */
-
-#ifndef META_SCREEN_CAST_WINDOW_STREAM_H
-#define META_SCREEN_CAST_WINDOW_STREAM_H
-
-#include <glib-object.h>
-
-#include "backends/meta-screen-cast-stream.h"
-#include "meta/window.h"
-
-#define META_TYPE_SCREEN_CAST_WINDOW_STREAM (meta_screen_cast_window_stream_get_type ())
-G_DECLARE_FINAL_TYPE (MetaScreenCastWindowStream,
- meta_screen_cast_window_stream,
- META, SCREEN_CAST_WINDOW_STREAM,
- MetaScreenCastStream)
-
-MetaScreenCastWindowStream * meta_screen_cast_window_stream_new (MetaScreenCastSession *session,
- GDBusConnection *connection,
- MetaWindow *window,
- MetaScreenCastCursorMode cursor_mode,
- MetaScreenCastFlag flags,
- GError **error);
-
-MetaWindow * meta_screen_cast_window_stream_get_window (MetaScreenCastWindowStream *window_stream);
-int meta_screen_cast_window_stream_get_width (MetaScreenCastWindowStream *window_stream);
-int meta_screen_cast_window_stream_get_height (MetaScreenCastWindowStream *window_stream);
-
-#endif /* META_SCREEN_CAST_WINDOW_STREAM_H */
diff --git a/src/backends/meta-screen-cast-window.c b/src/backends/meta-screen-cast-window.c
deleted file mode 100644
index ab3e4ebe3..000000000
--- a/src/backends/meta-screen-cast-window.c
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * Copyright (C) 2018 Red Hat Inc.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- */
-
-#include "config.h"
-
-#include "backends/meta-screen-cast-window.h"
-
-G_DEFINE_INTERFACE (MetaScreenCastWindow, meta_screen_cast_window, G_TYPE_OBJECT)
-
-static void
-meta_screen_cast_window_default_init (MetaScreenCastWindowInterface *iface)
-{
-}
-
-void
-meta_screen_cast_window_get_buffer_bounds (MetaScreenCastWindow *screen_cast_window,
- MetaRectangle *bounds)
-{
- META_SCREEN_CAST_WINDOW_GET_IFACE (screen_cast_window)->get_buffer_bounds (screen_cast_window,
- bounds);
-}
-
-void
-meta_screen_cast_window_transform_relative_position (MetaScreenCastWindow *screen_cast_window,
- double x,
- double y,
- double *x_out,
- double *y_out)
-{
- META_SCREEN_CAST_WINDOW_GET_IFACE (screen_cast_window)->transform_relative_position (screen_cast_window,
- x,
- y,
- x_out,
- y_out);
-}
-
-gboolean
-meta_screen_cast_window_transform_cursor_position (MetaScreenCastWindow *screen_cast_window,
- MetaCursorSprite *cursor_sprite,
- graphene_point_t *cursor_position,
- float *out_cursor_scale,
- graphene_point_t *out_relative_cursor_position)
-{
- MetaScreenCastWindowInterface *iface =
- META_SCREEN_CAST_WINDOW_GET_IFACE (screen_cast_window);
-
- return iface->transform_cursor_position (screen_cast_window,
- cursor_sprite,
- cursor_position,
- out_cursor_scale,
- out_relative_cursor_position);
-}
-
-void
-meta_screen_cast_window_capture_into (MetaScreenCastWindow *screen_cast_window,
- MetaRectangle *bounds,
- uint8_t *data)
-{
- META_SCREEN_CAST_WINDOW_GET_IFACE (screen_cast_window)->capture_into (screen_cast_window,
- bounds,
- data);
-}
-
-gboolean
-meta_screen_cast_window_blit_to_framebuffer (MetaScreenCastWindow *screen_cast_window,
- MetaRectangle *bounds,
- CoglFramebuffer *framebuffer)
-{
- MetaScreenCastWindowInterface *iface =
- META_SCREEN_CAST_WINDOW_GET_IFACE (screen_cast_window);
-
- return iface->blit_to_framebuffer (screen_cast_window, bounds, framebuffer);
-}
-
-gboolean
-meta_screen_cast_window_has_damage (MetaScreenCastWindow *screen_cast_window)
-{
- MetaScreenCastWindowInterface *iface =
- META_SCREEN_CAST_WINDOW_GET_IFACE (screen_cast_window);
-
- return iface->has_damage (screen_cast_window);
-}
diff --git a/src/backends/meta-screen-cast-window.h b/src/backends/meta-screen-cast-window.h
deleted file mode 100644
index e149646ed..000000000
--- a/src/backends/meta-screen-cast-window.h
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * Copyright (C) 2018 Red Hat Inc.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- */
-
-#ifndef META_SCREEN_CAST_WINDOW_H
-#define META_SCREEN_CAST_WINDOW_H
-
-#include <stdint.h>
-#include <glib-object.h>
-
-#include "backends/meta-cursor.h"
-#include "meta/boxes.h"
-
-G_BEGIN_DECLS
-
-#define META_TYPE_SCREEN_CAST_WINDOW (meta_screen_cast_window_get_type ())
-G_DECLARE_INTERFACE (MetaScreenCastWindow, meta_screen_cast_window,
- META, SCREEN_CAST_WINDOW, GObject)
-
-struct _MetaScreenCastWindowInterface
-{
- GTypeInterface parent_iface;
-
- void (*get_buffer_bounds) (MetaScreenCastWindow *screen_cast_window,
- MetaRectangle *bounds);
-
- void (*transform_relative_position) (MetaScreenCastWindow *screen_cast_window,
- double x,
- double y,
- double *x_out,
- double *y_out);
-
- gboolean (*transform_cursor_position) (MetaScreenCastWindow *screen_cast_window,
- MetaCursorSprite *cursor_sprite,
- graphene_point_t *cursor_position,
- float *out_cursor_scale,
- graphene_point_t *out_relative_cursor_position);
-
- void (*capture_into) (MetaScreenCastWindow *screen_cast_window,
- MetaRectangle *bounds,
- uint8_t *data);
-
- gboolean (*blit_to_framebuffer) (MetaScreenCastWindow *screen_cast_window,
- MetaRectangle *bounds,
- CoglFramebuffer *framebuffer);
-
- gboolean (*has_damage) (MetaScreenCastWindow *screen_cast_window);
-};
-
-void meta_screen_cast_window_get_buffer_bounds (MetaScreenCastWindow *screen_cast_window,
- MetaRectangle *bounds);
-
-void meta_screen_cast_window_transform_relative_position (MetaScreenCastWindow *screen_cast_window,
- double x,
- double y,
- double *x_out,
- double *y_out);
-
-gboolean meta_screen_cast_window_transform_cursor_position (MetaScreenCastWindow *screen_cast_window,
- MetaCursorSprite *cursor_sprite,
- graphene_point_t *cursor_position,
- float *out_cursor_scale,
- graphene_point_t *out_relative_cursor_position);
-
-void meta_screen_cast_window_capture_into (MetaScreenCastWindow *screen_cast_window,
- MetaRectangle *bounds,
- uint8_t *data);
-
-gboolean meta_screen_cast_window_blit_to_framebuffer (MetaScreenCastWindow *screen_cast_window,
- MetaRectangle *bounds,
- CoglFramebuffer *framebuffer);
-
-gboolean meta_screen_cast_window_has_damage (MetaScreenCastWindow *screen_cast_window);
-
-G_END_DECLS
-
-#endif /* META_SCREEN_CAST_WINDOW_H */
diff --git a/src/backends/meta-screen-cast.c b/src/backends/meta-screen-cast.c
deleted file mode 100644
index 6162b8d27..000000000
--- a/src/backends/meta-screen-cast.c
+++ /dev/null
@@ -1,385 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2015-2017 Red Hat Inc.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- */
-
-#include "config.h"
-
-#include "backends/meta-screen-cast.h"
-
-#include <pipewire/pipewire.h>
-
-#include "backends/meta-backend-private.h"
-#include "backends/meta-remote-desktop-session.h"
-#include "backends/meta-screen-cast-session.h"
-
-#define META_SCREEN_CAST_DBUS_SERVICE "org.gnome.Mutter.ScreenCast"
-#define META_SCREEN_CAST_DBUS_PATH "/org/gnome/Mutter/ScreenCast"
-#define META_SCREEN_CAST_API_VERSION 4
-
-struct _MetaScreenCast
-{
- MetaDBusScreenCastSkeleton parent;
-
- int dbus_name_id;
-
- int inhibit_count;
-
- GList *sessions;
-
- MetaDbusSessionWatcher *session_watcher;
- MetaBackend *backend;
-
- gboolean disable_dma_bufs;
-};
-
-static void
-meta_screen_cast_init_iface (MetaDBusScreenCastIface *iface);
-
-G_DEFINE_TYPE_WITH_CODE (MetaScreenCast, meta_screen_cast,
- META_DBUS_TYPE_SCREEN_CAST_SKELETON,
- G_IMPLEMENT_INTERFACE (META_DBUS_TYPE_SCREEN_CAST,
- meta_screen_cast_init_iface))
-
-void
-meta_screen_cast_inhibit (MetaScreenCast *screen_cast)
-{
- screen_cast->inhibit_count++;
- if (screen_cast->inhibit_count == 1)
- {
- while (screen_cast->sessions)
- {
- MetaScreenCastSession *session = screen_cast->sessions->data;
-
- meta_screen_cast_session_close (session);
- }
- }
-}
-
-void
-meta_screen_cast_uninhibit (MetaScreenCast *screen_cast)
-{
- g_return_if_fail (screen_cast->inhibit_count > 0);
-
- screen_cast->inhibit_count--;
-}
-
-GDBusConnection *
-meta_screen_cast_get_connection (MetaScreenCast *screen_cast)
-{
- GDBusInterfaceSkeleton *interface_skeleton =
- G_DBUS_INTERFACE_SKELETON (screen_cast);
-
- return g_dbus_interface_skeleton_get_connection (interface_skeleton);
-}
-
-MetaBackend *
-meta_screen_cast_get_backend (MetaScreenCast *screen_cast)
-{
- return screen_cast->backend;
-}
-
-void
-meta_screen_cast_disable_dma_bufs (MetaScreenCast *screen_cast)
-{
- screen_cast->disable_dma_bufs = TRUE;
-}
-
-CoglDmaBufHandle *
-meta_screen_cast_create_dma_buf_handle (MetaScreenCast *screen_cast,
- int width,
- int height)
-{
- ClutterBackend *clutter_backend =
- meta_backend_get_clutter_backend (screen_cast->backend);
- CoglContext *cogl_context =
- clutter_backend_get_cogl_context (clutter_backend);
- CoglRenderer *cogl_renderer = cogl_context_get_renderer (cogl_context);
- g_autoptr (GError) error = NULL;
- CoglDmaBufHandle *dmabuf_handle;
-
- if (screen_cast->disable_dma_bufs)
- return NULL;
-
- dmabuf_handle = cogl_renderer_create_dma_buf (cogl_renderer,
- width, height,
- &error);
- if (!dmabuf_handle)
- {
- g_warning ("Failed to allocate DMA buffer, "
- "disabling DMA buffer based screen casting: %s",
- error->message);
- screen_cast->disable_dma_bufs = TRUE;
- return NULL;
- }
-
- return dmabuf_handle;
-}
-
-static gboolean
-register_remote_desktop_screen_cast_session (MetaScreenCastSession *session,
- const char *remote_desktop_session_id,
- GError **error)
-{
- MetaScreenCast *screen_cast =
- meta_screen_cast_session_get_screen_cast (session);
- MetaBackend *backend = meta_screen_cast_get_backend (screen_cast);
- MetaRemoteDesktop *remote_desktop = meta_backend_get_remote_desktop (backend);
- MetaRemoteDesktopSession *remote_desktop_session;
-
- remote_desktop_session =
- meta_remote_desktop_get_session (remote_desktop, remote_desktop_session_id);
- if (!remote_desktop_session)
- {
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- "No remote desktop session found");
- return FALSE;
- }
-
- if (!meta_remote_desktop_session_register_screen_cast (remote_desktop_session,
- session,
- error))
- return FALSE;
-
- return TRUE;
-}
-
-static void
-on_session_closed (MetaScreenCastSession *session,
- MetaScreenCast *screen_cast)
-{
- screen_cast->sessions = g_list_remove (screen_cast->sessions, session);
-}
-
-static gboolean
-handle_create_session (MetaDBusScreenCast *skeleton,
- GDBusMethodInvocation *invocation,
- GVariant *properties)
-{
- MetaScreenCast *screen_cast = META_SCREEN_CAST (skeleton);
- const char *peer_name;
- MetaScreenCastSession *session;
- GError *error = NULL;
- const char *session_path;
- const char *client_dbus_name;
- char *remote_desktop_session_id = NULL;
- gboolean disable_animations;
- MetaScreenCastSessionType session_type;
-
- if (screen_cast->inhibit_count > 0)
- {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_ACCESS_DENIED,
- "Session creation inhibited");
-
- return TRUE;
- }
-
- g_variant_lookup (properties, "remote-desktop-session-id", "s",
- &remote_desktop_session_id);
-
- if (remote_desktop_session_id)
- session_type = META_SCREEN_CAST_SESSION_TYPE_REMOTE_DESKTOP;
- else
- session_type = META_SCREEN_CAST_SESSION_TYPE_NORMAL;
-
- peer_name = g_dbus_method_invocation_get_sender (invocation);
- session = meta_screen_cast_session_new (screen_cast,
- session_type,
- peer_name,
- &error);
- if (!session)
- {
- g_warning ("Failed to create screen cast session: %s",
- error->message);
-
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_FAILED,
- "Failed to create session: %s",
- error->message);
- g_error_free (error);
-
- return TRUE;
- }
-
- if (remote_desktop_session_id)
- {
- if (!register_remote_desktop_screen_cast_session (session,
- remote_desktop_session_id,
- &error))
- {
- g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
- G_DBUS_ERROR_FAILED,
- "%s", error->message);
- g_error_free (error);
- g_object_unref (session);
- return TRUE;
- }
- }
-
- if (g_variant_lookup (properties, "disable-animations", "b",
- &disable_animations))
- {
- meta_screen_cast_session_set_disable_animations (session,
- disable_animations);
- }
-
- client_dbus_name = g_dbus_method_invocation_get_sender (invocation);
- meta_dbus_session_watcher_watch_session (screen_cast->session_watcher,
- client_dbus_name,
- META_DBUS_SESSION (session));
-
- session_path = meta_screen_cast_session_get_object_path (session);
- meta_dbus_screen_cast_complete_create_session (skeleton,
- invocation,
- session_path);
-
- screen_cast->sessions = g_list_append (screen_cast->sessions, session);
-
- g_signal_connect (session, "session-closed",
- G_CALLBACK (on_session_closed),
- screen_cast);
-
- return TRUE;
-}
-
-static void
-meta_screen_cast_init_iface (MetaDBusScreenCastIface *iface)
-{
- iface->handle_create_session = handle_create_session;
-}
-
-static void
-on_bus_acquired (GDBusConnection *connection,
- const char *name,
- gpointer user_data)
-{
- MetaScreenCast *screen_cast = user_data;
- GDBusInterfaceSkeleton *interface_skeleton =
- G_DBUS_INTERFACE_SKELETON (screen_cast);
- GError *error = NULL;
-
- if (!g_dbus_interface_skeleton_export (interface_skeleton,
- connection,
- META_SCREEN_CAST_DBUS_PATH,
- &error))
- g_warning ("Failed to export remote desktop object: %s", error->message);
-}
-
-static void
-on_name_acquired (GDBusConnection *connection,
- const char *name,
- gpointer user_data)
-{
- g_info ("Acquired name %s", name);
-}
-
-static void
-on_name_lost (GDBusConnection *connection,
- const char *name,
- gpointer user_data)
-{
- g_warning ("Lost or failed to acquire name %s", name);
-}
-
-static void
-meta_screen_cast_constructed (GObject *object)
-{
- MetaScreenCast *screen_cast = META_SCREEN_CAST (object);
-
- screen_cast->dbus_name_id =
- g_bus_own_name (G_BUS_TYPE_SESSION,
- META_SCREEN_CAST_DBUS_SERVICE,
- G_BUS_NAME_OWNER_FLAGS_NONE,
- on_bus_acquired,
- on_name_acquired,
- on_name_lost,
- screen_cast,
- NULL);
-}
-
-static void
-meta_screen_cast_finalize (GObject *object)
-{
- MetaScreenCast *screen_cast = META_SCREEN_CAST (object);
-
- if (screen_cast->dbus_name_id)
- g_bus_unown_name (screen_cast->dbus_name_id);
-
- g_assert (!screen_cast->sessions);
-
- G_OBJECT_CLASS (meta_screen_cast_parent_class)->finalize (object);
-}
-
-static void
-on_prepare_shutdown (MetaBackend *backend,
- MetaScreenCast *screen_cast)
-{
- while (screen_cast->sessions)
- {
- MetaScreenCastSession *session = screen_cast->sessions->data;
-
- if (meta_screen_cast_session_get_session_type (session) !=
- META_SCREEN_CAST_SESSION_TYPE_REMOTE_DESKTOP)
- meta_screen_cast_session_close (session);
- }
-}
-
-MetaScreenCast *
-meta_screen_cast_new (MetaBackend *backend,
- MetaDbusSessionWatcher *session_watcher)
-{
- MetaScreenCast *screen_cast;
-
- screen_cast = g_object_new (META_TYPE_SCREEN_CAST, NULL);
- screen_cast->backend = backend;
- screen_cast->session_watcher = session_watcher;
-
- g_signal_connect (backend, "prepare-shutdown",
- G_CALLBACK (on_prepare_shutdown),
- screen_cast);
-
- return screen_cast;
-}
-
-
-static void
-meta_screen_cast_init (MetaScreenCast *screen_cast)
-{
- static gboolean is_pipewire_initialized = FALSE;
-
- if (!is_pipewire_initialized)
- {
- pw_init (NULL, NULL);
- is_pipewire_initialized = TRUE;
- }
-
- meta_dbus_screen_cast_set_version (META_DBUS_SCREEN_CAST (screen_cast),
- META_SCREEN_CAST_API_VERSION);
-}
-
-static void
-meta_screen_cast_class_init (MetaScreenCastClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- object_class->constructed = meta_screen_cast_constructed;
- object_class->finalize = meta_screen_cast_finalize;
-}
diff --git a/src/backends/meta-screen-cast.h b/src/backends/meta-screen-cast.h
deleted file mode 100644
index be297e28d..000000000
--- a/src/backends/meta-screen-cast.h
+++ /dev/null
@@ -1,69 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2015-2017 Red Hat Inc.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- */
-
-#ifndef META_SCREEN_CAST_H
-#define META_SCREEN_CAST_H
-
-#include <glib-object.h>
-
-#include "backends/meta-backend-private.h"
-#include "backends/meta-dbus-session-watcher.h"
-
-#include "meta-dbus-screen-cast.h"
-
-typedef enum _MetaScreenCastCursorMode
-{
- META_SCREEN_CAST_CURSOR_MODE_HIDDEN = 0,
- META_SCREEN_CAST_CURSOR_MODE_EMBEDDED = 1,
- META_SCREEN_CAST_CURSOR_MODE_METADATA = 2,
-} MetaScreenCastCursorMode;
-
-typedef enum _MetaScreenCastFlag
-{
- META_SCREEN_CAST_FLAG_NONE = 0,
- META_SCREEN_CAST_FLAG_IS_RECORDING = 1 << 0,
- META_SCREEN_CAST_FLAG_IS_PLATFORM = 1 << 1,
-} MetaScreenCastFlag;
-
-#define META_TYPE_SCREEN_CAST (meta_screen_cast_get_type ())
-G_DECLARE_FINAL_TYPE (MetaScreenCast, meta_screen_cast,
- META, SCREEN_CAST,
- MetaDBusScreenCastSkeleton)
-
-void meta_screen_cast_inhibit (MetaScreenCast *screen_cast);
-
-void meta_screen_cast_uninhibit (MetaScreenCast *screen_cast);
-
-GDBusConnection * meta_screen_cast_get_connection (MetaScreenCast *screen_cast);
-
-MetaBackend * meta_screen_cast_get_backend (MetaScreenCast *screen_cast);
-
-void meta_screen_cast_disable_dma_bufs (MetaScreenCast *screen_cast);
-
-CoglDmaBufHandle * meta_screen_cast_create_dma_buf_handle (MetaScreenCast *screen_cast,
- int width,
- int height);
-
-MetaScreenCast * meta_screen_cast_new (MetaBackend *backend,
- MetaDbusSessionWatcher *session_watcher);
-
-#endif /* META_SCREEN_CAST_H */
diff --git a/src/backends/meta-settings-private.h b/src/backends/meta-settings-private.h
deleted file mode 100644
index cde7e0439..000000000
--- a/src/backends/meta-settings-private.h
+++ /dev/null
@@ -1,81 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2017 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-
-#ifndef META_SETTINGS_PRIVATE_H
-#define META_SETTINGS_PRIVATE_H
-
-#include <glib-object.h>
-
-#include "meta/meta-settings.h"
-#include "meta/types.h"
-#include "core/util-private.h"
-
-typedef enum _MetaExperimentalFeature
-{
- META_EXPERIMENTAL_FEATURE_NONE = 0,
- META_EXPERIMENTAL_FEATURE_SCALE_MONITOR_FRAMEBUFFER = (1 << 0),
- META_EXPERIMENTAL_FEATURE_KMS_MODIFIERS = (1 << 1),
- META_EXPERIMENTAL_FEATURE_RT_SCHEDULER = (1 << 2),
- META_EXPERIMENTAL_FEATURE_DMA_BUF_SCREEN_SHARING = (1 << 3),
- META_EXPERIMENTAL_FEATURE_AUTOCLOSE_XWAYLAND = (1 << 4),
-} MetaExperimentalFeature;
-
-typedef enum _MetaXwaylandExtension
-{
- META_XWAYLAND_EXTENSION_SECURITY = (1 << 0),
- META_XWAYLAND_EXTENSION_XTEST = (1 << 1),
-} MetaXwaylandExtension;
-
-#define META_TYPE_SETTINGS (meta_settings_get_type ())
-G_DECLARE_FINAL_TYPE (MetaSettings, meta_settings,
- META, SETTINGS, GObject)
-
-MetaSettings * meta_settings_new (MetaBackend *backend);
-
-void meta_settings_post_init (MetaSettings *settings);
-
-void meta_settings_update_ui_scaling_factor (MetaSettings *settings);
-
-gboolean meta_settings_get_global_scaling_factor (MetaSettings *settings,
- int *scaing_factor);
-
-META_EXPORT_TEST
-gboolean meta_settings_is_experimental_feature_enabled (MetaSettings *settings,
- MetaExperimentalFeature feature);
-
-MetaExperimentalFeature meta_settings_get_experimental_features (MetaSettings *settings);
-
-META_EXPORT_TEST
-void meta_settings_override_experimental_features (MetaSettings *settings);
-
-META_EXPORT_TEST
-void meta_settings_enable_experimental_feature (MetaSettings *settings,
- MetaExperimentalFeature feature);
-
-void meta_settings_get_xwayland_grab_patterns (MetaSettings *settings,
- GPtrArray **allow_list_patterns,
- GPtrArray **deny_list_patterns);
-
-gboolean meta_settings_are_xwayland_grabs_allowed (MetaSettings *settings);
-
-int meta_settings_get_xwayland_disable_extensions (MetaSettings *settings);
-
-#endif /* META_SETTINGS_PRIVATE_H */
diff --git a/src/backends/meta-settings.c b/src/backends/meta-settings.c
deleted file mode 100644
index 6a754d4e0..000000000
--- a/src/backends/meta-settings.c
+++ /dev/null
@@ -1,559 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2017 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-
-#include "config.h"
-
-#include "backends/meta-settings-private.h"
-
-#include <gio/gio.h>
-
-#include "backends/meta-backend-private.h"
-#include "backends/meta-logical-monitor.h"
-#include "backends/meta-monitor-manager-private.h"
-#include "ui/theme-private.h"
-
-#ifndef XWAYLAND_GRAB_DEFAULT_ACCESS_RULES
-# warning "XWAYLAND_GRAB_DEFAULT_ACCESS_RULES is not set"
-# define XWAYLAND_GRAB_DEFAULT_ACCESS_RULES ""
-#endif
-
-enum
-{
- UI_SCALING_FACTOR_CHANGED,
- GLOBAL_SCALING_FACTOR_CHANGED,
- FONT_DPI_CHANGED,
- EXPERIMENTAL_FEATURES_CHANGED,
-
- N_SIGNALS
-};
-
-static guint signals[N_SIGNALS];
-
-struct _MetaSettings
-{
- GObject parent;
-
- MetaBackend *backend;
-
- GSettings *interface_settings;
- GSettings *mutter_settings;
- GSettings *wayland_settings;
-
- int ui_scaling_factor;
- int global_scaling_factor;
-
- int font_dpi;
-
- MetaExperimentalFeature experimental_features;
- gboolean experimental_features_overridden;
-
- gboolean xwayland_allow_grabs;
- GPtrArray *xwayland_grab_allow_list_patterns;
- GPtrArray *xwayland_grab_deny_list_patterns;
-
- /* A bitmask of MetaXwaylandExtension enum */
- int xwayland_disable_extensions;
-};
-
-G_DEFINE_TYPE (MetaSettings, meta_settings, G_TYPE_OBJECT)
-
-static int
-calculate_ui_scaling_factor (MetaSettings *settings)
-{
- MetaMonitorManager *monitor_manager =
- meta_backend_get_monitor_manager (settings->backend);
- MetaLogicalMonitor *primary_logical_monitor;
-
- primary_logical_monitor =
- meta_monitor_manager_get_primary_logical_monitor (monitor_manager);
- if (!primary_logical_monitor)
- return 1;
-
- return (int) meta_logical_monitor_get_scale (primary_logical_monitor);
-}
-
-static gboolean
-update_ui_scaling_factor (MetaSettings *settings)
-{
- int ui_scaling_factor;
-
- if (meta_is_stage_views_scaled ())
- ui_scaling_factor = 1;
- else
- ui_scaling_factor = calculate_ui_scaling_factor (settings);
-
- if (settings->ui_scaling_factor != ui_scaling_factor)
- {
- settings->ui_scaling_factor = ui_scaling_factor;
- return TRUE;
- }
- else
- {
- return FALSE;
- }
-}
-
-void
-meta_settings_update_ui_scaling_factor (MetaSettings *settings)
-{
- if (update_ui_scaling_factor (settings))
- g_signal_emit (settings, signals[UI_SCALING_FACTOR_CHANGED], 0);
-}
-
-int
-meta_settings_get_ui_scaling_factor (MetaSettings *settings)
-{
- g_assert (settings->ui_scaling_factor != 0);
-
- return settings->ui_scaling_factor;
-}
-
-static gboolean
-update_global_scaling_factor (MetaSettings *settings)
-{
- int global_scaling_factor;
-
- global_scaling_factor =
- (int) g_settings_get_uint (settings->interface_settings,
- "scaling-factor");
-
- if (settings->global_scaling_factor != global_scaling_factor)
- {
- settings->global_scaling_factor = global_scaling_factor;
- return TRUE;
- }
- else
- {
- return FALSE;
- }
-}
-
-gboolean
-meta_settings_get_global_scaling_factor (MetaSettings *settings,
- int *out_scaling_factor)
-{
- if (settings->global_scaling_factor == 0)
- return FALSE;
-
- *out_scaling_factor = settings->global_scaling_factor;
- return TRUE;
-}
-
-static gboolean
-update_font_dpi (MetaSettings *settings)
-{
- double text_scaling_factor;
- /* Number of logical pixels on an inch when unscaled */
- const double dots_per_inch = 96;
- /* Being based on Xft, API users expect the DPI to be 1/1024th of an inch. */
- const double xft_factor = 1024;
- int font_dpi;
-
- text_scaling_factor = g_settings_get_double (settings->interface_settings,
- "text-scaling-factor");
- font_dpi = (int) (text_scaling_factor *
- dots_per_inch *
- xft_factor *
- settings->ui_scaling_factor);
-
- if (font_dpi != settings->font_dpi)
- {
- settings->font_dpi = font_dpi;
-
- g_object_set (clutter_settings_get_default (),
- "font-dpi", font_dpi,
- NULL);
-
- return TRUE;
- }
- else
- {
- return FALSE;
- }
-}
-
-static void
-meta_settings_update_font_dpi (MetaSettings *settings)
-{
- if (update_font_dpi (settings))
- g_signal_emit (settings, signals[FONT_DPI_CHANGED], 0);
-}
-
-int
-meta_settings_get_font_dpi (MetaSettings *settings)
-{
- g_assert (settings->font_dpi != 0);
-
- return settings->font_dpi;
-}
-
-static void
-interface_settings_changed (GSettings *interface_settings,
- const char *key,
- MetaSettings *settings)
-{
- if (g_str_equal (key, "scaling-factor"))
- {
- if (update_global_scaling_factor (settings))
- g_signal_emit (settings, signals[GLOBAL_SCALING_FACTOR_CHANGED], 0);
- }
- else if (g_str_equal (key, "text-scaling-factor"))
- {
- meta_settings_update_font_dpi (settings);
- }
-}
-
-gboolean
-meta_settings_is_experimental_feature_enabled (MetaSettings *settings,
- MetaExperimentalFeature feature)
-{
- return !!(settings->experimental_features & feature);
-}
-
-void
-meta_settings_override_experimental_features (MetaSettings *settings)
-{
- settings->experimental_features = META_EXPERIMENTAL_FEATURE_NONE;
- settings->experimental_features_overridden = TRUE;
-}
-
-void
-meta_settings_enable_experimental_feature (MetaSettings *settings,
- MetaExperimentalFeature feature)
-{
- g_assert (settings->experimental_features_overridden);
-
- settings->experimental_features |= feature;
-}
-
-static gboolean
-experimental_features_handler (GVariant *features_variant,
- gpointer *result,
- gpointer data)
-{
- MetaSettings *settings = data;
- GVariantIter features_iter;
- char *feature_str;
- MetaExperimentalFeature features = META_EXPERIMENTAL_FEATURE_NONE;
-
- if (settings->experimental_features_overridden)
- {
- *result = GINT_TO_POINTER (FALSE);
- return TRUE;
- }
-
- g_variant_iter_init (&features_iter, features_variant);
- while (g_variant_iter_loop (&features_iter, "s", &feature_str))
- {
- MetaExperimentalFeature feature = META_EXPERIMENTAL_FEATURE_NONE;
-
- if (g_str_equal (feature_str, "scale-monitor-framebuffer"))
- feature = META_EXPERIMENTAL_FEATURE_SCALE_MONITOR_FRAMEBUFFER;
- else if (g_str_equal (feature_str, "kms-modifiers"))
- feature = META_EXPERIMENTAL_FEATURE_KMS_MODIFIERS;
- else if (g_str_equal (feature_str, "rt-scheduler"))
- feature = META_EXPERIMENTAL_FEATURE_RT_SCHEDULER;
- else if (g_str_equal (feature_str, "dma-buf-screen-sharing"))
- feature = META_EXPERIMENTAL_FEATURE_DMA_BUF_SCREEN_SHARING;
- else if (g_str_equal (feature_str, "autoclose-xwayland"))
- feature = META_EXPERIMENTAL_FEATURE_AUTOCLOSE_XWAYLAND;
-
- if (feature)
- g_message ("Enabling experimental feature '%s'", feature_str);
- else
- g_warning ("Unknown experimental feature '%s'", feature_str);
-
- features |= feature;
- }
-
- if (features != settings->experimental_features)
- {
- settings->experimental_features = features;
- *result = GINT_TO_POINTER (TRUE);
- }
- else
- {
- *result = GINT_TO_POINTER (FALSE);
- }
-
- return TRUE;
-}
-
-static gboolean
-update_experimental_features (MetaSettings *settings)
-{
- return GPOINTER_TO_INT (g_settings_get_mapped (settings->mutter_settings,
- "experimental-features",
- experimental_features_handler,
- settings));
-}
-
-static void
-mutter_settings_changed (GSettings *mutter_settings,
- gchar *key,
- MetaSettings *settings)
-{
- MetaExperimentalFeature old_experimental_features;
-
- if (!g_str_equal (key, "experimental-features"))
- return;
-
- old_experimental_features = settings->experimental_features;
- if (update_experimental_features (settings))
- g_signal_emit (settings, signals[EXPERIMENTAL_FEATURES_CHANGED], 0,
- (unsigned int) old_experimental_features);
-}
-
-static void
-xwayland_grab_list_add_item (MetaSettings *settings,
- char *item)
-{
- /* If first character is '!', it's a denied value */
- if (item[0] != '!')
- g_ptr_array_add (settings->xwayland_grab_allow_list_patterns,
- g_pattern_spec_new (item));
- else if (item[1] != 0)
- g_ptr_array_add (settings->xwayland_grab_deny_list_patterns,
- g_pattern_spec_new (&item[1]));
-}
-
-static gboolean
-xwayland_grab_access_rules_handler (GVariant *variant,
- gpointer *result,
- gpointer data)
-{
- MetaSettings *settings = data;
- GVariantIter iter;
- char *item;
-
- /* Create a GPatternSpec for each element */
- g_variant_iter_init (&iter, variant);
- while (g_variant_iter_loop (&iter, "s", &item))
- xwayland_grab_list_add_item (settings, item);
-
- *result = GINT_TO_POINTER (TRUE);
-
- return TRUE;
-}
-
-static void
-update_xwayland_grab_access_rules (MetaSettings *settings)
-{
- gchar **system_defaults;
- int i;
-
- /* Free previous patterns and create new arrays */
- g_clear_pointer (&settings->xwayland_grab_allow_list_patterns,
- g_ptr_array_unref);
- settings->xwayland_grab_allow_list_patterns =
- g_ptr_array_new_with_free_func ((GDestroyNotify) g_pattern_spec_free);
-
- g_clear_pointer (&settings->xwayland_grab_deny_list_patterns,
- g_ptr_array_unref);
- settings->xwayland_grab_deny_list_patterns =
- g_ptr_array_new_with_free_func ((GDestroyNotify) g_pattern_spec_free);
-
- /* Add system defaults values */
- system_defaults = g_strsplit (XWAYLAND_GRAB_DEFAULT_ACCESS_RULES, ",", -1);
- for (i = 0; system_defaults[i]; i++)
- xwayland_grab_list_add_item (settings, system_defaults[i]);
- g_strfreev (system_defaults);
-
- /* Then add gsettings values */
- g_settings_get_mapped (settings->wayland_settings,
- "xwayland-grab-access-rules",
- xwayland_grab_access_rules_handler,
- settings);
-}
-
-static void
-update_xwayland_allow_grabs (MetaSettings *settings)
-{
- settings->xwayland_allow_grabs =
- g_settings_get_boolean (settings->wayland_settings,
- "xwayland-allow-grabs");
-}
-
-static void
-update_xwayland_disable_extensions (MetaSettings *settings)
-{
- settings->xwayland_disable_extensions =
- g_settings_get_flags (settings->wayland_settings,
- "xwayland-disable-extension");
-}
-
-static void
-wayland_settings_changed (GSettings *wayland_settings,
- gchar *key,
- MetaSettings *settings)
-{
-
- if (g_str_equal (key, "xwayland-allow-grabs"))
- {
- update_xwayland_allow_grabs (settings);
- }
- else if (g_str_equal (key, "xwayland-grab-access-rules"))
- {
- update_xwayland_grab_access_rules (settings);
- }
- else if (g_str_equal (key, "xwayland-disable-extension"))
- {
- update_xwayland_disable_extensions (settings);
- }
-}
-
-void
-meta_settings_get_xwayland_grab_patterns (MetaSettings *settings,
- GPtrArray **allow_list_patterns,
- GPtrArray **deny_list_patterns)
-{
- *allow_list_patterns = settings->xwayland_grab_allow_list_patterns;
- *deny_list_patterns = settings->xwayland_grab_deny_list_patterns;
-}
-
-gboolean
-meta_settings_are_xwayland_grabs_allowed (MetaSettings *settings)
-{
- return (settings->xwayland_allow_grabs);
-}
-
-int
-meta_settings_get_xwayland_disable_extensions (MetaSettings *settings)
-{
- return (settings->xwayland_disable_extensions);
-}
-
-MetaSettings *
-meta_settings_new (MetaBackend *backend)
-{
- MetaSettings *settings;
-
- settings = g_object_new (META_TYPE_SETTINGS, NULL);
- settings->backend = backend;
-
- return settings;
-}
-
-static void
-meta_settings_dispose (GObject *object)
-{
- MetaSettings *settings = META_SETTINGS (object);
-
- g_clear_object (&settings->mutter_settings);
- g_clear_object (&settings->interface_settings);
- g_clear_object (&settings->wayland_settings);
- g_clear_pointer (&settings->xwayland_grab_allow_list_patterns,
- g_ptr_array_unref);
- g_clear_pointer (&settings->xwayland_grab_deny_list_patterns,
- g_ptr_array_unref);
-
- G_OBJECT_CLASS (meta_settings_parent_class)->dispose (object);
-}
-
-static void
-meta_settings_init (MetaSettings *settings)
-{
- settings->interface_settings = g_settings_new ("org.gnome.desktop.interface");
- g_signal_connect (settings->interface_settings, "changed",
- G_CALLBACK (interface_settings_changed),
- settings);
- settings->mutter_settings = g_settings_new ("org.gnome.mutter");
- g_signal_connect (settings->mutter_settings, "changed",
- G_CALLBACK (mutter_settings_changed),
- settings);
- settings->wayland_settings = g_settings_new ("org.gnome.mutter.wayland");
- g_signal_connect (settings->wayland_settings, "changed",
- G_CALLBACK (wayland_settings_changed),
- settings);
-
- /* Chain up inter-dependent settings. */
- g_signal_connect (settings, "global-scaling-factor-changed",
- G_CALLBACK (meta_settings_update_ui_scaling_factor), NULL);
- g_signal_connect (settings, "ui-scaling-factor-changed",
- G_CALLBACK (meta_settings_update_font_dpi), NULL);
-
- update_global_scaling_factor (settings);
- update_experimental_features (settings);
- update_xwayland_grab_access_rules (settings);
- update_xwayland_allow_grabs (settings);
- update_xwayland_disable_extensions (settings);
-}
-
-static void
-on_monitors_changed (MetaMonitorManager *monitor_manager,
- MetaSettings *settings)
-{
- meta_settings_update_ui_scaling_factor (settings);
-}
-
-void
-meta_settings_post_init (MetaSettings *settings)
-{
- MetaMonitorManager *monitor_manager =
- meta_backend_get_monitor_manager (settings->backend);
-
- update_ui_scaling_factor (settings);
- update_font_dpi (settings);
-
- g_signal_connect_object (monitor_manager, "monitors-changed-internal",
- G_CALLBACK (on_monitors_changed),
- settings, G_CONNECT_AFTER);
-}
-
-static void
-meta_settings_class_init (MetaSettingsClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- object_class->dispose = meta_settings_dispose;
-
- signals[UI_SCALING_FACTOR_CHANGED] =
- g_signal_new ("ui-scaling-factor-changed",
- G_TYPE_FROM_CLASS (object_class),
- G_SIGNAL_RUN_LAST,
- 0,
- NULL, NULL, NULL,
- G_TYPE_NONE, 0);
-
- signals[GLOBAL_SCALING_FACTOR_CHANGED] =
- g_signal_new ("global-scaling-factor-changed",
- G_TYPE_FROM_CLASS (object_class),
- G_SIGNAL_RUN_LAST,
- 0,
- NULL, NULL, NULL,
- G_TYPE_NONE, 0);
-
- signals[FONT_DPI_CHANGED] =
- g_signal_new ("font-dpi-changed",
- G_TYPE_FROM_CLASS (object_class),
- G_SIGNAL_RUN_LAST,
- 0,
- NULL, NULL, NULL,
- G_TYPE_NONE, 0);
-
- signals[EXPERIMENTAL_FEATURES_CHANGED] =
- g_signal_new ("experimental-features-changed",
- G_TYPE_FROM_CLASS (object_class),
- G_SIGNAL_RUN_LAST,
- 0,
- NULL, NULL, NULL,
- G_TYPE_NONE, 1, G_TYPE_UINT);
-}
diff --git a/src/backends/meta-stage-impl-private.h b/src/backends/meta-stage-impl-private.h
deleted file mode 100644
index ab3e0d391..000000000
--- a/src/backends/meta-stage-impl-private.h
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * Copyright (C) 2007,2008,2009,2010,2011 Intel Corporation.
- * Copyright (C) 2021 Red Hat
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
- *
- * Written by:
- * Matthew Allum
- * Robert Bragg
- * Neil Roberts
- * Emmanuele Bassi
- *
- */
-
-#ifndef META_STAGE_IMPL_PRIVATE_H
-#define META_STAGE_IMPL_PRIVATE_H
-
-#include <cairo.h>
-
-#include "clutter/clutter.h"
-
-G_BEGIN_DECLS
-
-#define META_TYPE_STAGE_IMPL (meta_stage_impl_get_type ())
-#define META_STAGE_IMPL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), META_TYPE_STAGE_IMPL, MetaStageImpl))
-#define META_IS_STAGE_IMPL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), META_TYPE_STAGE_IMPL))
-#define META_STAGE_IMPL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), META_TYPE_STAGE_IMPL, MetaStageImplClass))
-#define META_IS_STAGE_IMPL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), META_TYPE_STAGE_IMPL))
-#define META_STAGE_IMPL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), META_TYPE_STAGE_IMPL, MetaStageImplClass))
-
-typedef struct _MetaStageImpl MetaStageImpl;
-typedef struct _MetaStageImplClass MetaStageImplClass;
-
-G_DEFINE_AUTOPTR_CLEANUP_FUNC (MetaStageImpl, g_object_unref)
-
-#define META_TYPE_STAGE_VIEW (meta_stage_view_get_type ())
-
-struct _MetaStageImpl
-{
- GObject parent_instance;
-
- /* the stage wrapper */
- ClutterStage *wrapper;
-
- /* back pointer to the backend */
- ClutterBackend *backend;
-};
-
-struct _MetaStageImplClass
-{
- GObjectClass parent_class;
-};
-
-GType meta_stage_impl_get_type (void) G_GNUC_CONST;
-
-void meta_stage_impl_presented (MetaStageImpl *stage_impl,
- CoglFrameEvent frame_event,
- ClutterFrameInfo *frame_info);
-
-void meta_stage_impl_add_onscreen_frame_info (MetaStageImpl *stage_impl,
- ClutterStageView *view);
-
-G_END_DECLS
-
-#endif /* META_STAGE_IMPL_PRIVATE_H */
diff --git a/src/backends/meta-stage-impl.c b/src/backends/meta-stage-impl.c
deleted file mode 100644
index 28534ec81..000000000
--- a/src/backends/meta-stage-impl.c
+++ /dev/null
@@ -1,756 +0,0 @@
-/*
- * Clutter.
- *
- * An OpenGL based 'interactive canvas' library.
- *
- * Copyright (C) 2007,2008,2009,2010,2011 Intel Corporation.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
-
- * Authors:
- * Matthew Allum
- * Robert Bragg
- * Neil Roberts
- * Emmanuele Bassi
- */
-
-#include "config.h"
-
-#include "backends/meta-stage-impl-private.h"
-
-#include <stdlib.h>
-#include <math.h>
-
-#include "backends/meta-stage-view-private.h"
-#include "clutter/clutter-mutter.h"
-#include "cogl/cogl.h"
-#include "core/util-private.h"
-
-#define MAX_STACK_RECTS 256
-
-typedef struct _MetaStageImplPrivate
-{
- int64_t global_frame_counter;
-} MetaStageImplPrivate;
-
-static void
-clutter_stage_window_iface_init (ClutterStageWindowInterface *iface);
-
-G_DEFINE_TYPE_WITH_CODE (MetaStageImpl,
- meta_stage_impl,
- G_TYPE_OBJECT,
- G_ADD_PRIVATE (MetaStageImpl)
- G_IMPLEMENT_INTERFACE (CLUTTER_TYPE_STAGE_WINDOW,
- clutter_stage_window_iface_init));
-
-enum
-{
- PROP_0,
- PROP_WRAPPER,
- PROP_BACKEND,
- PROP_LAST
-};
-
-static void
-meta_stage_impl_unrealize (ClutterStageWindow *stage_window)
-{
- meta_topic (META_DEBUG_BACKEND, "Unrealizing Cogl stage [%p]", stage_window);
-}
-
-static gboolean
-meta_stage_impl_realize (ClutterStageWindow *stage_window)
-{
- ClutterBackend *backend;
-
- meta_topic (META_DEBUG_BACKEND,
- "Realizing stage '%s' [%p]",
- G_OBJECT_TYPE_NAME (stage_window),
- stage_window);
-
- backend = clutter_get_default_backend ();
-
- if (backend->cogl_context == NULL)
- {
- g_warning ("Failed to realize stage: missing Cogl context");
- return FALSE;
- }
-
- return TRUE;
-}
-
-static int64_t
-meta_stage_impl_get_frame_counter (ClutterStageWindow *stage_window)
-{
- MetaStageImpl *stage_impl = META_STAGE_IMPL (stage_window);
- MetaStageImplPrivate *priv =
- meta_stage_impl_get_instance_private (stage_impl);
-
- return priv->global_frame_counter;
-}
-
-static ClutterActor *
-meta_stage_impl_get_wrapper (ClutterStageWindow *stage_window)
-{
- return CLUTTER_ACTOR (META_STAGE_IMPL (stage_window)->wrapper);
-}
-
-static void
-meta_stage_impl_show (ClutterStageWindow *stage_window,
- gboolean do_raise)
-{
- MetaStageImpl *stage_impl = META_STAGE_IMPL (stage_window);
-
- clutter_actor_map (CLUTTER_ACTOR (stage_impl->wrapper));
-}
-
-static void
-meta_stage_impl_hide (ClutterStageWindow *stage_window)
-{
- MetaStageImpl *stage_impl = META_STAGE_IMPL (stage_window);
-
- clutter_actor_unmap (CLUTTER_ACTOR (stage_impl->wrapper));
-}
-
-static void
-meta_stage_impl_resize (ClutterStageWindow *stage_window,
- gint width,
- gint height)
-{
-}
-
-static void
-paint_damage_region (ClutterStageWindow *stage_window,
- ClutterStageView *view,
- cairo_region_t *swap_region,
- cairo_region_t *queued_redraw_clip)
-{
- CoglFramebuffer *framebuffer = clutter_stage_view_get_framebuffer (view);
- CoglContext *ctx = cogl_framebuffer_get_context (framebuffer);
- static CoglPipeline *overlay_blue = NULL;
- MetaStageImpl *stage_impl = META_STAGE_IMPL (stage_window);
- ClutterActor *actor = CLUTTER_ACTOR (stage_impl->wrapper);
- graphene_matrix_t transform;
- int n_rects, i;
-
- cogl_framebuffer_push_matrix (framebuffer);
- clutter_actor_get_transform (actor, &transform);
- cogl_framebuffer_transform (framebuffer, &transform);
-
- /* Blue for the swap region */
- if (G_UNLIKELY (overlay_blue == NULL))
- {
- overlay_blue = cogl_pipeline_new (ctx);
- cogl_pipeline_set_color4ub (overlay_blue, 0x00, 0x00, 0x33, 0x33);
- }
-
- n_rects = cairo_region_num_rectangles (swap_region);
- for (i = 0; i < n_rects; i++)
- {
- cairo_rectangle_int_t rect;
- float x_1, x_2, y_1, y_2;
-
- cairo_region_get_rectangle (swap_region, i, &rect);
- x_1 = rect.x;
- x_2 = rect.x + rect.width;
- y_1 = rect.y;
- y_2 = rect.y + rect.height;
-
- cogl_framebuffer_draw_rectangle (framebuffer, overlay_blue, x_1, y_1, x_2, y_2);
- }
-
- /* Red for the clip */
- if (queued_redraw_clip)
- {
- static CoglPipeline *overlay_red = NULL;
-
- if (G_UNLIKELY (overlay_red == NULL))
- {
- overlay_red = cogl_pipeline_new (ctx);
- cogl_pipeline_set_color4ub (overlay_red, 0x33, 0x00, 0x00, 0x33);
- }
-
- n_rects = cairo_region_num_rectangles (queued_redraw_clip);
- for (i = 0; i < n_rects; i++)
- {
- cairo_rectangle_int_t rect;
- float x_1, x_2, y_1, y_2;
-
- cairo_region_get_rectangle (queued_redraw_clip, i, &rect);
- x_1 = rect.x;
- x_2 = rect.x + rect.width;
- y_1 = rect.y;
- y_2 = rect.y + rect.height;
-
- cogl_framebuffer_draw_rectangle (framebuffer, overlay_red, x_1, y_1, x_2, y_2);
- }
- }
-
- cogl_framebuffer_pop_matrix (framebuffer);
-}
-
-static void
-swap_framebuffer (ClutterStageWindow *stage_window,
- ClutterStageView *stage_view,
- cairo_region_t *swap_region,
- gboolean swap_with_damage,
- ClutterFrame *frame)
-{
- MetaStageImpl *stage_impl = META_STAGE_IMPL (stage_window);
- MetaStageImplPrivate *priv =
- meta_stage_impl_get_instance_private (stage_impl);
- CoglFramebuffer *framebuffer = clutter_stage_view_get_onscreen (stage_view);
- CoglContext *cogl_context = cogl_framebuffer_get_context (framebuffer);
-
- clutter_stage_view_before_swap_buffer (stage_view, swap_region);
-
- if (COGL_IS_ONSCREEN (framebuffer))
- {
- CoglOnscreen *onscreen = COGL_ONSCREEN (framebuffer);
- int *damage, n_rects, i;
- CoglFrameInfo *frame_info;
-
- n_rects = cairo_region_num_rectangles (swap_region);
- damage = g_newa (int, n_rects * 4);
- for (i = 0; i < n_rects; i++)
- {
- cairo_rectangle_int_t rect;
-
- cairo_region_get_rectangle (swap_region, i, &rect);
- damage[i * 4] = rect.x;
- damage[i * 4 + 1] = rect.y;
- damage[i * 4 + 2] = rect.width;
- damage[i * 4 + 3] = rect.height;
- }
-
- frame_info =
- cogl_frame_info_new (cogl_context, priv->global_frame_counter);
- priv->global_frame_counter++;
-
- /* push on the screen */
- if (n_rects > 0 && !swap_with_damage)
- {
- meta_topic (META_DEBUG_BACKEND,
- "cogl_onscreen_swap_region (onscreen: %p)",
- onscreen);
-
- cogl_onscreen_swap_region (onscreen,
- damage, n_rects,
- frame_info,
- frame);
- }
- else
- {
- meta_topic (META_DEBUG_BACKEND,
- "cogl_onscreen_swap_buffers (onscreen: %p)",
- onscreen);
-
- cogl_onscreen_swap_buffers_with_damage (onscreen,
- damage, n_rects,
- frame_info,
- frame);
- }
- }
- else
- {
- MetaStageView *view = META_STAGE_VIEW (stage_view);
-
- meta_topic (META_DEBUG_BACKEND,
- "fake offscreen swap (framebuffer: %p)",
- framebuffer);
- meta_stage_view_perform_fake_swap (view, priv->global_frame_counter);
- priv->global_frame_counter++;
- }
-}
-
-static cairo_region_t *
-offset_scale_and_clamp_region (const cairo_region_t *region,
- int offset_x,
- int offset_y,
- float scale)
-{
- int n_rects, i;
- cairo_rectangle_int_t *rects;
- g_autofree cairo_rectangle_int_t *freeme = NULL;
-
- n_rects = cairo_region_num_rectangles (region);
-
- if (n_rects == 0)
- return cairo_region_create ();
-
- if (n_rects < MAX_STACK_RECTS)
- rects = g_newa (cairo_rectangle_int_t, n_rects);
- else
- rects = freeme = g_new (cairo_rectangle_int_t, n_rects);
-
- for (i = 0; i < n_rects; i++)
- {
- cairo_rectangle_int_t *rect = &rects[i];
- graphene_rect_t tmp;
-
- cairo_region_get_rectangle (region, i, rect);
-
- _clutter_util_rect_from_rectangle (rect, &tmp);
- graphene_rect_offset (&tmp, offset_x, offset_y);
- graphene_rect_scale (&tmp, scale, scale, &tmp);
- _clutter_util_rectangle_int_extents (&tmp, rect);
- }
-
- return cairo_region_create_rectangles (rects, n_rects);
-}
-
-static cairo_region_t *
-scale_offset_and_clamp_region (const cairo_region_t *region,
- float scale,
- int offset_x,
- int offset_y)
-{
- int n_rects, i;
- cairo_rectangle_int_t *rects;
- g_autofree cairo_rectangle_int_t *freeme = NULL;
-
- n_rects = cairo_region_num_rectangles (region);
-
- if (n_rects == 0)
- return cairo_region_create ();
-
- if (n_rects < MAX_STACK_RECTS)
- rects = g_newa (cairo_rectangle_int_t, n_rects);
- else
- rects = freeme = g_new (cairo_rectangle_int_t, n_rects);
-
- for (i = 0; i < n_rects; i++)
- {
- cairo_rectangle_int_t *rect = &rects[i];
- graphene_rect_t tmp;
-
- cairo_region_get_rectangle (region, i, rect);
-
- _clutter_util_rect_from_rectangle (rect, &tmp);
- graphene_rect_scale (&tmp, scale, scale, &tmp);
- graphene_rect_offset (&tmp, offset_x, offset_y);
- _clutter_util_rectangle_int_extents (&tmp, rect);
- }
-
- return cairo_region_create_rectangles (rects, n_rects);
-}
-
-static void
-paint_stage (MetaStageImpl *stage_impl,
- ClutterStageView *stage_view,
- cairo_region_t *redraw_clip)
-{
- ClutterStage *stage = stage_impl->wrapper;
-
- _clutter_stage_maybe_setup_viewport (stage, stage_view);
- clutter_stage_paint_view (stage, stage_view, redraw_clip);
-
- clutter_stage_view_after_paint (stage_view, redraw_clip);
-}
-
-static cairo_region_t *
-transform_swap_region_to_onscreen (ClutterStageView *stage_view,
- cairo_region_t *swap_region)
-{
- CoglFramebuffer *onscreen = clutter_stage_view_get_onscreen (stage_view);
- int n_rects, i;
- cairo_rectangle_int_t *rects;
- cairo_region_t *transformed_region;
- int width, height;
-
- width = cogl_framebuffer_get_width (onscreen);
- height = cogl_framebuffer_get_height (onscreen);
-
- n_rects = cairo_region_num_rectangles (swap_region);
- rects = g_newa (cairo_rectangle_int_t, n_rects);
- for (i = 0; i < n_rects; i++)
- {
- cairo_region_get_rectangle (swap_region, i, &rects[i]);
- clutter_stage_view_transform_rect_to_onscreen (stage_view,
- &rects[i],
- width,
- height,
- &rects[i]);
- }
- transformed_region = cairo_region_create_rectangles (rects, n_rects);
-
- return transformed_region;
-}
-
-static void
-meta_stage_impl_redraw_view_primary (MetaStageImpl *stage_impl,
- ClutterStageView *stage_view,
- ClutterFrame *frame)
-{
- ClutterStageWindow *stage_window = CLUTTER_STAGE_WINDOW (stage_impl);
- MetaStageView *view = META_STAGE_VIEW (stage_view);
- CoglFramebuffer *fb = clutter_stage_view_get_framebuffer (stage_view);
- CoglFramebuffer *onscreen = clutter_stage_view_get_onscreen (stage_view);
- cairo_rectangle_int_t view_rect;
- gboolean is_full_redraw;
- gboolean use_clipped_redraw = TRUE;
- gboolean can_blit_sub_buffer;
- gboolean has_buffer_age;
- gboolean swap_with_damage;
- cairo_region_t *redraw_clip;
- cairo_region_t *queued_redraw_clip = NULL;
- cairo_region_t *fb_clip_region;
- cairo_region_t *swap_region;
- ClutterDrawDebugFlag paint_debug_flags;
- ClutterDamageHistory *damage_history;
- float fb_scale;
- int fb_width, fb_height;
- int buffer_age = 0;
-
- clutter_stage_view_get_layout (stage_view, &view_rect);
- fb_scale = clutter_stage_view_get_scale (stage_view);
- fb_width = cogl_framebuffer_get_width (fb);
- fb_height = cogl_framebuffer_get_height (fb);
-
- can_blit_sub_buffer =
- COGL_IS_ONSCREEN (onscreen) &&
- cogl_clutter_winsys_has_feature (COGL_WINSYS_FEATURE_SWAP_REGION);
-
- has_buffer_age =
- COGL_IS_ONSCREEN (onscreen) &&
- cogl_clutter_winsys_has_feature (COGL_WINSYS_FEATURE_BUFFER_AGE);
-
- redraw_clip = clutter_stage_view_take_redraw_clip (stage_view);
-
- /* NB: a NULL redraw clip == full stage redraw */
- if (!redraw_clip)
- is_full_redraw = TRUE;
- else
- is_full_redraw = FALSE;
-
- damage_history = meta_stage_view_get_damage_history (view);
-
- if (has_buffer_age)
- {
- buffer_age = cogl_onscreen_get_buffer_age (COGL_ONSCREEN (onscreen));
- if (!clutter_damage_history_is_age_valid (damage_history, buffer_age))
- {
- meta_topic (META_DEBUG_BACKEND,
- "Invalid back buffer(age=%d): forcing full redraw",
- buffer_age);
- use_clipped_redraw = FALSE;
- }
- }
-
- meta_get_clutter_debug_flags (NULL, &paint_debug_flags, NULL);
-
- use_clipped_redraw =
- use_clipped_redraw &&
- !(paint_debug_flags & CLUTTER_DEBUG_DISABLE_CLIPPED_REDRAWS) &&
- _clutter_stage_window_can_clip_redraws (stage_window) &&
- (can_blit_sub_buffer || has_buffer_age) &&
- !is_full_redraw &&
- /* some drivers struggle to get going and produce some junk
- * frames when starting up... */
- cogl_onscreen_get_frame_counter (COGL_ONSCREEN (onscreen)) > 3;
-
- if (use_clipped_redraw)
- {
- fb_clip_region = offset_scale_and_clamp_region (redraw_clip,
- -view_rect.x,
- -view_rect.y,
- fb_scale);
-
- if (G_UNLIKELY (paint_debug_flags & CLUTTER_DEBUG_PAINT_DAMAGE_REGION))
- {
- queued_redraw_clip =
- scale_offset_and_clamp_region (fb_clip_region,
- 1.0 / fb_scale,
- view_rect.x,
- view_rect.y);
- }
- }
- else
- {
- cairo_rectangle_int_t fb_rect;
-
- fb_rect = (cairo_rectangle_int_t) {
- .width = fb_width,
- .height = fb_height,
- };
- fb_clip_region = cairo_region_create_rectangle (&fb_rect);
-
- g_clear_pointer (&redraw_clip, cairo_region_destroy);
- redraw_clip = cairo_region_create_rectangle (&view_rect);
-
- if (G_UNLIKELY (paint_debug_flags & CLUTTER_DEBUG_PAINT_DAMAGE_REGION))
- queued_redraw_clip = cairo_region_reference (redraw_clip);
- }
-
- g_return_if_fail (!cairo_region_is_empty (fb_clip_region));
-
- swap_with_damage = FALSE;
- if (has_buffer_age)
- {
- clutter_damage_history_record (damage_history, fb_clip_region);
-
- if (use_clipped_redraw)
- {
- int age;
-
- for (age = 1; age <= buffer_age; age++)
- {
- const cairo_region_t *old_damage;
-
- old_damage =
- clutter_damage_history_lookup (damage_history, age);
- cairo_region_union (fb_clip_region, old_damage);
- }
-
- meta_topic (META_DEBUG_BACKEND,
- "Reusing back buffer(age=%d) - repairing region: num rects: %d",
- buffer_age,
- cairo_region_num_rectangles (fb_clip_region));
-
- swap_with_damage = TRUE;
- }
-
- clutter_damage_history_step (damage_history);
- }
-
- if (use_clipped_redraw)
- {
- /* Regenerate redraw_clip because:
- * 1. It's missing the regions added from damage_history above; and
- * 2. If using fractional scaling then it might be a fraction of a
- * logical pixel (or one physical pixel) smaller than
- * fb_clip_region, due to the clamping from
- * offset_scale_and_clamp_region. So we need to ensure redraw_clip
- * is a superset of fb_clip_region to avoid such gaps.
- */
- cairo_region_destroy (redraw_clip);
- redraw_clip = scale_offset_and_clamp_region (fb_clip_region,
- 1.0 / fb_scale,
- view_rect.x,
- view_rect.y);
- }
-
- if (paint_debug_flags & CLUTTER_DEBUG_PAINT_DAMAGE_REGION)
- {
- cairo_region_t *debug_redraw_clip;
-
- debug_redraw_clip = cairo_region_create_rectangle (&view_rect);
- paint_stage (stage_impl, stage_view, debug_redraw_clip);
- cairo_region_destroy (debug_redraw_clip);
- }
- else if (use_clipped_redraw)
- {
- cogl_framebuffer_push_region_clip (fb, fb_clip_region);
-
- paint_stage (stage_impl, stage_view, redraw_clip);
-
- cogl_framebuffer_pop_clip (fb);
- }
- else
- {
- meta_topic (META_DEBUG_BACKEND, "Unclipped stage paint");
-
- paint_stage (stage_impl, stage_view, redraw_clip);
- }
-
- /* XXX: It seems there will be a race here in that the stage
- * window may be resized before the cogl_onscreen_swap_region
- * is handled and so we may copy the wrong region. I can't
- * really see how we can handle this with the current state of X
- * but at least in this case a full redraw should be queued by
- * the resize anyway so it should only exhibit temporary
- * artefacts.
- */
- if (use_clipped_redraw)
- swap_region = cairo_region_reference (fb_clip_region);
- else
- swap_region = cairo_region_create ();
-
- g_clear_pointer (&redraw_clip, cairo_region_destroy);
- g_clear_pointer (&fb_clip_region, cairo_region_destroy);
-
- COGL_TRACE_BEGIN_SCOPED (MetaStageImplRedrawViewSwapFramebuffer,
- "Paint (swap framebuffer)");
-
- if (clutter_stage_view_get_onscreen (stage_view) !=
- clutter_stage_view_get_framebuffer (stage_view))
- {
- cairo_region_t *transformed_swap_region;
-
- transformed_swap_region =
- transform_swap_region_to_onscreen (stage_view, swap_region);
- cairo_region_destroy (swap_region);
- swap_region = transformed_swap_region;
- }
-
- if (queued_redraw_clip)
- {
- cairo_region_t *swap_region_in_stage_space;
-
- swap_region_in_stage_space =
- scale_offset_and_clamp_region (swap_region,
- 1.0f / fb_scale,
- view_rect.x,
- view_rect.y);
-
- cairo_region_subtract (swap_region_in_stage_space, queued_redraw_clip);
-
- paint_damage_region (stage_window, stage_view,
- swap_region_in_stage_space, queued_redraw_clip);
-
- cairo_region_destroy (queued_redraw_clip);
- cairo_region_destroy (swap_region_in_stage_space);
- }
-
- swap_framebuffer (stage_window,
- stage_view,
- swap_region,
- swap_with_damage,
- frame);
-
- cairo_region_destroy (swap_region);
-}
-
-static gboolean
-meta_stage_impl_scanout_view (MetaStageImpl *stage_impl,
- ClutterStageView *stage_view,
- CoglScanout *scanout,
- ClutterFrame *frame,
- GError **error)
-{
- MetaStageImplPrivate *priv =
- meta_stage_impl_get_instance_private (stage_impl);
- CoglFramebuffer *framebuffer =
- clutter_stage_view_get_framebuffer (stage_view);
- CoglContext *cogl_context = cogl_framebuffer_get_context (framebuffer);
- CoglOnscreen *onscreen;
- CoglFrameInfo *frame_info;
-
- g_assert (COGL_IS_ONSCREEN (framebuffer));
-
- onscreen = COGL_ONSCREEN (framebuffer);
-
- frame_info = cogl_frame_info_new (cogl_context, priv->global_frame_counter);
-
- if (!cogl_onscreen_direct_scanout (onscreen,
- scanout,
- frame_info,
- frame,
- error))
- {
- cogl_object_unref (frame_info);
- return FALSE;
- }
-
- priv->global_frame_counter++;
-
- return TRUE;
-}
-
-static void
-meta_stage_impl_redraw_view (ClutterStageWindow *stage_window,
- ClutterStageView *stage_view,
- ClutterFrame *frame)
-{
- MetaStageImpl *stage_impl = META_STAGE_IMPL (stage_window);
- g_autoptr (CoglScanout) scanout = NULL;
-
- scanout = clutter_stage_view_take_scanout (stage_view);
- if (scanout)
- {
- g_autoptr (GError) error = NULL;
-
- if (meta_stage_impl_scanout_view (stage_impl,
- stage_view,
- scanout,
- frame,
- &error))
- return;
-
- if (!g_error_matches (error,
- COGL_SCANOUT_ERROR,
- COGL_SCANOUT_ERROR_INHIBITED))
- g_warning ("Failed to scan out client buffer: %s", error->message);
- }
-
- meta_stage_impl_redraw_view_primary (stage_impl, stage_view, frame);
-}
-
-void
-meta_stage_impl_add_onscreen_frame_info (MetaStageImpl *stage_impl,
- ClutterStageView *stage_view)
-{
- MetaStageImplPrivate *priv =
- meta_stage_impl_get_instance_private (stage_impl);
- CoglFramebuffer *framebuffer = clutter_stage_view_get_onscreen (stage_view);
- CoglContext *cogl_context = cogl_framebuffer_get_context (framebuffer);
- CoglFrameInfo *frame_info;
-
- frame_info = cogl_frame_info_new (cogl_context, priv->global_frame_counter);
- priv->global_frame_counter++;
-
- cogl_onscreen_add_frame_info (COGL_ONSCREEN (framebuffer), frame_info);
-}
-
-static void
-clutter_stage_window_iface_init (ClutterStageWindowInterface *iface)
-{
- iface->realize = meta_stage_impl_realize;
- iface->unrealize = meta_stage_impl_unrealize;
- iface->get_wrapper = meta_stage_impl_get_wrapper;
- iface->resize = meta_stage_impl_resize;
- iface->show = meta_stage_impl_show;
- iface->hide = meta_stage_impl_hide;
- iface->get_frame_counter = meta_stage_impl_get_frame_counter;
- iface->redraw_view = meta_stage_impl_redraw_view;
-}
-
-static void
-meta_stage_impl_set_property (GObject *gobject,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- MetaStageImpl *self = META_STAGE_IMPL (gobject);
-
- switch (prop_id)
- {
- case PROP_WRAPPER:
- self->wrapper = g_value_get_object (value);
- break;
-
- case PROP_BACKEND:
- self->backend = g_value_get_object (value);
- break;
-
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
- break;
- }
-}
-
-static void
-meta_stage_impl_class_init (MetaStageImplClass *klass)
-{
- GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
-
- gobject_class->set_property = meta_stage_impl_set_property;
-
- g_object_class_override_property (gobject_class, PROP_WRAPPER, "wrapper");
- g_object_class_override_property (gobject_class, PROP_BACKEND, "backend");
-}
-
-static void
-meta_stage_impl_init (MetaStageImpl *stage)
-{
-}
diff --git a/src/backends/meta-stage-private.h b/src/backends/meta-stage-private.h
deleted file mode 100644
index 07534f6e3..000000000
--- a/src/backends/meta-stage-private.h
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * Copyright (C) 2012 Intel Corporation
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-
-#ifndef META_STAGE_PRIVATE_H
-#define META_STAGE_PRIVATE_H
-
-#include "backends/meta-cursor.h"
-#include "core/util-private.h"
-#include "meta/boxes.h"
-#include "meta/meta-stage.h"
-#include "meta/types.h"
-
-G_BEGIN_DECLS
-
-typedef struct _MetaStageWatch MetaStageWatch;
-typedef struct _MetaOverlay MetaOverlay;
-
-typedef enum
-{
- META_STAGE_WATCH_BEFORE_PAINT,
- META_STAGE_WATCH_AFTER_ACTOR_PAINT,
- META_STAGE_WATCH_AFTER_OVERLAY_PAINT,
- META_STAGE_WATCH_AFTER_PAINT,
-} MetaStageWatchPhase;
-
-typedef void (* MetaStageWatchFunc) (MetaStage *stage,
- ClutterStageView *view,
- ClutterPaintContext *paint_context,
- gpointer user_data);
-
-ClutterActor *meta_stage_new (MetaBackend *backend);
-
-MetaOverlay *meta_stage_create_cursor_overlay (MetaStage *stage);
-void meta_stage_remove_cursor_overlay (MetaStage *stage,
- MetaOverlay *overlay);
-
-void meta_stage_update_cursor_overlay (MetaStage *stage,
- MetaOverlay *overlay,
- CoglTexture *texture,
- graphene_rect_t *rect);
-
-void meta_overlay_set_visible (MetaOverlay *overlay,
- gboolean is_visible);
-
-gboolean meta_overlay_is_visible (MetaOverlay *overlay);
-
-void meta_stage_set_active (MetaStage *stage,
- gboolean is_active);
-
-META_EXPORT_TEST
-MetaStageWatch * meta_stage_watch_view (MetaStage *stage,
- ClutterStageView *view,
- MetaStageWatchPhase watch_mode,
- MetaStageWatchFunc callback,
- gpointer user_data);
-
-META_EXPORT_TEST
-void meta_stage_remove_watch (MetaStage *stage,
- MetaStageWatch *watch);
-
-G_END_DECLS
-
-#endif /* META_STAGE_PRIVATE_H */
diff --git a/src/backends/meta-stage-view-private.h b/src/backends/meta-stage-view-private.h
deleted file mode 100644
index aaf3f31eb..000000000
--- a/src/backends/meta-stage-view-private.h
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Copyright (C) 2007,2008,2009,2010,2011 Intel Corporation.
- * Copyright (C) 2021 Red Hat
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
- *
- * Written by:
- * Matthew Allum
- * Robert Bragg
- * Neil Roberts
- * Emmanuele Bassi
- *
- */
-
-#ifndef META_STAGE_VIEW_H
-#define META_STAGE_VIEW_H
-
-#include <cairo.h>
-
-#include "clutter/clutter-mutter.h"
-
-G_BEGIN_DECLS
-
-#define META_TYPE_STAGE_VIEW (meta_stage_view_get_type ())
-
-G_DECLARE_DERIVABLE_TYPE (MetaStageView,
- meta_stage_view,
- META, STAGE_VIEW,
- ClutterStageView)
-
-struct _MetaStageViewClass
-{
- ClutterStageViewClass parent_class;
-};
-
-ClutterDamageHistory * meta_stage_view_get_damage_history (MetaStageView *view);
-void meta_stage_view_perform_fake_swap (MetaStageView *view,
- int64_t counter);
-
-#endif /* META_STAGE_VIEW_H */
diff --git a/src/backends/meta-stage-view.c b/src/backends/meta-stage-view.c
deleted file mode 100644
index 473943196..000000000
--- a/src/backends/meta-stage-view.c
+++ /dev/null
@@ -1,204 +0,0 @@
-/*
- * Copyright (C) 2007,2008,2009,2010,2011 Intel Corporation.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
-
- * Authors:
- * Matthew Allum
- * Robert Bragg
- * Neil Roberts
- * Emmanuele Bassi
- */
-
-#include "config.h"
-
-#include "meta-stage-view-private.h"
-
-typedef struct _MetaStageViewPrivate
-{
- /* Damage history, in stage view render target framebuffer coordinate space.
- */
- ClutterDamageHistory *damage_history;
-
- guint notify_presented_handle_id;
-
- CoglFrameClosure *frame_cb_closure;
-} MetaStageViewPrivate;
-
-G_DEFINE_TYPE_WITH_PRIVATE (MetaStageView, meta_stage_view,
- CLUTTER_TYPE_STAGE_VIEW)
-
-static void
-frame_cb (CoglOnscreen *onscreen,
- CoglFrameEvent frame_event,
- CoglFrameInfo *frame_info,
- void *user_data)
-{
- ClutterStageView *view = user_data;
-
- if (frame_event == COGL_FRAME_EVENT_SYNC)
- return;
-
- if (cogl_frame_info_get_is_symbolic (frame_info))
- {
- clutter_stage_view_notify_ready (view);
- }
- else
- {
- ClutterFrameInfo clutter_frame_info;
- ClutterFrameInfoFlag flags = CLUTTER_FRAME_INFO_FLAG_NONE;
-
- if (cogl_frame_info_is_hw_clock (frame_info))
- flags |= CLUTTER_FRAME_INFO_FLAG_HW_CLOCK;
-
- if (cogl_frame_info_is_zero_copy (frame_info))
- flags |= CLUTTER_FRAME_INFO_FLAG_ZERO_COPY;
-
- if (cogl_frame_info_is_vsync (frame_info))
- flags |= CLUTTER_FRAME_INFO_FLAG_VSYNC;
-
- clutter_frame_info = (ClutterFrameInfo) {
- .frame_counter = cogl_frame_info_get_global_frame_counter (frame_info),
- .refresh_rate = cogl_frame_info_get_refresh_rate (frame_info),
- .presentation_time =
- cogl_frame_info_get_presentation_time_us (frame_info),
- .flags = flags,
- .sequence = cogl_frame_info_get_sequence (frame_info),
- .gpu_rendering_duration_ns =
- cogl_frame_info_get_rendering_duration_ns (frame_info),
- .cpu_time_before_buffer_swap_us =
- cogl_frame_info_get_time_before_buffer_swap_us (frame_info),
- };
- clutter_stage_view_notify_presented (view, &clutter_frame_info);
- }
-}
-
-static void
-meta_stage_view_dispose (GObject *object)
-{
- MetaStageView *view = META_STAGE_VIEW (object);
- MetaStageViewPrivate *priv =
- meta_stage_view_get_instance_private (view);
- ClutterStageView *stage_view = CLUTTER_STAGE_VIEW (view);
-
- g_clear_handle_id (&priv->notify_presented_handle_id, g_source_remove);
- g_clear_pointer (&priv->damage_history, clutter_damage_history_free);
-
- if (priv->frame_cb_closure)
- {
- CoglFramebuffer *framebuffer;
-
- framebuffer = clutter_stage_view_get_onscreen (stage_view);
- cogl_onscreen_remove_frame_callback (COGL_ONSCREEN (framebuffer),
- priv->frame_cb_closure);
- priv->frame_cb_closure = NULL;
- }
-
- G_OBJECT_CLASS (meta_stage_view_parent_class)->dispose (object);
-}
-
-static void
-meta_stage_view_constructed (GObject *object)
-{
- MetaStageView *view = META_STAGE_VIEW (object);
- MetaStageViewPrivate *priv =
- meta_stage_view_get_instance_private (view);
- ClutterStageView *stage_view = CLUTTER_STAGE_VIEW (view);
- CoglFramebuffer *framebuffer;
-
- framebuffer = clutter_stage_view_get_onscreen (stage_view);
- if (framebuffer && COGL_IS_ONSCREEN (framebuffer))
- {
- priv->frame_cb_closure =
- cogl_onscreen_add_frame_callback (COGL_ONSCREEN (framebuffer),
- frame_cb,
- view,
- NULL);
- }
-
- G_OBJECT_CLASS (meta_stage_view_parent_class)->constructed (object);
-}
-
-static void
-meta_stage_view_init (MetaStageView *view)
-{
- MetaStageViewPrivate *priv =
- meta_stage_view_get_instance_private (view);
-
- priv->damage_history = clutter_damage_history_new ();
-}
-
-static void
-meta_stage_view_class_init (MetaStageViewClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- object_class->constructed = meta_stage_view_constructed;
- object_class->dispose = meta_stage_view_dispose;
-}
-
-ClutterDamageHistory *
-meta_stage_view_get_damage_history (MetaStageView *view)
-{
- MetaStageViewPrivate *priv =
- meta_stage_view_get_instance_private (view);
-
- return priv->damage_history;
-}
-
-typedef struct _NotifyPresentedClosure
-{
- ClutterStageView *view;
- ClutterFrameInfo frame_info;
-} NotifyPresentedClosure;
-
-static gboolean
-notify_presented_idle (gpointer user_data)
-{
- NotifyPresentedClosure *closure = user_data;
- MetaStageView *view = META_STAGE_VIEW (closure->view);
- MetaStageViewPrivate *priv =
- meta_stage_view_get_instance_private (view);
-
- priv->notify_presented_handle_id = 0;
- clutter_stage_view_notify_presented (closure->view, &closure->frame_info);
-
- return G_SOURCE_REMOVE;
-}
-
-void
-meta_stage_view_perform_fake_swap (MetaStageView *view,
- int64_t counter)
-{
- ClutterStageView *clutter_view = CLUTTER_STAGE_VIEW (view);
- MetaStageViewPrivate *priv =
- meta_stage_view_get_instance_private (view);
- NotifyPresentedClosure *closure;
-
- closure = g_new0 (NotifyPresentedClosure, 1);
- closure->view = clutter_view;
- closure->frame_info = (ClutterFrameInfo) {
- .frame_counter = counter,
- .refresh_rate = clutter_stage_view_get_refresh_rate (clutter_view),
- .presentation_time = g_get_monotonic_time (),
- .flags = CLUTTER_FRAME_INFO_FLAG_NONE,
- .sequence = 0,
- };
-
- g_warn_if_fail (priv->notify_presented_handle_id == 0);
- priv->notify_presented_handle_id =
- g_idle_add_full (G_PRIORITY_DEFAULT,
- notify_presented_idle,
- closure, g_free);
-}
diff --git a/src/backends/meta-stage.c b/src/backends/meta-stage.c
deleted file mode 100644
index 6f8e3feae..000000000
--- a/src/backends/meta-stage.c
+++ /dev/null
@@ -1,485 +0,0 @@
-/*
- * Copyright (C) 2014 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Written by:
- * Jasper St. Pierre <jstpierre@mecheye.net>
- */
-
-#include "config.h"
-
-#include "backends/meta-stage-private.h"
-
-#include "backends/meta-backend-private.h"
-#include "backends/meta-cursor-tracker-private.h"
-#include "clutter/clutter-mutter.h"
-#include "meta/meta-backend.h"
-#include "meta/meta-monitor-manager.h"
-#include "meta/util.h"
-
-#define N_WATCH_MODES 4
-
-enum
-{
- ACTORS_PAINTED,
-
- N_SIGNALS
-};
-
-static guint signals[N_SIGNALS];
-
-struct _MetaStageWatch
-{
- ClutterStageView *view;
- MetaStageWatchFunc callback;
- gpointer user_data;
-};
-
-struct _MetaOverlay
-{
- MetaStage *stage;
-
- gboolean is_visible;
-
- CoglPipeline *pipeline;
- CoglTexture *texture;
-
- graphene_rect_t current_rect;
- graphene_rect_t previous_rect;
- gboolean previous_is_valid;
-};
-
-struct _MetaStage
-{
- ClutterStage parent;
-
- MetaBackend *backend;
-
- GPtrArray *watchers[N_WATCH_MODES];
-
- GList *overlays;
- gboolean is_active;
-};
-
-G_DEFINE_TYPE (MetaStage, meta_stage, CLUTTER_TYPE_STAGE);
-
-static MetaOverlay *
-meta_overlay_new (MetaStage *stage)
-{
- ClutterBackend *clutter_backend =
- meta_backend_get_clutter_backend (stage->backend);
- CoglContext *ctx = clutter_backend_get_cogl_context (clutter_backend);
- MetaOverlay *overlay;
-
- overlay = g_new0 (MetaOverlay, 1);
- overlay->stage = stage;
- overlay->pipeline = cogl_pipeline_new (ctx);
-
- return overlay;
-}
-
-static void
-meta_overlay_free (MetaOverlay *overlay)
-{
- if (overlay->pipeline)
- cogl_object_unref (overlay->pipeline);
-
- g_free (overlay);
-}
-
-static void
-meta_overlay_set (MetaOverlay *overlay,
- CoglTexture *texture,
- graphene_rect_t *rect)
-{
- if (overlay->texture != texture)
- {
- overlay->texture = texture;
-
- if (texture)
- cogl_pipeline_set_layer_texture (overlay->pipeline, 0, texture);
- else
- cogl_pipeline_set_layer_texture (overlay->pipeline, 0, NULL);
- }
-
- overlay->current_rect = *rect;
-}
-
-static void
-meta_overlay_paint (MetaOverlay *overlay,
- ClutterPaintContext *paint_context)
-{
- CoglFramebuffer *framebuffer;
-
- if (!overlay->texture)
- return;
-
- if (!overlay->is_visible &&
- !(clutter_paint_context_get_paint_flags (paint_context) &
- CLUTTER_PAINT_FLAG_FORCE_CURSORS))
- return;
-
- framebuffer = clutter_paint_context_get_framebuffer (paint_context);
- cogl_framebuffer_draw_rectangle (framebuffer,
- overlay->pipeline,
- overlay->current_rect.origin.x,
- overlay->current_rect.origin.y,
- (overlay->current_rect.origin.x +
- overlay->current_rect.size.width),
- (overlay->current_rect.origin.y +
- overlay->current_rect.size.height));
-
- if (!graphene_rect_equal (&overlay->previous_rect, &overlay->current_rect))
- {
- overlay->previous_rect = overlay->current_rect;
- overlay->previous_is_valid = TRUE;
- }
-}
-
-static void
-meta_stage_finalize (GObject *object)
-{
- MetaStage *stage = META_STAGE (object);
- GList *l;
- int i;
-
- l = stage->overlays;
- while (l)
- {
- meta_overlay_free (l->data);
- l = g_list_delete_link (l, l);
- }
-
- for (i = 0; i < N_WATCH_MODES; i++)
- g_clear_pointer (&stage->watchers[i], g_ptr_array_unref);
-
- G_OBJECT_CLASS (meta_stage_parent_class)->finalize (object);
-}
-
-static void
-notify_watchers_for_mode (MetaStage *stage,
- ClutterStageView *view,
- ClutterPaintContext *paint_context,
- MetaStageWatchPhase watch_phase)
-{
- GPtrArray *watchers;
- int i;
-
- watchers = stage->watchers[watch_phase];
-
- for (i = 0; i < watchers->len; i++)
- {
- MetaStageWatch *watch = g_ptr_array_index (watchers, i);
-
- if (watch->view && view != watch->view)
- continue;
-
- watch->callback (stage, view, paint_context, watch->user_data);
- }
-}
-
-static void
-meta_stage_before_paint (ClutterStage *stage,
- ClutterStageView *view)
-{
- MetaStage *meta_stage = META_STAGE (stage);
-
- notify_watchers_for_mode (meta_stage, view, NULL,
- META_STAGE_WATCH_BEFORE_PAINT);
-}
-
-static void
-meta_stage_paint (ClutterActor *actor,
- ClutterPaintContext *paint_context)
-{
- MetaStage *stage = META_STAGE (actor);
- ClutterStageView *view;
-
- CLUTTER_ACTOR_CLASS (meta_stage_parent_class)->paint (actor, paint_context);
-
- view = clutter_paint_context_get_stage_view (paint_context);
- if (view)
- {
- notify_watchers_for_mode (stage, view, paint_context,
- META_STAGE_WATCH_AFTER_ACTOR_PAINT);
- }
-
- g_signal_emit (stage, signals[ACTORS_PAINTED], 0);
-
- if ((clutter_paint_context_get_paint_flags (paint_context) &
- CLUTTER_PAINT_FLAG_FORCE_CURSORS))
- {
- MetaCursorTracker *cursor_tracker =
- meta_backend_get_cursor_tracker (stage->backend);
-
- meta_cursor_tracker_track_position (cursor_tracker);
- }
-
- if (!(clutter_paint_context_get_paint_flags (paint_context) &
- CLUTTER_PAINT_FLAG_NO_CURSORS))
- g_list_foreach (stage->overlays, (GFunc) meta_overlay_paint, paint_context);
-
- if ((clutter_paint_context_get_paint_flags (paint_context) &
- CLUTTER_PAINT_FLAG_FORCE_CURSORS))
- {
- MetaCursorTracker *cursor_tracker =
- meta_backend_get_cursor_tracker (stage->backend);
-
- meta_cursor_tracker_untrack_position (cursor_tracker);
- }
-
- if (view)
- {
- notify_watchers_for_mode (stage, view, paint_context,
- META_STAGE_WATCH_AFTER_OVERLAY_PAINT);
- }
-}
-
-static void
-meta_stage_paint_view (ClutterStage *stage,
- ClutterStageView *view,
- const cairo_region_t *redraw_clip)
-{
- MetaStage *meta_stage = META_STAGE (stage);
-
- CLUTTER_STAGE_CLASS (meta_stage_parent_class)->paint_view (stage, view,
- redraw_clip);
-
- notify_watchers_for_mode (meta_stage, view, NULL,
- META_STAGE_WATCH_AFTER_PAINT);
-}
-
-static void
-meta_stage_activate (ClutterStage *actor)
-{
- MetaStage *stage = META_STAGE (actor);
-
- CLUTTER_STAGE_CLASS (meta_stage_parent_class)->activate (actor);
-
- stage->is_active = TRUE;
-}
-
-static void
-meta_stage_deactivate (ClutterStage *actor)
-{
- MetaStage *stage = META_STAGE (actor);
-
- CLUTTER_STAGE_CLASS (meta_stage_parent_class)->deactivate (actor);
-
- stage->is_active = FALSE;
-}
-
-static void
-on_power_save_changed (MetaMonitorManager *monitor_manager,
- MetaStage *stage)
-{
- if (meta_monitor_manager_get_power_save_mode (monitor_manager) ==
- META_POWER_SAVE_ON)
- clutter_actor_queue_redraw (CLUTTER_ACTOR (stage));
-}
-
-static void
-meta_stage_class_init (MetaStageClass *klass)
-{
- ClutterStageClass *stage_class = (ClutterStageClass *) klass;
- ClutterActorClass *actor_class = (ClutterActorClass *) klass;
- GObjectClass *object_class = (GObjectClass *) klass;
-
- object_class->finalize = meta_stage_finalize;
-
- actor_class->paint = meta_stage_paint;
-
- stage_class->activate = meta_stage_activate;
- stage_class->deactivate = meta_stage_deactivate;
- stage_class->before_paint = meta_stage_before_paint;
- stage_class->paint_view = meta_stage_paint_view;
-
- signals[ACTORS_PAINTED] = g_signal_new ("actors-painted",
- G_TYPE_FROM_CLASS (klass),
- G_SIGNAL_RUN_LAST,
- 0,
- NULL, NULL, NULL,
- G_TYPE_NONE, 0);
-}
-
-static void
-meta_stage_init (MetaStage *stage)
-{
- int i;
-
- for (i = 0; i < N_WATCH_MODES; i++)
- stage->watchers[i] = g_ptr_array_new_with_free_func (g_free);
-}
-
-ClutterActor *
-meta_stage_new (MetaBackend *backend)
-{
- MetaStage *stage;
- MetaMonitorManager *monitor_manager;
-
- stage = g_object_new (META_TYPE_STAGE, NULL);
- stage->backend = backend;
-
- monitor_manager = meta_backend_get_monitor_manager (backend);
- g_signal_connect (monitor_manager, "power-save-mode-changed",
- G_CALLBACK (on_power_save_changed),
- stage);
-
- return CLUTTER_ACTOR (stage);
-}
-
-static void
-queue_redraw_clutter_rect (MetaStage *stage,
- MetaOverlay *overlay,
- graphene_rect_t *rect)
-{
- cairo_rectangle_int_t clip = {
- .x = floorf (rect->origin.x),
- .y = floorf (rect->origin.y),
- .width = ceilf (rect->size.width),
- .height = ceilf (rect->size.height)
- };
-
- /* Since we're flooring the coordinates, we need to enlarge the clip by the
- * difference between the actual coordinate and the floored value */
- clip.width += ceilf (rect->origin.x - clip.x) * 2;
- clip.height += ceilf (rect->origin.y - clip.y) * 2;
-
- clutter_actor_queue_redraw_with_clip (CLUTTER_ACTOR (stage), &clip);
-}
-
-static void
-queue_redraw_for_overlay (MetaStage *stage,
- MetaOverlay *overlay)
-{
- /* Clear the location the overlay was at before, if we need to. */
- if (overlay->previous_is_valid)
- {
- queue_redraw_clutter_rect (stage, overlay, &overlay->previous_rect);
- overlay->previous_is_valid = FALSE;
- }
-
- /* Draw the overlay at the new position */
- if (overlay->is_visible && overlay->texture)
- queue_redraw_clutter_rect (stage, overlay, &overlay->current_rect);
-}
-
-MetaOverlay *
-meta_stage_create_cursor_overlay (MetaStage *stage)
-{
- MetaOverlay *overlay;
-
- overlay = meta_overlay_new (stage);
- stage->overlays = g_list_prepend (stage->overlays, overlay);
-
- return overlay;
-}
-
-void
-meta_stage_remove_cursor_overlay (MetaStage *stage,
- MetaOverlay *overlay)
-{
- GList *link;
-
- link = g_list_find (stage->overlays, overlay);
- if (!link)
- return;
-
- stage->overlays = g_list_delete_link (stage->overlays, link);
- meta_overlay_free (overlay);
-}
-
-void
-meta_stage_update_cursor_overlay (MetaStage *stage,
- MetaOverlay *overlay,
- CoglTexture *texture,
- graphene_rect_t *rect)
-{
- meta_overlay_set (overlay, texture, rect);
- queue_redraw_for_overlay (stage, overlay);
-}
-
-void
-meta_overlay_set_visible (MetaOverlay *overlay,
- gboolean is_visible)
-{
- if (overlay->is_visible == is_visible)
- return;
-
- overlay->is_visible = is_visible;
- queue_redraw_for_overlay (overlay->stage, overlay);
-}
-
-gboolean
-meta_overlay_is_visible (MetaOverlay *overlay)
-{
- return overlay->is_visible;
-}
-
-void
-meta_stage_set_active (MetaStage *stage,
- gboolean is_active)
-{
- if (stage->is_active == is_active)
- return;
-
- if (is_active)
- g_signal_emit_by_name (CLUTTER_STAGE (stage), "activate");
- else
- g_signal_emit_by_name (CLUTTER_STAGE (stage), "deactivate");
-}
-
-MetaStageWatch *
-meta_stage_watch_view (MetaStage *stage,
- ClutterStageView *view,
- MetaStageWatchPhase watch_phase,
- MetaStageWatchFunc callback,
- gpointer user_data)
-{
- MetaStageWatch *watch;
- GPtrArray *watchers;
-
- watch = g_new0 (MetaStageWatch, 1);
- watch->view = view;
- watch->callback = callback;
- watch->user_data = user_data;
-
- watchers = stage->watchers[watch_phase];
- g_ptr_array_add (watchers, watch);
-
- return watch;
-}
-
-void
-meta_stage_remove_watch (MetaStage *stage,
- MetaStageWatch *watch)
-{
- GPtrArray *watchers;
- gboolean removed = FALSE;
- int i;
-
- for (i = 0; i < N_WATCH_MODES; i++)
- {
- watchers = stage->watchers[i];
- removed = g_ptr_array_remove_fast (watchers, watch);
-
- if (removed)
- break;
- }
-
- g_assert (removed);
-}
diff --git a/src/backends/meta-viewport-info.c b/src/backends/meta-viewport-info.c
deleted file mode 100644
index 1adef8759..000000000
--- a/src/backends/meta-viewport-info.c
+++ /dev/null
@@ -1,223 +0,0 @@
-/*
- * Copyright (C) 2020 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Written by:
- * Carlos Garnacho <carlosg@gnome.org>
- */
-
-#include "config.h"
-
-#include "backends/meta-viewport-info.h"
-#include "core/boxes-private.h"
-
-typedef struct _ViewInfo ViewInfo;
-
-struct _ViewInfo
-{
- MetaRectangle rect;
- float scale;
-};
-
-struct _MetaViewportInfo
-{
- GObject parent;
- GArray *views;
- gboolean is_views_scaled;
-};
-
-G_DEFINE_TYPE (MetaViewportInfo, meta_viewport_info, G_TYPE_OBJECT)
-
-static void
-meta_viewport_info_finalize (GObject *object)
-{
- MetaViewportInfo *info = META_VIEWPORT_INFO (object);
-
- g_array_unref (info->views);
-
- G_OBJECT_CLASS (meta_viewport_info_parent_class)->finalize (object);
-}
-
-static void
-meta_viewport_info_class_init (MetaViewportInfoClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- object_class->finalize = meta_viewport_info_finalize;
-}
-
-static void
-meta_viewport_info_init (MetaViewportInfo *info)
-{
- info->views = g_array_new (FALSE, FALSE, sizeof (ViewInfo));
-}
-
-MetaViewportInfo *
-meta_viewport_info_new (cairo_rectangle_int_t *views,
- float *scales,
- int n_views,
- gboolean is_views_scaled)
-{
- MetaViewportInfo *viewport_info;
- int i;
-
- viewport_info = g_object_new (META_TYPE_VIEWPORT_INFO, NULL);
-
- for (i = 0; i < n_views; i++)
- {
- ViewInfo info;
-
- info.rect = views[i];
- info.scale = scales[i];
- g_array_append_val (viewport_info->views, info);
- }
-
- viewport_info->is_views_scaled = is_views_scaled;
-
- return viewport_info;
-}
-
-int
-meta_viewport_info_get_view_at (MetaViewportInfo *viewport_info,
- float x,
- float y)
-{
- int i;
-
- for (i = 0; i < viewport_info->views->len; i++)
- {
- ViewInfo *info = &g_array_index (viewport_info->views, ViewInfo, i);
-
- if (META_POINT_IN_RECT (x, y, info->rect))
- return i;
- }
-
- return -1;
-}
-
-gboolean
-meta_viewport_info_get_view_info (MetaViewportInfo *viewport_info,
- int idx,
- cairo_rectangle_int_t *rect,
- float *scale)
-{
- ViewInfo *info;
-
- if (idx < 0 || idx >= viewport_info->views->len)
- return FALSE;
-
- info = &g_array_index (viewport_info->views, ViewInfo, idx);
- if (rect)
- *rect = info->rect;
- if (scale)
- *scale = info->scale;
-
- return TRUE;
-}
-
-static gboolean
-view_has_neighbor (cairo_rectangle_int_t *view,
- cairo_rectangle_int_t *neighbor,
- MetaDisplayDirection neighbor_direction)
-{
- switch (neighbor_direction)
- {
- case META_DISPLAY_RIGHT:
- if (neighbor->x == (view->x + view->width) &&
- meta_rectangle_vert_overlap (neighbor, view))
- return TRUE;
- break;
- case META_DISPLAY_LEFT:
- if (view->x == (neighbor->x + neighbor->width) &&
- meta_rectangle_vert_overlap (neighbor, view))
- return TRUE;
- break;
- case META_DISPLAY_UP:
- if (view->y == (neighbor->y + neighbor->height) &&
- meta_rectangle_horiz_overlap (neighbor, view))
- return TRUE;
- break;
- case META_DISPLAY_DOWN:
- if (neighbor->y == (view->y + view->height) &&
- meta_rectangle_horiz_overlap (neighbor, view))
- return TRUE;
- break;
- }
-
- return FALSE;
-}
-
-int
-meta_viewport_info_get_neighbor (MetaViewportInfo *viewport_info,
- int idx,
- MetaDisplayDirection direction)
-{
- cairo_rectangle_int_t rect;
- int i;
-
- if (!meta_viewport_info_get_view_info (viewport_info, idx, &rect, NULL))
- return -1;
-
- for (i = 0; i < viewport_info->views->len; i++)
- {
- ViewInfo *info = &g_array_index (viewport_info->views, ViewInfo, i);
-
- if (idx == i)
- continue;
- if (view_has_neighbor (&rect, &info->rect, direction))
- return i;
- }
-
- return -1;
-}
-
-int
-meta_viewport_info_get_num_views (MetaViewportInfo *info)
-{
- return info->views->len;
-}
-
-void
-meta_viewport_info_get_extents (MetaViewportInfo *viewport_info,
- float *width,
- float *height)
-{
- int min_x = G_MAXINT, min_y = G_MAXINT, max_x = G_MININT, max_y = G_MININT, i;
-
- g_return_if_fail (viewport_info != NULL);
-
- for (i = 0; i < viewport_info->views->len; i++)
- {
- ViewInfo *info = &g_array_index (viewport_info->views, ViewInfo, i);
-
- min_x = MIN (min_x, info->rect.x);
- max_x = MAX (max_x, info->rect.x + info->rect.width);
- min_y = MIN (min_y, info->rect.y);
- max_y = MAX (max_y, info->rect.y + info->rect.height);
- }
-
- if (width)
- *width = (float) max_x - min_x;
- if (height)
- *height = (float) max_y - min_y;
-}
-
-gboolean
-meta_viewport_info_is_views_scaled (MetaViewportInfo *viewport_info)
-{
- return viewport_info->is_views_scaled;
-}
diff --git a/src/backends/meta-viewport-info.h b/src/backends/meta-viewport-info.h
deleted file mode 100644
index e10f5b78f..000000000
--- a/src/backends/meta-viewport-info.h
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Copyright (C) 2020 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Written by:
- * Carlos Garnacho <carlosg@gnome.org>
- */
-
-#ifndef META_VIEWPORT_INFO_H
-#define META_VIEWPORT_INFO_H
-
-#include <cairo.h>
-#include <glib-object.h>
-
-#include "meta/display.h"
-
-#define META_TYPE_VIEWPORT_INFO (meta_viewport_info_get_type ())
-G_DECLARE_FINAL_TYPE (MetaViewportInfo, meta_viewport_info,
- META, VIEWPORT_INFO, GObject)
-
-MetaViewportInfo * meta_viewport_info_new (cairo_rectangle_int_t *views,
- float *scales,
- int n_views,
- gboolean is_views_scaled);
-
-int meta_viewport_info_get_view_at (MetaViewportInfo *info,
- float x,
- float y);
-
-gboolean meta_viewport_info_get_view_info (MetaViewportInfo *viewport_info,
- int idx,
- cairo_rectangle_int_t *rect,
- float *scale);
-
-int meta_viewport_info_get_neighbor (MetaViewportInfo *info,
- int idx,
- MetaDisplayDirection direction);
-
-int meta_viewport_info_get_num_views (MetaViewportInfo *info);
-
-void meta_viewport_info_get_extents (MetaViewportInfo *info,
- float *width,
- float *height);
-
-gboolean meta_viewport_info_is_views_scaled (MetaViewportInfo *info);
-
-#endif /* META_VIEWPORT_INFO_H */
diff --git a/src/backends/meta-virtual-monitor.c b/src/backends/meta-virtual-monitor.c
deleted file mode 100644
index 2bd95ffd7..000000000
--- a/src/backends/meta-virtual-monitor.c
+++ /dev/null
@@ -1,238 +0,0 @@
-/*
- * Copyright (C) 2021 Red Hat Inc.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- */
-
-#include "config.h"
-
-#include "backends/meta-virtual-monitor.h"
-
-#include "backends/meta-crtc.h"
-#include "backends/meta-crtc-mode.h"
-#include "backends/meta-output.h"
-
-enum
-{
- DESTROY,
-
- N_SIGNALS
-};
-
-static guint signals[N_SIGNALS] = { 0 };
-
-enum
-{
- PROP_0,
-
- PROP_CRTC,
- PROP_CRTC_MODE,
- PROP_OUTPUT,
-
- N_PROPS
-};
-
-static GParamSpec *obj_props[N_PROPS];
-
-typedef struct _MetaVirtualMonitorPrivate
-{
- MetaCrtc *crtc;
- MetaCrtcMode *crtc_mode;
- MetaOutput *output;
-
- gboolean is_destroyed;
-} MetaVirtualMonitorPrivate;
-
-G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (MetaVirtualMonitor, meta_virtual_monitor,
- G_TYPE_OBJECT)
-
-MetaVirtualMonitorInfo *
-meta_virtual_monitor_info_new (int width,
- int height,
- float refresh_rate,
- const char *vendor,
- const char *product,
- const char *serial)
-{
- MetaVirtualMonitorInfo *info;
-
- info = g_new0 (MetaVirtualMonitorInfo, 1);
- info->width = width;
- info->height = height;
- info->refresh_rate = refresh_rate;
- info->vendor = g_strdup (vendor);
- info->product = g_strdup (product);
- info->serial = g_strdup (serial);
-
- return info;
-}
-
-void
-meta_virtual_monitor_info_free (MetaVirtualMonitorInfo *info)
-{
- g_free (info->vendor);
- g_free (info->product);
- g_free (info->serial);
- g_free (info);
-}
-
-MetaCrtc *
-meta_virtual_monitor_get_crtc (MetaVirtualMonitor *virtual_monitor)
-{
- MetaVirtualMonitorPrivate *priv =
- meta_virtual_monitor_get_instance_private (virtual_monitor);
-
- return priv->crtc;
-}
-
-MetaCrtcMode *
-meta_virtual_monitor_get_crtc_mode (MetaVirtualMonitor *virtual_monitor)
-{
- MetaVirtualMonitorPrivate *priv =
- meta_virtual_monitor_get_instance_private (virtual_monitor);
-
- return priv->crtc_mode;
-}
-
-MetaOutput *
-meta_virtual_monitor_get_output (MetaVirtualMonitor *virtual_monitor)
-{
- MetaVirtualMonitorPrivate *priv =
- meta_virtual_monitor_get_instance_private (virtual_monitor);
-
- return priv->output;
-}
-
-static void
-meta_virtual_monitor_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- MetaVirtualMonitor *virtual_monitor = META_VIRTUAL_MONITOR (object);
- MetaVirtualMonitorPrivate *priv =
- meta_virtual_monitor_get_instance_private (virtual_monitor);
-
- switch (prop_id)
- {
- case PROP_CRTC:
- priv->crtc = g_value_get_object (value);
- break;
- case PROP_CRTC_MODE:
- priv->crtc_mode = g_value_get_object (value);
- break;
- case PROP_OUTPUT:
- priv->output = g_value_get_object (value);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- }
-}
-
-static void
-meta_virtual_monitor_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- MetaVirtualMonitor *virtual_monitor = META_VIRTUAL_MONITOR (object);
- MetaVirtualMonitorPrivate *priv =
- meta_virtual_monitor_get_instance_private (virtual_monitor);
-
- switch (prop_id)
- {
- case PROP_CRTC:
- g_value_set_object (value, priv->crtc);
- break;
- case PROP_CRTC_MODE:
- g_value_set_object (value, priv->crtc_mode);
- break;
- case PROP_OUTPUT:
- g_value_set_object (value, priv->output);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- }
-}
-
-static void
-meta_virtual_monitor_dispose (GObject *object)
-{
- MetaVirtualMonitor *virtual_monitor = META_VIRTUAL_MONITOR (object);
- MetaVirtualMonitorPrivate *priv =
- meta_virtual_monitor_get_instance_private (virtual_monitor);
-
- if (!priv->is_destroyed)
- {
- g_signal_emit (virtual_monitor, signals[DESTROY], 0);
- priv->is_destroyed = TRUE;
- }
-
- g_clear_object (&priv->crtc);
- g_clear_object (&priv->crtc_mode);
- g_clear_object (&priv->output);
-
- G_OBJECT_CLASS (meta_virtual_monitor_parent_class)->dispose (object);
-}
-
-static void
-meta_virtual_monitor_init (MetaVirtualMonitor *virtual_monitor)
-{
-}
-
-static void
-meta_virtual_monitor_class_init (MetaVirtualMonitorClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- object_class->set_property = meta_virtual_monitor_set_property;
- object_class->get_property = meta_virtual_monitor_get_property;
- object_class->dispose = meta_virtual_monitor_dispose;
-
- obj_props[PROP_CRTC] =
- g_param_spec_object ("crtc",
- "crtc",
- "The virtual CRTC",
- META_TYPE_CRTC,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT_ONLY |
- G_PARAM_STATIC_STRINGS);
- obj_props[PROP_CRTC_MODE] =
- g_param_spec_object ("crtc-mode",
- "crtc-mode",
- "The virtual CRTC mode",
- META_TYPE_CRTC_MODE,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT_ONLY |
- G_PARAM_STATIC_STRINGS);
- obj_props[PROP_OUTPUT] =
- g_param_spec_object ("output",
- "output",
- "The virtual output",
- META_TYPE_OUTPUT,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT_ONLY |
- G_PARAM_STATIC_STRINGS);
- g_object_class_install_properties (object_class, N_PROPS, obj_props);
-
- signals[DESTROY] =
- g_signal_new ("destroy",
- G_TYPE_FROM_CLASS (klass),
- G_SIGNAL_RUN_LAST, 0,
- NULL, NULL, NULL,
- G_TYPE_NONE, 0);
-}
diff --git a/src/backends/meta-virtual-monitor.h b/src/backends/meta-virtual-monitor.h
deleted file mode 100644
index 2b733df9c..000000000
--- a/src/backends/meta-virtual-monitor.h
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Copyright (C) 2021 Red Hat Inc.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- */
-
-#ifndef META_VIRTUAL_MONITOR_H
-#define META_VIRTUAL_MONITOR_H
-
-#include <glib-object.h>
-
-#include "backends/meta-backend-types.h"
-#include "core/util-private.h"
-
-typedef struct _MetaVirtualMonitorInfo
-{
- int width;
- int height;
- float refresh_rate;
-
- char *vendor;
- char *product;
- char *serial;
-} MetaVirtualMonitorInfo;
-
-#define META_TYPE_VIRTUAL_MONITOR (meta_virtual_monitor_get_type ())
-G_DECLARE_DERIVABLE_TYPE (MetaVirtualMonitor, meta_virtual_monitor,
- META, VIRTUAL_MONITOR,
- GObject)
-
-struct _MetaVirtualMonitorClass
-{
- GObjectClass parent_class;
-};
-
-META_EXPORT_TEST
-MetaVirtualMonitorInfo * meta_virtual_monitor_info_new (int width,
- int height,
- float refresh_rate,
- const char *vendor,
- const char *product,
- const char *serial);
-
-META_EXPORT_TEST
-void meta_virtual_monitor_info_free (MetaVirtualMonitorInfo *info);
-
-MetaCrtc * meta_virtual_monitor_get_crtc (MetaVirtualMonitor *virtual_monitor);
-
-MetaCrtcMode * meta_virtual_monitor_get_crtc_mode (MetaVirtualMonitor *virtual_monitor);
-
-META_EXPORT_TEST
-MetaOutput * meta_virtual_monitor_get_output (MetaVirtualMonitor *virtual_monitor);
-
-G_DEFINE_AUTOPTR_CLEANUP_FUNC (MetaVirtualMonitorInfo,
- meta_virtual_monitor_info_free)
-
-#endif /* META_VIRTUAL_MONITOR_H */
diff --git a/src/backends/native/dbus-utils.c b/src/backends/native/dbus-utils.c
deleted file mode 100644
index 79fafe881..000000000
--- a/src/backends/native/dbus-utils.c
+++ /dev/null
@@ -1,107 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2014 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Written by:
- * Jasper St. Pierre <jstpierre@mecheye.net>
- */
-
-#include "config.h"
-
-#include "backends/native/dbus-utils.h"
-
-#include <glib.h>
-
-/* Stolen from tp_escape_as_identifier, from tp-glib,
- * which follows the same escaping convention as systemd.
- */
-static inline gboolean
-_esc_ident_bad (gchar c, gboolean is_first)
-{
- return ((c < 'a' || c > 'z') &&
- (c < 'A' || c > 'Z') &&
- (c < '0' || c > '9' || is_first));
-}
-
-static gchar *
-escape_dbus_component (const gchar *name)
-{
- gboolean bad = FALSE;
- size_t len = 0;
- GString *op;
- const gchar *ptr, *first_ok;
-
- g_return_val_if_fail (name != NULL, NULL);
-
- /* fast path for empty name */
- if (name[0] == '\0')
- return g_strdup ("_");
-
- for (ptr = name; *ptr; ptr++)
- {
- if (_esc_ident_bad (*ptr, ptr == name))
- {
- bad = TRUE;
- len += 3;
- }
- else
- len++;
- }
-
- /* fast path if it's clean */
- if (!bad)
- return g_strdup (name);
-
- /* If strictly less than ptr, first_ok is the first uncopied safe character.
- */
- first_ok = name;
- op = g_string_sized_new (len);
- for (ptr = name; *ptr; ptr++)
- {
- if (_esc_ident_bad (*ptr, ptr == name))
- {
- /* copy preceding safe characters if any */
- if (first_ok < ptr)
- {
- g_string_append_len (op, first_ok, ptr - first_ok);
- }
- /* escape the unsafe character */
- g_string_append_printf (op, "_%02x", (unsigned char)(*ptr));
- /* restart after it */
- first_ok = ptr + 1;
- }
- }
- /* copy trailing safe characters if any */
- if (first_ok < ptr)
- {
- g_string_append_len (op, first_ok, ptr - first_ok);
- }
- return g_string_free (op, FALSE);
-}
-
-char *
-get_escaped_dbus_path (const char *prefix,
- const char *component)
-{
- char *escaped_component = escape_dbus_component (component);
- char *path = g_strconcat (prefix, "/", escaped_component, NULL);
-
- g_free (escaped_component);
- return path;
-}
diff --git a/src/backends/native/dbus-utils.h b/src/backends/native/dbus-utils.h
deleted file mode 100644
index ee56c455a..000000000
--- a/src/backends/native/dbus-utils.h
+++ /dev/null
@@ -1,32 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2014 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Written by:
- * Jasper St. Pierre <jstpierre@mecheye.net>
- */
-
-#ifndef DBUS_UTILS_H
-#define DBUS_UTILS_H
-
-char *
-get_escaped_dbus_path (const char *prefix,
- const char *component);
-
-#endif /* DBUS_UTILS_H */
diff --git a/src/backends/native/gen-default-modes.py b/src/backends/native/gen-default-modes.py
deleted file mode 100755
index fed514d45..000000000
--- a/src/backends/native/gen-default-modes.py
+++ /dev/null
@@ -1,127 +0,0 @@
-#!/usr/bin/env python3
-
-# Copyright (C) 2016 Red Hat Inc.
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License as
-# published by the Free Software Foundation; either version 2 of the
-# License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
-# 02111-1307, USA.
-
-import os
-import sys
-
-if len(sys.argv) != 2:
- print("Usage: %s [output file]"%sys.argv[0])
- exit(1)
-
-common_resolutions = [
- # 4:3
- (800, 600),
- (1024, 768),
- (1152, 864),
- (1280, 960),
- (1400, 1050),
- (1440, 1080),
- (1600, 1200),
- (1920, 1440),
- (2048, 1536),
- # 16:10
- (1280, 800),
- (1440, 900),
- (1680, 1050),
- (1920, 1200),
- (2560, 1600),
- # 16:9
- (1280, 720),
- (1366, 768),
- (1600, 900),
- (1920, 1080),
- (2048, 1152),
- (2560, 1440),
- (2880, 1620),
- (3200, 1800),
- (3840, 2160),
- (4096, 2304),
- (5120, 2880),
-]
-
-output_lines = [
- "/* Generated by gen-default-modes.py */\n",
- "static const drmModeModeInfo meta_default_landscape_drm_mode_infos[] = {",
-]
-
-def sync_flags(hsync, vsync):
- flags = "DRM_MODE_FLAG_"
- flags += "NHSYNC" if hsync[0] == '-' else "PHSYNC"
- flags += " | DRM_MODE_FLAG_"
- flags += "NVSYNC" if vsync[0] == '-' else "PVSYNC"
- return flags
-
-def drm_mode_info_from_modeline(line):
- sline = line.split()
- return "{ %d, %d, %d, %d, %d, 0, %d, %d, %d, %d, 0, 0, %s, DRM_MODE_TYPE_DEFAULT, %s }," % \
- (int(float(sline[2]) * 1000),
- int(sline[3]),
- int(sline[4]),
- int(sline[5]),
- int(sline[6]),
- int(sline[7]),
- int(sline[8]),
- int(sline[9]),
- int(sline[10]),
- sync_flags(sline[11], sline[12]),
- sline[1])
-
-def portrait_drm_mode_info_from_modeline(line):
- sline = line.split()
- return "{ %d, %d, %d, %d, %d, 0, %d, %d, %d, %d, 0, 0, %s, DRM_MODE_TYPE_DEFAULT, \"%dx%d_60.00\" }," % \
- (int(float(sline[2]) * 1000),
- int(sline[7]),
- int(sline[8]),
- int(sline[9]),
- int(sline[10]),
- int(sline[3]),
- int(sline[4]),
- int(sline[5]),
- int(sline[6]),
- sync_flags(sline[12], sline[11]),
- int(sline[7]), int(sline[3]))
-
-for resolution in common_resolutions:
- cvt = os.popen("%s %s %s" % ('cvt', resolution[0], resolution[1]))
- cvt.readline() # discard comment line
- line = cvt.readline()
- output_lines.append(drm_mode_info_from_modeline(line))
- cvt.close()
-output_lines.append("};")
-
-output_lines.append("")
-output_lines.append("static const drmModeModeInfo meta_default_portrait_drm_mode_infos[] = {")
-for resolution in common_resolutions:
- cvt = os.popen("%s %s %s" % ('cvt', resolution[0], resolution[1]))
- cvt.readline() # discard comment line
- line = cvt.readline()
- output_lines.append(portrait_drm_mode_info_from_modeline(line))
- cvt.close()
-output_lines.append("};")
-
-try:
- output_file = open(sys.argv[1], 'w')
-
- for line in output_lines:
- output_file.write(line + "\n")
- output_file.flush()
- output_file.close()
-except:
- print("Failed to generate modelines:", sys.exc_info()[0])
- exit(1)
diff --git a/src/backends/native/meta-backend-native-private.h b/src/backends/native/meta-backend-native-private.h
deleted file mode 100644
index cd184685f..000000000
--- a/src/backends/native/meta-backend-native-private.h
+++ /dev/null
@@ -1,35 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2015 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Written by:
- * Jonas Ådahl <jadahl@gmail.com>
- */
-
-#ifndef META_BACKEND_NATIVE_PRIVATE_H
-#define META_BACKEND_NATIVE_PRIVATE_H
-
-#include "backends/native/meta-backend-native.h"
-#include "backends/native/meta-barrier-native.h"
-
-MetaBarrierManagerNative *meta_backend_native_get_barrier_manager (MetaBackendNative *native);
-
-MetaDevicePool * meta_backend_native_get_device_pool (MetaBackendNative *native);
-
-#endif /* META_BACKEND_NATIVE_PRIVATE_H */
diff --git a/src/backends/native/meta-backend-native-types.h b/src/backends/native/meta-backend-native-types.h
deleted file mode 100644
index 152b57cf6..000000000
--- a/src/backends/native/meta-backend-native-types.h
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright (C) 2019 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- */
-
-#ifndef META_BACKEND_NATIVE_TYPES_H
-#define META_BACKEND_NATIVE_TYPES_H
-
-typedef struct _MetaBackendNative MetaBackendNative;
-typedef struct _MetaSeatNative MetaSeatNative;
-typedef struct _MetaSeatImpl MetaSeatImpl;
-typedef struct _MetaKeymapNative MetaKeymapNative;
-typedef struct _MetaRendererNative MetaRendererNative;
-typedef struct _MetaGpuKms MetaGpuKms;
-typedef struct _MetaCrtcVirtual MetaCrtcVirtual;
-typedef struct _MetaCrtcModeVirtual MetaCrtcModeVirtual;
-typedef struct _MetaDevicePool MetaDevicePool;
-typedef struct _MetaDeviceFile MetaDeviceFile;
-
-typedef enum _MetaSeatNativeFlag
-{
- META_SEAT_NATIVE_FLAG_NONE = 0,
- META_SEAT_NATIVE_FLAG_NO_LIBINPUT = 1 << 0,
-} MetaSeatNativeFlag;
-
-#endif /* META_BACKEND_NATIVE_TYPES_H */
diff --git a/src/backends/native/meta-backend-native.c b/src/backends/native/meta-backend-native.c
deleted file mode 100644
index 81d9629d0..000000000
--- a/src/backends/native/meta-backend-native.c
+++ /dev/null
@@ -1,768 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2014 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Written by:
- * Jasper St. Pierre <jstpierre@mecheye.net>
- */
-
-/**
- * SECTION:meta-backend-native
- * @title: MetaBackendNative
- * @short_description: A native (KMS/evdev) MetaBackend
- *
- * MetaBackendNative is an implementation of #MetaBackend that uses "native"
- * technologies like DRM/KMS and libinput/evdev to perform the necessary
- * functions.
- */
-
-#include "config.h"
-
-#include "backends/native/meta-backend-native.h"
-#include "backends/native/meta-backend-native-private.h"
-#include "backends/native/meta-input-thread.h"
-
-#include <sched.h>
-#include <stdlib.h>
-
-#include "backends/meta-cursor-tracker-private.h"
-#include "backends/meta-idle-manager.h"
-#include "backends/meta-keymap-utils.h"
-#include "backends/meta-logical-monitor.h"
-#include "backends/meta-monitor-manager-private.h"
-#include "backends/meta-pointer-constraint.h"
-#include "backends/meta-settings-private.h"
-#include "backends/meta-stage-private.h"
-#include "backends/native/meta-clutter-backend-native.h"
-#include "backends/native/meta-device-pool-private.h"
-#include "backends/native/meta-kms.h"
-#include "backends/native/meta-kms-device.h"
-#include "backends/native/meta-launcher.h"
-#include "backends/native/meta-monitor-manager-native.h"
-#include "backends/native/meta-renderer-native.h"
-#include "backends/native/meta-seat-native.h"
-#include "backends/native/meta-stage-native.h"
-#include "cogl/cogl.h"
-#include "core/meta-border.h"
-#include "meta/main.h"
-
-#ifdef HAVE_REMOTE_DESKTOP
-#include "backends/meta-screen-cast.h"
-#endif
-
-enum
-{
- PROP_0,
-
- PROP_HEADLESS,
-
- N_PROPS
-};
-
-static GParamSpec *obj_props[N_PROPS];
-
-struct _MetaBackendNative
-{
- MetaBackend parent;
-
- MetaLauncher *launcher;
- MetaDevicePool *device_pool;
- MetaUdev *udev;
- MetaKms *kms;
-
- gboolean is_headless;
-
- gulong udev_device_added_handler_id;
-};
-
-static GInitableIface *initable_parent_iface;
-
-static void
-initable_iface_init (GInitableIface *initable_iface);
-
-G_DEFINE_TYPE_WITH_CODE (MetaBackendNative, meta_backend_native, META_TYPE_BACKEND,
- G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE,
- initable_iface_init))
-
-static void
-disconnect_udev_device_added_handler (MetaBackendNative *native);
-
-static void
-meta_backend_native_dispose (GObject *object)
-{
- MetaBackendNative *native = META_BACKEND_NATIVE (object);
-
- if (native->udev_device_added_handler_id)
- {
- disconnect_udev_device_added_handler (native);
- native->udev_device_added_handler_id = 0;
- }
-
- if (native->kms)
- meta_kms_prepare_shutdown (native->kms);
-
- G_OBJECT_CLASS (meta_backend_native_parent_class)->dispose (object);
-
- g_clear_object (&native->kms);
- g_clear_object (&native->udev);
- g_clear_object (&native->device_pool);
- g_clear_pointer (&native->launcher, meta_launcher_free);
-}
-
-static ClutterBackend *
-meta_backend_native_create_clutter_backend (MetaBackend *backend)
-{
- return g_object_new (META_TYPE_CLUTTER_BACKEND_NATIVE, NULL);
-}
-
-static ClutterSeat *
-meta_backend_native_create_default_seat (MetaBackend *backend,
- GError **error)
-{
- MetaBackendNative *backend_native = META_BACKEND_NATIVE (backend);
- const char *seat_id;
- MetaSeatNativeFlag flags;
-
- seat_id = meta_backend_native_get_seat_id (backend_native);
-
- if (meta_backend_native_is_headless (backend_native))
- flags = META_SEAT_NATIVE_FLAG_NO_LIBINPUT;
- else
- flags = META_SEAT_NATIVE_FLAG_NONE;
-
- return CLUTTER_SEAT (g_object_new (META_TYPE_SEAT_NATIVE,
- "backend", backend,
- "seat-id", seat_id,
- "flags", flags,
- NULL));
-}
-
-#ifdef HAVE_REMOTE_DESKTOP
-static void
-maybe_disable_screen_cast_dma_bufs (MetaBackendNative *native)
-{
- MetaBackend *backend = META_BACKEND (native);
- MetaSettings *settings = meta_backend_get_settings (backend);
- MetaRenderer *renderer = meta_backend_get_renderer (backend);
- MetaRendererNative *renderer_native = META_RENDERER_NATIVE (renderer);
- MetaScreenCast *screen_cast = meta_backend_get_screen_cast (backend);
- MetaGpuKms *primary_gpu;
- MetaKmsDevice *kms_device;
- const char *driver_name;
- static const char *enable_dma_buf_drivers[] = {
- "i915",
- NULL,
- };
-
- primary_gpu = meta_renderer_native_get_primary_gpu (renderer_native);
- if (!primary_gpu)
- {
- g_message ("Disabling DMA buffer screen sharing (surfaceless)");
- goto disable_dma_bufs;
- }
-
- kms_device = meta_gpu_kms_get_kms_device (primary_gpu);
- driver_name = meta_kms_device_get_driver_name (kms_device);
-
- if (g_strv_contains (enable_dma_buf_drivers, driver_name))
- return;
-
- if (meta_settings_is_experimental_feature_enabled (settings,
- META_EXPERIMENTAL_FEATURE_DMA_BUF_SCREEN_SHARING))
- return;
-
- g_message ("Disabling DMA buffer screen sharing for driver '%s'.",
- driver_name);
-
-disable_dma_bufs:
- meta_screen_cast_disable_dma_bufs (screen_cast);
-}
-#endif /* HAVE_REMOTE_DESKTOP */
-
-static void
-update_viewports (MetaBackend *backend)
-{
- MetaMonitorManager *monitor_manager =
- meta_backend_get_monitor_manager (backend);
- ClutterBackend *clutter_backend = meta_backend_get_clutter_backend (backend);
- MetaSeatNative *seat =
- META_SEAT_NATIVE (clutter_backend_get_default_seat (clutter_backend));
- MetaViewportInfo *viewports;
-
- viewports = meta_monitor_manager_get_viewports (monitor_manager);
- meta_seat_native_set_viewports (seat, viewports);
- g_object_unref (viewports);
-}
-
-static void
-meta_backend_native_post_init (MetaBackend *backend)
-{
- MetaSettings *settings = meta_backend_get_settings (backend);
-
- META_BACKEND_CLASS (meta_backend_native_parent_class)->post_init (backend);
-
- if (meta_settings_is_experimental_feature_enabled (settings,
- META_EXPERIMENTAL_FEATURE_RT_SCHEDULER))
- {
- int retval;
- struct sched_param sp = {
- .sched_priority = sched_get_priority_min (SCHED_RR)
- };
-
- retval = sched_setscheduler (0, SCHED_RR | SCHED_RESET_ON_FORK, &sp);
-
- if (retval != 0)
- g_warning ("Failed to set RT scheduler: %m");
- }
-
-#ifdef HAVE_REMOTE_DESKTOP
- maybe_disable_screen_cast_dma_bufs (META_BACKEND_NATIVE (backend));
-#endif
-
- update_viewports (backend);
-}
-
-static MetaMonitorManager *
-meta_backend_native_create_monitor_manager (MetaBackend *backend,
- GError **error)
-{
- MetaBackendNative *backend_native = META_BACKEND_NATIVE (backend);
- MetaMonitorManager *manager;
-
- manager = g_initable_new (META_TYPE_MONITOR_MANAGER_NATIVE, NULL, error,
- "backend", backend,
- "needs-outputs", !backend_native->is_headless,
- NULL);
- if (!manager)
- return NULL;
-
- g_signal_connect_swapped (manager, "monitors-changed-internal",
- G_CALLBACK (update_viewports), backend);
-
- return manager;
-}
-
-static MetaCursorRenderer *
-meta_backend_native_get_cursor_renderer (MetaBackend *backend,
- ClutterInputDevice *device)
-{
- ClutterBackend *clutter_backend = meta_backend_get_clutter_backend (backend);
- MetaSeatNative *seat_native =
- META_SEAT_NATIVE (clutter_backend_get_default_seat (clutter_backend));
-
- return meta_seat_native_maybe_ensure_cursor_renderer (seat_native, device);
-}
-
-static MetaRenderer *
-meta_backend_native_create_renderer (MetaBackend *backend,
- GError **error)
-{
- MetaBackendNative *native = META_BACKEND_NATIVE (backend);
- MetaRendererNative *renderer_native;
-
- renderer_native = meta_renderer_native_new (native, error);
- if (!renderer_native)
- return NULL;
-
- return META_RENDERER (renderer_native);
-}
-
-static MetaInputSettings *
-meta_backend_native_get_input_settings (MetaBackend *backend)
-{
- ClutterBackend *clutter_backend = meta_backend_get_clutter_backend (backend);
- MetaSeatNative *seat_native =
- META_SEAT_NATIVE (clutter_backend_get_default_seat (clutter_backend));
-
- return meta_seat_impl_get_input_settings (seat_native->impl);
-}
-
-static MetaLogicalMonitor *
-meta_backend_native_get_current_logical_monitor (MetaBackend *backend)
-{
- MetaCursorTracker *cursor_tracker = meta_backend_get_cursor_tracker (backend);
- MetaMonitorManager *monitor_manager =
- meta_backend_get_monitor_manager (backend);
- graphene_point_t point;
-
- meta_cursor_tracker_get_pointer (cursor_tracker, &point, NULL);
- return meta_monitor_manager_get_logical_monitor_at (monitor_manager,
- point.x, point.y);
-}
-
-static void
-meta_backend_native_set_keymap (MetaBackend *backend,
- const char *layouts,
- const char *variants,
- const char *options)
-{
- ClutterBackend *clutter_backend = meta_backend_get_clutter_backend (backend);
- ClutterSeat *seat;
-
- seat = clutter_backend_get_default_seat (clutter_backend);
- meta_seat_native_set_keyboard_map (META_SEAT_NATIVE (seat),
- layouts, variants, options);
-
- meta_backend_notify_keymap_changed (backend);
-}
-
-static struct xkb_keymap *
-meta_backend_native_get_keymap (MetaBackend *backend)
-{
- ClutterBackend *clutter_backend = meta_backend_get_clutter_backend (backend);
- ClutterSeat *seat;
-
- seat = clutter_backend_get_default_seat (clutter_backend);
- return meta_seat_native_get_keyboard_map (META_SEAT_NATIVE (seat));
-}
-
-static xkb_layout_index_t
-meta_backend_native_get_keymap_layout_group (MetaBackend *backend)
-{
- ClutterBackend *clutter_backend = meta_backend_get_clutter_backend (backend);
- ClutterSeat *seat;
-
- seat = clutter_backend_get_default_seat (clutter_backend);
- return meta_seat_native_get_keyboard_layout_index (META_SEAT_NATIVE (seat));
-}
-
-static void
-meta_backend_native_lock_layout_group (MetaBackend *backend,
- guint idx)
-{
- ClutterBackend *clutter_backend = meta_backend_get_clutter_backend (backend);
- xkb_layout_index_t old_idx;
- ClutterSeat *seat;
-
- old_idx = meta_backend_native_get_keymap_layout_group (backend);
- if (old_idx == idx)
- return;
-
- seat = clutter_backend_get_default_seat (clutter_backend);
- meta_seat_native_set_keyboard_layout_index (META_SEAT_NATIVE (seat), idx);
- meta_backend_notify_keymap_layout_group_changed (backend, idx);
-}
-
-const char *
-meta_backend_native_get_seat_id (MetaBackendNative *backend_native)
-{
- if (backend_native->is_headless)
- return "seat0";
- else
- return meta_launcher_get_seat_id (backend_native->launcher);
-}
-
-gboolean
-meta_backend_native_is_headless (MetaBackendNative *backend_native)
-{
- return backend_native->is_headless;
-}
-
-static void
-meta_backend_native_set_pointer_constraint (MetaBackend *backend,
- MetaPointerConstraint *constraint)
-{
- ClutterBackend *clutter_backend = meta_backend_get_clutter_backend (backend);
- ClutterSeat *seat = clutter_backend_get_default_seat (clutter_backend);
- MetaPointerConstraintImpl *constraint_impl = NULL;
- cairo_region_t *region;
-
- if (constraint)
- {
- region = meta_pointer_constraint_get_region (constraint);
- constraint_impl = meta_pointer_constraint_impl_native_new (constraint,
- region);
- }
-
- meta_seat_native_set_pointer_constraint (META_SEAT_NATIVE (seat),
- constraint_impl);
-}
-
-static void
-meta_backend_native_update_screen_size (MetaBackend *backend,
- int width, int height)
-{
- ClutterActor *stage = meta_backend_get_stage (backend);
- ClutterStageWindow *stage_window =
- _clutter_stage_get_window (CLUTTER_STAGE (stage));
- MetaStageNative *stage_native = META_STAGE_NATIVE (stage_window);
-
- meta_stage_native_rebuild_views (stage_native);
-
- clutter_actor_set_size (stage, width, height);
-}
-
-static MetaGpuKms *
-create_gpu_from_udev_device (MetaBackendNative *native,
- GUdevDevice *device,
- GError **error)
-{
- MetaKmsDeviceFlag flags = META_KMS_DEVICE_FLAG_NONE;
- const char *device_path;
- MetaKmsDevice *kms_device;
-
- if (meta_is_udev_device_platform_device (device))
- flags |= META_KMS_DEVICE_FLAG_PLATFORM_DEVICE;
-
- if (meta_is_udev_device_boot_vga (device))
- flags |= META_KMS_DEVICE_FLAG_BOOT_VGA;
-
- if (meta_is_udev_device_disable_modifiers (device))
- flags |= META_KMS_DEVICE_FLAG_DISABLE_MODIFIERS;
-
- if (meta_is_udev_device_preferred_primary (device))
- flags |= META_KMS_DEVICE_FLAG_PREFERRED_PRIMARY;
-
- device_path = g_udev_device_get_device_file (device);
-
- kms_device = meta_kms_create_device (native->kms, device_path, flags,
- error);
- if (!kms_device)
- return NULL;
-
- return meta_gpu_kms_new (native, kms_device, error);
-}
-
-static void
-on_udev_device_added (MetaUdev *udev,
- GUdevDevice *device,
- MetaBackendNative *native)
-{
- MetaBackend *backend = META_BACKEND (native);
- g_autoptr (GError) error = NULL;
- const char *device_path;
- MetaGpuKms *new_gpu_kms;
- GList *gpus, *l;
-
- if (!meta_udev_is_drm_device (udev, device))
- return;
-
- device_path = g_udev_device_get_device_file (device);
-
- gpus = meta_backend_get_gpus (backend);
- for (l = gpus; l; l = l->next)
- {
- MetaGpuKms *gpu_kms = l->data;
-
- if (!g_strcmp0 (device_path, meta_gpu_kms_get_file_path (gpu_kms)))
- {
- g_warning ("Failed to hotplug secondary gpu '%s': %s",
- device_path, "device already present");
- return;
- }
- }
-
- if (meta_is_udev_device_ignore (device))
- {
- g_message ("Ignoring DRM device '%s' (from udev rule)", device_path);
- return;
- }
-
- new_gpu_kms = create_gpu_from_udev_device (native, device, &error);
- if (!new_gpu_kms)
- {
- g_warning ("Failed to hotplug secondary gpu '%s': %s",
- device_path, error->message);
- return;
- }
-
- meta_backend_add_gpu (backend, META_GPU (new_gpu_kms));
-}
-
-static void
-connect_udev_device_added_handler (MetaBackendNative *native)
-{
- native->udev_device_added_handler_id =
- g_signal_connect (native->udev, "device-added",
- G_CALLBACK (on_udev_device_added), native);
-}
-
-static void
-disconnect_udev_device_added_handler (MetaBackendNative *native)
-{
- g_clear_signal_handler (&native->udev_device_added_handler_id, native->udev);
-}
-
-static gboolean
-init_gpus (MetaBackendNative *native,
- GError **error)
-{
- MetaBackend *backend = META_BACKEND (native);
- MetaUdev *udev = meta_backend_native_get_udev (native);
- GList *devices;
- GList *l;
-
- devices = meta_udev_list_drm_devices (udev, error);
- if (*error)
- return FALSE;
-
- for (l = devices; l; l = l->next)
- {
- GUdevDevice *device = l->data;
- MetaGpuKms *gpu_kms;
- GError *local_error = NULL;
-
- if (meta_is_udev_device_ignore (device))
- {
- g_message ("Ignoring DRM device '%s' (from udev rule)",
- g_udev_device_get_device_file (device));
- continue;
- }
-
- gpu_kms = create_gpu_from_udev_device (native, device, &local_error);
-
- if (!gpu_kms)
- {
- g_warning ("Failed to open gpu '%s': %s",
- g_udev_device_get_device_file (device),
- local_error->message);
- g_clear_error (&local_error);
- continue;
- }
-
- meta_backend_add_gpu (backend, META_GPU (gpu_kms));
- }
-
- g_list_free_full (devices, g_object_unref);
-
- if (!native->is_headless &&
- g_list_length (meta_backend_get_gpus (backend)) == 0)
- {
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND,
- "No GPUs found");
- return FALSE;
- }
-
- connect_udev_device_added_handler (native);
-
- return TRUE;
-}
-
-static gboolean
-meta_backend_native_initable_init (GInitable *initable,
- GCancellable *cancellable,
- GError **error)
-{
- MetaBackendNative *native = META_BACKEND_NATIVE (initable);
- MetaKmsFlags kms_flags;
-
- if (!meta_is_stage_views_enabled ())
- {
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- "The native backend requires stage views");
- return FALSE;
- }
-
- if (!native->is_headless)
- {
- native->launcher = meta_launcher_new (error);
- if (!native->launcher)
- return FALSE;
- }
-
- native->device_pool = meta_device_pool_new (native->launcher);
- native->udev = meta_udev_new (native);
-
- kms_flags = META_KMS_FLAG_NONE;
- if (native->is_headless)
- kms_flags |= META_KMS_FLAG_NO_MODE_SETTING;
-
- native->kms = meta_kms_new (META_BACKEND (native), kms_flags, error);
- if (!native->kms)
- return FALSE;
-
- if (!init_gpus (native, error))
- return FALSE;
-
- return initable_parent_iface->init (initable, cancellable, error);
-}
-
-static void
-meta_backend_native_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- MetaBackendNative *backend_native = META_BACKEND_NATIVE (object);
-
- switch (prop_id)
- {
- case PROP_HEADLESS:
- backend_native->is_headless = g_value_get_boolean (value);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-
-static void
-initable_iface_init (GInitableIface *initable_iface)
-{
- initable_parent_iface = g_type_interface_peek_parent (initable_iface);
-
- initable_iface->init = meta_backend_native_initable_init;
-}
-
-static void
-meta_backend_native_class_init (MetaBackendNativeClass *klass)
-{
- MetaBackendClass *backend_class = META_BACKEND_CLASS (klass);
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- object_class->set_property = meta_backend_native_set_property;
- object_class->dispose = meta_backend_native_dispose;
-
- backend_class->create_clutter_backend = meta_backend_native_create_clutter_backend;
- backend_class->create_default_seat = meta_backend_native_create_default_seat;
-
- backend_class->post_init = meta_backend_native_post_init;
-
- backend_class->create_monitor_manager = meta_backend_native_create_monitor_manager;
- backend_class->get_cursor_renderer = meta_backend_native_get_cursor_renderer;
- backend_class->create_renderer = meta_backend_native_create_renderer;
- backend_class->get_input_settings = meta_backend_native_get_input_settings;
-
- backend_class->get_current_logical_monitor = meta_backend_native_get_current_logical_monitor;
-
- backend_class->set_keymap = meta_backend_native_set_keymap;
- backend_class->get_keymap = meta_backend_native_get_keymap;
- backend_class->get_keymap_layout_group = meta_backend_native_get_keymap_layout_group;
- backend_class->lock_layout_group = meta_backend_native_lock_layout_group;
- backend_class->update_screen_size = meta_backend_native_update_screen_size;
-
- backend_class->set_pointer_constraint = meta_backend_native_set_pointer_constraint;
-
- obj_props[PROP_HEADLESS] =
- g_param_spec_boolean ("headless",
- "headless",
- "Headless",
- FALSE,
- G_PARAM_WRITABLE |
- G_PARAM_CONSTRUCT_ONLY |
- G_PARAM_STATIC_STRINGS);
- g_object_class_install_properties (object_class, N_PROPS, obj_props);
-}
-
-static void
-meta_backend_native_init (MetaBackendNative *native)
-{
-}
-
-MetaLauncher *
-meta_backend_native_get_launcher (MetaBackendNative *native)
-{
- return native->launcher;
-}
-
-MetaDevicePool *
-meta_backend_native_get_device_pool (MetaBackendNative *native)
-{
- return native->device_pool;
-}
-
-MetaUdev *
-meta_backend_native_get_udev (MetaBackendNative *native)
-{
- return native->udev;
-}
-
-MetaKms *
-meta_backend_native_get_kms (MetaBackendNative *native)
-{
- return native->kms;
-}
-
-gboolean
-meta_activate_vt (int vt, GError **error)
-{
- MetaBackend *backend = meta_get_backend ();
- MetaBackendNative *native = META_BACKEND_NATIVE (backend);
- MetaLauncher *launcher = meta_backend_native_get_launcher (native);
-
- if (native->is_headless)
- {
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- "Can't switch VT while headless");
- return FALSE;
- }
-
- return meta_launcher_activate_vt (launcher, vt, error);
-}
-
-void
-meta_backend_native_pause (MetaBackendNative *native)
-{
- MetaBackend *backend = META_BACKEND (native);
- MetaMonitorManager *monitor_manager =
- meta_backend_get_monitor_manager (backend);
- MetaMonitorManagerNative *monitor_manager_native =
- META_MONITOR_MANAGER_NATIVE (monitor_manager);
- ClutterBackend *clutter_backend = meta_backend_get_clutter_backend (backend);
- MetaSeatNative *seat =
- META_SEAT_NATIVE (clutter_backend_get_default_seat (clutter_backend));
- MetaRenderer *renderer = meta_backend_get_renderer (backend);
-
- COGL_TRACE_BEGIN_SCOPED (MetaBackendNativePause,
- "Backend (pause)");
-
- meta_seat_native_release_devices (seat);
- meta_renderer_pause (renderer);
-
- disconnect_udev_device_added_handler (native);
-
- meta_monitor_manager_native_pause (monitor_manager_native);
-}
-
-void meta_backend_native_resume (MetaBackendNative *native)
-{
- MetaBackend *backend = META_BACKEND (native);
- ClutterStage *stage = CLUTTER_STAGE (meta_backend_get_stage (backend));
- MetaMonitorManager *monitor_manager =
- meta_backend_get_monitor_manager (backend);
- MetaMonitorManagerNative *monitor_manager_native =
- META_MONITOR_MANAGER_NATIVE (monitor_manager);
- ClutterBackend *clutter_backend = meta_backend_get_clutter_backend (backend);
- MetaSeatNative *seat =
- META_SEAT_NATIVE (clutter_backend_get_default_seat (clutter_backend));
- MetaRenderer *renderer = meta_backend_get_renderer (backend);
- MetaIdleManager *idle_manager;
- MetaInputSettings *input_settings;
-
- COGL_TRACE_BEGIN_SCOPED (MetaBackendNativeResume,
- "Backend (resume)");
-
- meta_monitor_manager_native_resume (monitor_manager_native);
- meta_kms_resume (native->kms);
-
- connect_udev_device_added_handler (native);
-
- meta_seat_native_reclaim_devices (seat);
- meta_renderer_resume (renderer);
-
- clutter_actor_queue_redraw (CLUTTER_ACTOR (stage));
-
- idle_manager = meta_backend_get_idle_manager (backend);
- meta_idle_manager_reset_idle_time (idle_manager);
-
- input_settings = meta_backend_get_input_settings (backend);
- meta_input_settings_maybe_restore_numlock_state (input_settings);
-
- clutter_seat_ensure_a11y_state (CLUTTER_SEAT (seat));
-}
diff --git a/src/backends/native/meta-backend-native.h b/src/backends/native/meta-backend-native.h
deleted file mode 100644
index aad4c8413..000000000
--- a/src/backends/native/meta-backend-native.h
+++ /dev/null
@@ -1,55 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2014 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Written by:
- * Jasper St. Pierre <jstpierre@mecheye.net>
- */
-
-#ifndef META_BACKEND_NATIVE_H
-#define META_BACKEND_NATIVE_H
-
-#include "backends/meta-backend-private.h"
-#include "backends/native/meta-clutter-backend-native.h"
-#include "backends/native/meta-kms-types.h"
-#include "backends/native/meta-launcher.h"
-#include "backends/native/meta-udev.h"
-
-#define META_TYPE_BACKEND_NATIVE (meta_backend_native_get_type ())
-META_EXPORT_TEST
-G_DECLARE_FINAL_TYPE (MetaBackendNative, meta_backend_native,
- META, BACKEND_NATIVE, MetaBackend)
-
-gboolean meta_activate_vt (int vt, GError **error);
-
-void meta_backend_native_pause (MetaBackendNative *backend_native);
-
-void meta_backend_native_resume (MetaBackendNative *backend_native);
-
-MetaLauncher * meta_backend_native_get_launcher (MetaBackendNative *native);
-
-MetaUdev * meta_backend_native_get_udev (MetaBackendNative *native);
-
-MetaKms * meta_backend_native_get_kms (MetaBackendNative *native);
-
-const char * meta_backend_native_get_seat_id (MetaBackendNative *backend_native);
-
-gboolean meta_backend_native_is_headless (MetaBackendNative *backend_native);
-
-#endif /* META_BACKEND_NATIVE_H */
diff --git a/src/backends/native/meta-barrier-native.c b/src/backends/native/meta-barrier-native.c
deleted file mode 100644
index 3c9c1eabe..000000000
--- a/src/backends/native/meta-barrier-native.c
+++ /dev/null
@@ -1,652 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2015 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Written by:
- * Jonas Ådahl <jadahl@gmail.com>
- */
-
-/**
- * SECTION:barrier-native
- * @Title: MetaBarrierImplNative
- * @Short_Description: Pointer barriers implementation for the native backend
- */
-
-#include "config.h"
-
-#include "backends/native/meta-barrier-native.h"
-
-#include <stdlib.h>
-
-#include "backends/meta-backend-private.h"
-#include "backends/meta-barrier-private.h"
-#include "backends/native/meta-seat-native.h"
-#include "meta/barrier.h"
-#include "meta/util.h"
-
-struct _MetaBarrierManagerNative
-{
- GHashTable *barriers;
- GMutex mutex;
-};
-
-typedef enum
-{
- /* The barrier is active and responsive to pointer motion. */
- META_BARRIER_STATE_ACTIVE,
-
- /* An intermediate state after a pointer hit the pointer barrier. */
- META_BARRIER_STATE_HIT,
-
- /* The barrier was hit by a pointer and is still within the hit box and
- * has not been released.*/
- META_BARRIER_STATE_HELD,
-
- /* The pointer was released by the user. If the following motion hits
- * the barrier, it will pass through. */
- META_BARRIER_STATE_RELEASE,
-
- /* An intermediate state when the pointer has left the barrier. */
- META_BARRIER_STATE_LEFT,
-} MetaBarrierState;
-
-struct _MetaBarrierImplNative
-{
- MetaBarrierImpl parent;
-
- MetaBarrier *barrier;
- MetaBarrierManagerNative *manager;
-
- gboolean is_active;
- MetaBarrierState state;
- int trigger_serial;
- guint32 last_event_time;
- MetaBarrierDirection blocked_dir;
- GMainContext *main_context;
-};
-
-G_DEFINE_TYPE (MetaBarrierImplNative,
- meta_barrier_impl_native,
- META_TYPE_BARRIER_IMPL)
-
-static int
-next_serial (void)
-{
- static int barrier_serial = 1;
-
- barrier_serial++;
-
- /* If it wraps, avoid 0 as it's not a valid serial. */
- if (barrier_serial == 0)
- barrier_serial++;
-
- return barrier_serial;
-}
-
-static gboolean
-is_barrier_horizontal (MetaBarrier *barrier)
-{
- return meta_border_is_horizontal (&barrier->priv->border);
-}
-
-static gboolean
-is_barrier_blocking_directions (MetaBarrier *barrier,
- MetaBarrierDirection directions)
-{
- return meta_border_is_blocking_directions (&barrier->priv->border,
- directions);
-}
-
-static void
-dismiss_pointer (MetaBarrierImplNative *self)
-{
- self->state = META_BARRIER_STATE_LEFT;
-}
-
-/*
- * Calculate the hit box for a held motion. The hit box is a 2 px wide region
- * in the opposite direction of every direction the barrier blocks. The purpose
- * of this is to allow small movements without receiving a "left" signal. This
- * heuristic comes from the X.org pointer barrier implementation.
- */
-static MetaLine2
-calculate_barrier_hit_box (MetaBarrier *barrier)
-{
- MetaLine2 hit_box = barrier->priv->border.line;
-
- if (is_barrier_horizontal (barrier))
- {
- if (is_barrier_blocking_directions (barrier,
- META_BARRIER_DIRECTION_POSITIVE_Y))
- hit_box.a.y -= 2.0f;
- if (is_barrier_blocking_directions (barrier,
- META_BARRIER_DIRECTION_NEGATIVE_Y))
- hit_box.b.y += 2.0f;
- }
- else
- {
- if (is_barrier_blocking_directions (barrier,
- META_BARRIER_DIRECTION_POSITIVE_X))
- hit_box.a.x -= 2.0f;
- if (is_barrier_blocking_directions (barrier,
- META_BARRIER_DIRECTION_NEGATIVE_X))
- hit_box.b.x += 2.0f;
- }
-
- return hit_box;
-}
-
-static gboolean
-is_within_box (MetaLine2 box,
- MetaVector2 point)
-{
- return (point.x >= box.a.x && point.x < box.b.x &&
- point.y >= box.a.y && point.y < box.b.y);
-}
-
-static void
-maybe_release_barrier (gpointer key,
- gpointer value,
- gpointer user_data)
-{
- MetaBarrierImplNative *self = key;
- MetaBarrier *barrier = self->barrier;
- MetaLine2 *motion = user_data;
- MetaLine2 hit_box;
-
- if (self->state != META_BARRIER_STATE_HELD)
- return;
-
- /* Release if we end up outside barrier end points. */
- if (is_barrier_horizontal (barrier))
- {
- if (motion->b.x > MAX (barrier->priv->border.line.a.x,
- barrier->priv->border.line.b.x) ||
- motion->b.x < MIN (barrier->priv->border.line.a.x,
- barrier->priv->border.line.b.x))
- {
- dismiss_pointer (self);
- return;
- }
- }
- else
- {
- if (motion->b.y > MAX (barrier->priv->border.line.a.y,
- barrier->priv->border.line.b.y) ||
- motion->b.y < MIN (barrier->priv->border.line.a.y,
- barrier->priv->border.line.b.y))
- {
- dismiss_pointer (self);
- return;
- }
- }
-
- /* Release if we don't intersect and end up outside of hit box. */
- hit_box = calculate_barrier_hit_box (barrier);
- if (!is_within_box (hit_box, motion->b))
- {
- dismiss_pointer (self);
- return;
- }
-}
-
-static void
-maybe_release_barriers (MetaBarrierManagerNative *manager,
- float prev_x,
- float prev_y,
- float x,
- float y)
-{
- MetaLine2 motion = {
- .a = {
- .x = prev_x,
- .y = prev_y,
- },
- .b = {
- .x = x,
- .y = y,
- },
- };
-
- g_hash_table_foreach (manager->barriers,
- maybe_release_barrier,
- &motion);
-}
-
-typedef struct _MetaClosestBarrierData
-{
- struct
- {
- MetaLine2 motion;
- MetaBarrierDirection directions;
- } in;
-
- struct
- {
- float closest_distance_2;
- MetaBarrierImplNative *barrier_impl;
- } out;
-} MetaClosestBarrierData;
-
-static void
-update_closest_barrier (gpointer key,
- gpointer value,
- gpointer user_data)
-{
- MetaBarrierImplNative *self = key;
- MetaBarrier *barrier = self->barrier;
- MetaClosestBarrierData *data = user_data;
- MetaVector2 intersection;
- float dx, dy;
- float distance_2;
-
- /* Ignore if the barrier is not blocking in any of the motions directions. */
- if (!is_barrier_blocking_directions (barrier, data->in.directions))
- return;
-
- /* Ignore if the barrier released the pointer. */
- if (self->state == META_BARRIER_STATE_RELEASE)
- return;
-
- /* Ignore if we are moving away from barrier. */
- if (self->state == META_BARRIER_STATE_HELD &&
- (data->in.directions & self->blocked_dir) == 0)
- return;
-
- /* Check if the motion intersects with the barrier, and retrieve the
- * intersection point if any. */
- if (!meta_line2_intersects_with (&barrier->priv->border.line,
- &data->in.motion,
- &intersection))
- return;
-
- /* Calculate the distance to the barrier and keep track of the closest
- * barrier. */
- dx = intersection.x - data->in.motion.a.x;
- dy = intersection.y - data->in.motion.a.y;
- distance_2 = dx*dx + dy*dy;
- if (data->out.barrier_impl == NULL ||
- distance_2 < data->out.closest_distance_2)
- {
- data->out.barrier_impl = self;
- data->out.closest_distance_2 = distance_2;
- }
-}
-
-static gboolean
-get_closest_barrier (MetaBarrierManagerNative *manager,
- float prev_x,
- float prev_y,
- float x,
- float y,
- MetaBarrierDirection motion_dir,
- MetaBarrierImplNative **barrier_impl)
-{
- MetaClosestBarrierData closest_barrier_data;
-
- closest_barrier_data = (MetaClosestBarrierData) {
- .in = {
- .motion = {
- .a = {
- .x = prev_x,
- .y = prev_y,
- },
- .b = {
- .x = x,
- .y = y,
- },
- },
- .directions = motion_dir,
- },
- };
-
- g_hash_table_foreach (manager->barriers,
- update_closest_barrier,
- &closest_barrier_data);
-
- if (closest_barrier_data.out.barrier_impl != NULL)
- {
- *barrier_impl = closest_barrier_data.out.barrier_impl;
- return TRUE;
- }
- else
- {
- return FALSE;
- }
-}
-
-typedef struct _MetaBarrierEventData
-{
- guint32 time;
- float prev_x;
- float prev_y;
- float x;
- float y;
- float dx;
- float dy;
-} MetaBarrierEventData;
-
-typedef struct
-{
- MetaBarrierEvent *event;
- MetaBarrier *barrier;
- MetaBarrierState state;
-} MetaBarrierIdleData;
-
-static gboolean
-emit_event_idle (MetaBarrierIdleData *idle_data)
-{
- if (idle_data->state == META_BARRIER_STATE_HELD)
- _meta_barrier_emit_hit_signal (idle_data->barrier, idle_data->event);
- else
- _meta_barrier_emit_left_signal (idle_data->barrier, idle_data->event);
-
- meta_barrier_event_unref (idle_data->event);
-
- return G_SOURCE_REMOVE;
-}
-
-static void
-queue_event (MetaBarrierImplNative *self,
- MetaBarrierEvent *event)
-{
- MetaBarrierIdleData *idle_data;
- GSource *source;
-
- idle_data = g_new0 (MetaBarrierIdleData, 1);
- idle_data->state = self->state;
- idle_data->barrier = self->barrier;
- idle_data->event = event;
-
- source = g_idle_source_new ();
- g_source_set_priority (source, G_PRIORITY_HIGH);
- g_source_set_callback (source,
- (GSourceFunc) emit_event_idle,
- idle_data,
- g_free);
-
- g_source_attach (source, self->main_context);
- g_source_unref (source);
-}
-
-static void
-emit_barrier_event (MetaBarrierImplNative *self,
- guint32 time,
- float prev_x,
- float prev_y,
- float x,
- float y,
- float dx,
- float dy)
-{
- MetaBarrierEvent *event = g_new0 (MetaBarrierEvent, 1);
- MetaBarrierState old_state = self->state;
-
- switch (self->state)
- {
- case META_BARRIER_STATE_HIT:
- self->state = META_BARRIER_STATE_HELD;
- self->trigger_serial = next_serial ();
- event->dt = 0;
-
- break;
- case META_BARRIER_STATE_RELEASE:
- case META_BARRIER_STATE_LEFT:
- self->state = META_BARRIER_STATE_ACTIVE;
-
- G_GNUC_FALLTHROUGH;
- case META_BARRIER_STATE_HELD:
- event->dt = time - self->last_event_time;
-
- break;
- case META_BARRIER_STATE_ACTIVE:
- g_assert_not_reached (); /* Invalid state. */
- }
-
- event->ref_count = 1;
- event->event_id = self->trigger_serial;
- event->time = time;
-
- event->x = x;
- event->y = y;
- event->dx = dx;
- event->dy = dy;
-
- event->grabbed = self->state == META_BARRIER_STATE_HELD;
- event->released = old_state == META_BARRIER_STATE_RELEASE;
-
- self->last_event_time = time;
-
- queue_event (self, event);
-}
-
-static void
-maybe_emit_barrier_event (gpointer key, gpointer value, gpointer user_data)
-{
- MetaBarrierImplNative *self = key;
- MetaBarrierEventData *data = user_data;
-
- switch (self->state)
- {
- case META_BARRIER_STATE_ACTIVE:
- break;
- case META_BARRIER_STATE_HIT:
- case META_BARRIER_STATE_HELD:
- case META_BARRIER_STATE_RELEASE:
- case META_BARRIER_STATE_LEFT:
- emit_barrier_event (self,
- data->time,
- data->prev_x,
- data->prev_y,
- data->x,
- data->y,
- data->dx,
- data->dy);
- break;
- }
-}
-
-/* Clamp (x, y) to the barrier and remove clamped direction from motion_dir. */
-static void
-clamp_to_barrier (MetaBarrierImplNative *self,
- MetaBarrierDirection *motion_dir,
- float *x,
- float *y)
-{
- MetaBarrier *barrier = self->barrier;
-
- if (is_barrier_horizontal (barrier))
- {
- if (*motion_dir & META_BARRIER_DIRECTION_POSITIVE_Y)
- *y = barrier->priv->border.line.a.y;
- else if (*motion_dir & META_BARRIER_DIRECTION_NEGATIVE_Y)
- *y = barrier->priv->border.line.a.y;
-
- self->blocked_dir = *motion_dir & (META_BARRIER_DIRECTION_POSITIVE_Y |
- META_BARRIER_DIRECTION_NEGATIVE_Y);
- *motion_dir &= ~(META_BARRIER_DIRECTION_POSITIVE_Y |
- META_BARRIER_DIRECTION_NEGATIVE_Y);
- }
- else
- {
- if (*motion_dir & META_BARRIER_DIRECTION_POSITIVE_X)
- *x = barrier->priv->border.line.a.x;
- else if (*motion_dir & META_BARRIER_DIRECTION_NEGATIVE_X)
- *x = barrier->priv->border.line.a.x;
-
- self->blocked_dir = *motion_dir & (META_BARRIER_DIRECTION_POSITIVE_X |
- META_BARRIER_DIRECTION_NEGATIVE_X);
- *motion_dir &= ~(META_BARRIER_DIRECTION_POSITIVE_X |
- META_BARRIER_DIRECTION_NEGATIVE_X);
- }
-
- self->state = META_BARRIER_STATE_HIT;
-}
-
-void
-meta_barrier_manager_native_process_in_impl (MetaBarrierManagerNative *manager,
- ClutterInputDevice *device,
- guint32 time,
- float *x,
- float *y)
-{
- graphene_point_t prev_pos;
- float prev_x;
- float prev_y;
- float orig_x = *x;
- float orig_y = *y;
- MetaBarrierDirection motion_dir = 0;
- MetaBarrierEventData barrier_event_data;
- MetaBarrierImplNative *barrier_impl;
-
- if (!clutter_seat_query_state (clutter_input_device_get_seat (device),
- device, NULL, &prev_pos, NULL))
- return;
-
- g_mutex_lock (&manager->mutex);
-
- prev_x = prev_pos.x;
- prev_y = prev_pos.y;
-
- /* Get the direction of the motion vector. */
- if (prev_x < *x)
- motion_dir |= META_BARRIER_DIRECTION_POSITIVE_X;
- else if (prev_x > *x)
- motion_dir |= META_BARRIER_DIRECTION_NEGATIVE_X;
- if (prev_y < *y)
- motion_dir |= META_BARRIER_DIRECTION_POSITIVE_Y;
- else if (prev_y > *y)
- motion_dir |= META_BARRIER_DIRECTION_NEGATIVE_Y;
-
- /* Clamp to the closest barrier in any direction until either there are no
- * more barriers to clamp to or all directions have been clamped. */
- while (motion_dir != 0)
- {
- if (get_closest_barrier (manager,
- prev_x, prev_y,
- *x, *y,
- motion_dir,
- &barrier_impl))
- clamp_to_barrier (barrier_impl, &motion_dir, x, y);
- else
- break;
- }
-
- /* Potentially release active barrier movements. */
- maybe_release_barriers (manager, prev_x, prev_y, *x, *y);
-
- /* Initiate or continue barrier interaction. */
- barrier_event_data = (MetaBarrierEventData) {
- .time = time,
- .prev_x = prev_x,
- .prev_y = prev_y,
- .x = *x,
- .y = *y,
- .dx = orig_x - prev_x,
- .dy = orig_y - prev_y,
- };
-
- g_hash_table_foreach (manager->barriers,
- maybe_emit_barrier_event,
- &barrier_event_data);
-
- g_mutex_unlock (&manager->mutex);
-}
-
-static gboolean
-_meta_barrier_impl_native_is_active (MetaBarrierImpl *impl)
-{
- MetaBarrierImplNative *self = META_BARRIER_IMPL_NATIVE (impl);
-
- return self->is_active;
-}
-
-static void
-_meta_barrier_impl_native_release (MetaBarrierImpl *impl,
- MetaBarrierEvent *event)
-{
- MetaBarrierImplNative *self = META_BARRIER_IMPL_NATIVE (impl);
-
- if (self->state == META_BARRIER_STATE_HELD &&
- event->event_id == self->trigger_serial)
- self->state = META_BARRIER_STATE_RELEASE;
-}
-
-static void
-_meta_barrier_impl_native_destroy (MetaBarrierImpl *impl)
-{
- MetaBarrierImplNative *self = META_BARRIER_IMPL_NATIVE (impl);
-
- g_mutex_lock (&self->manager->mutex);
- g_hash_table_remove (self->manager->barriers, self);
- g_mutex_unlock (&self->manager->mutex);
- g_main_context_unref (self->main_context);
- self->is_active = FALSE;
-}
-
-MetaBarrierImpl *
-meta_barrier_impl_native_new (MetaBarrier *barrier)
-{
- MetaBarrierImplNative *self;
- MetaBarrierManagerNative *manager;
- ClutterBackend *backend = clutter_get_default_backend ();
- ClutterSeat *seat = clutter_backend_get_default_seat (backend);
-
- self = g_object_new (META_TYPE_BARRIER_IMPL_NATIVE, NULL);
-
- self->barrier = barrier;
- self->is_active = TRUE;
- self->main_context = g_main_context_ref_thread_default ();
-
- manager = meta_seat_native_get_barrier_manager (META_SEAT_NATIVE (seat));
- self->manager = manager;
- g_mutex_lock (&manager->mutex);
- g_hash_table_add (manager->barriers, self);
- g_mutex_unlock (&manager->mutex);
-
- return META_BARRIER_IMPL (self);
-}
-
-static void
-meta_barrier_impl_native_class_init (MetaBarrierImplNativeClass *klass)
-{
- MetaBarrierImplClass *impl_class = META_BARRIER_IMPL_CLASS (klass);
-
- impl_class->is_active = _meta_barrier_impl_native_is_active;
- impl_class->release = _meta_barrier_impl_native_release;
- impl_class->destroy = _meta_barrier_impl_native_destroy;
-}
-
-static void
-meta_barrier_impl_native_init (MetaBarrierImplNative *self)
-{
-}
-
-MetaBarrierManagerNative *
-meta_barrier_manager_native_new (void)
-{
- MetaBarrierManagerNative *manager;
-
- manager = g_new0 (MetaBarrierManagerNative, 1);
-
- manager->barriers = g_hash_table_new (NULL, NULL);
- g_mutex_init (&manager->mutex);
-
- return manager;
-}
diff --git a/src/backends/native/meta-barrier-native.h b/src/backends/native/meta-barrier-native.h
deleted file mode 100644
index 1bcf56c7c..000000000
--- a/src/backends/native/meta-barrier-native.h
+++ /dev/null
@@ -1,52 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2015 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Written by:
- * Jonas Ådahl <jadahl@gmail.com>
- */
-
-#ifndef META_BARRIER_NATIVE_H
-#define META_BARRIER_NATIVE_H
-
-#include "backends/meta-barrier-private.h"
-
-G_BEGIN_DECLS
-
-#define META_TYPE_BARRIER_IMPL_NATIVE (meta_barrier_impl_native_get_type ())
-G_DECLARE_FINAL_TYPE (MetaBarrierImplNative,
- meta_barrier_impl_native,
- META, BARRIER_IMPL_NATIVE,
- MetaBarrierImpl)
-
-typedef struct _MetaBarrierManagerNative MetaBarrierManagerNative;
-
-
-MetaBarrierImpl *meta_barrier_impl_native_new (MetaBarrier *barrier);
-
-MetaBarrierManagerNative *meta_barrier_manager_native_new (void);
-void meta_barrier_manager_native_process_in_impl (MetaBarrierManagerNative *manager,
- ClutterInputDevice *device,
- guint32 time,
- float *x,
- float *y);
-
-G_END_DECLS
-
-#endif /* META_BARRIER_NATIVE_H */
diff --git a/src/backends/native/meta-clutter-backend-native.c b/src/backends/native/meta-clutter-backend-native.c
deleted file mode 100644
index a28ecea99..000000000
--- a/src/backends/native/meta-clutter-backend-native.c
+++ /dev/null
@@ -1,111 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2016 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Written by:
- * Jonas Ådahl <jadahl@gmail.com>
- */
-
-/**
- * SECTION:meta-clutter-backend-native
- * @title: MetaClutterBackendNatve
- * @short_description: A native backend which renders using EGL.
- *
- * MetaClutterBackendNative is the #ClutterBackend which is used by the native
- * (as opposed to the X) backend. It creates a stage with #MetaStageNative and
- * renders using the #CoglRenderer.
- *
- * Note that MetaClutterBackendNative is something different than a
- * #MetaBackendNative. The former is a #ClutterBackend implementation, while
- * the latter is a #MetaBackend implementation.
- */
-
-#include "config.h"
-
-#include "backends/native/meta-clutter-backend-native.h"
-
-#include <glib-object.h>
-
-#include "backends/meta-backend-private.h"
-#include "backends/meta-renderer.h"
-#include "backends/native/meta-backend-native.h"
-#include "backends/native/meta-seat-native.h"
-#include "backends/native/meta-stage-native.h"
-#include "clutter/clutter.h"
-#include "core/bell.h"
-#include "meta/meta-backend.h"
-
-struct _MetaClutterBackendNative
-{
- ClutterBackend parent;
-};
-
-G_DEFINE_TYPE (MetaClutterBackendNative, meta_clutter_backend_native,
- CLUTTER_TYPE_BACKEND)
-
-static CoglRenderer *
-meta_clutter_backend_native_get_renderer (ClutterBackend *clutter_backend,
- GError **error)
-{
- MetaBackend *backend = meta_get_backend ();
- MetaRenderer *renderer = meta_backend_get_renderer (backend);
-
- return meta_renderer_create_cogl_renderer (renderer);
-}
-
-static ClutterStageWindow *
-meta_clutter_backend_native_create_stage (ClutterBackend *clutter_backend,
- ClutterStage *wrapper,
- GError **error)
-{
- return g_object_new (META_TYPE_STAGE_NATIVE,
- "backend", clutter_backend,
- "wrapper", wrapper,
- NULL);
-}
-
-static ClutterSeat *
-meta_clutter_backend_native_get_default_seat (ClutterBackend *clutter_backend)
-{
- MetaBackend *backend = meta_get_backend ();
-
- return meta_backend_get_default_seat (backend);
-}
-
-static gboolean
-meta_clutter_backend_native_is_display_server (ClutterBackend *clutter_backend)
-{
- return TRUE;
-}
-
-static void
-meta_clutter_backend_native_init (MetaClutterBackendNative *clutter_backend_nativen)
-{
-}
-
-static void
-meta_clutter_backend_native_class_init (MetaClutterBackendNativeClass *klass)
-{
- ClutterBackendClass *clutter_backend_class = CLUTTER_BACKEND_CLASS (klass);
-
- clutter_backend_class->get_renderer = meta_clutter_backend_native_get_renderer;
- clutter_backend_class->create_stage = meta_clutter_backend_native_create_stage;
- clutter_backend_class->get_default_seat = meta_clutter_backend_native_get_default_seat;
- clutter_backend_class->is_display_server = meta_clutter_backend_native_is_display_server;
-}
diff --git a/src/backends/native/meta-clutter-backend-native.h b/src/backends/native/meta-clutter-backend-native.h
deleted file mode 100644
index dea35988c..000000000
--- a/src/backends/native/meta-clutter-backend-native.h
+++ /dev/null
@@ -1,38 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2016 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Written by:
- * Jonas Ådahl <jadahl@gmail.com>
- */
-
-#ifndef META_CLUTTER_BACKEND_NATIVE_H
-#define META_CLUTTER_BACKEND_NATIVE_H
-
-#include <glib-object.h>
-
-#include "backends/native/meta-stage-native.h"
-#include "clutter/clutter.h"
-
-#define META_TYPE_CLUTTER_BACKEND_NATIVE (meta_clutter_backend_native_get_type ())
-G_DECLARE_FINAL_TYPE (MetaClutterBackendNative, meta_clutter_backend_native,
- META, CLUTTER_BACKEND_NATIVE,
- ClutterBackend)
-
-#endif /* META_CLUTTER_BACKEND_NATIVE_H */
diff --git a/src/backends/native/meta-cogl-utils.c b/src/backends/native/meta-cogl-utils.c
deleted file mode 100644
index 582f86661..000000000
--- a/src/backends/native/meta-cogl-utils.c
+++ /dev/null
@@ -1,85 +0,0 @@
-/* meta-cogl-utils.c
- *
- * Copyright 2020 Georges Basile Stavracas Neto <georges.stavracas@gmail.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * SPDX-License-Identifier: GPL-2.0-or-later
- *
- */
-
-#include "backends/native/meta-cogl-utils.h"
-
-#include <drm_fourcc.h>
-
-typedef struct _PixelFormatMap {
- uint32_t drm_format;
- CoglPixelFormat cogl_format;
- CoglTextureComponents cogl_components;
-} PixelFormatMap;
-
-static const PixelFormatMap pixel_format_map[] = {
-/* DRM formats are defined as little-endian, not machine endian. */
-#if G_BYTE_ORDER == G_LITTLE_ENDIAN
- { DRM_FORMAT_RGB565, COGL_PIXEL_FORMAT_RGB_565, COGL_TEXTURE_COMPONENTS_RGB },
- { DRM_FORMAT_ABGR8888, COGL_PIXEL_FORMAT_RGBA_8888_PRE, COGL_TEXTURE_COMPONENTS_RGBA },
- { DRM_FORMAT_XBGR8888, COGL_PIXEL_FORMAT_RGBA_8888_PRE, COGL_TEXTURE_COMPONENTS_RGB },
- { DRM_FORMAT_ARGB8888, COGL_PIXEL_FORMAT_BGRA_8888_PRE, COGL_TEXTURE_COMPONENTS_RGBA },
- { DRM_FORMAT_XRGB8888, COGL_PIXEL_FORMAT_BGRA_8888_PRE, COGL_TEXTURE_COMPONENTS_RGB },
- { DRM_FORMAT_BGRA8888, COGL_PIXEL_FORMAT_ARGB_8888_PRE, COGL_TEXTURE_COMPONENTS_RGBA },
- { DRM_FORMAT_BGRX8888, COGL_PIXEL_FORMAT_ARGB_8888_PRE, COGL_TEXTURE_COMPONENTS_RGB },
- { DRM_FORMAT_RGBA8888, COGL_PIXEL_FORMAT_ABGR_8888_PRE, COGL_TEXTURE_COMPONENTS_RGBA },
- { DRM_FORMAT_RGBX8888, COGL_PIXEL_FORMAT_ABGR_8888_PRE, COGL_TEXTURE_COMPONENTS_RGB },
-#elif G_BYTE_ORDER == G_BIG_ENDIAN
- /* DRM_FORMAT_RGB565 cannot be expressed. */
- { DRM_FORMAT_ABGR8888, COGL_PIXEL_FORMAT_ABGR_8888_PRE, COGL_TEXTURE_COMPONENTS_RGBA },
- { DRM_FORMAT_XBGR8888, COGL_PIXEL_FORMAT_ABGR_8888_PRE, COGL_TEXTURE_COMPONENTS_RGB },
- { DRM_FORMAT_ARGB8888, COGL_PIXEL_FORMAT_ARGB_8888_PRE, COGL_TEXTURE_COMPONENTS_RGBA },
- { DRM_FORMAT_XRGB8888, COGL_PIXEL_FORMAT_ARGB_8888_PRE, COGL_TEXTURE_COMPONENTS_RGB },
- { DRM_FORMAT_BGRA8888, COGL_PIXEL_FORMAT_BGRA_8888_PRE, COGL_TEXTURE_COMPONENTS_RGBA },
- { DRM_FORMAT_BGRX8888, COGL_PIXEL_FORMAT_BGRA_8888_PRE, COGL_TEXTURE_COMPONENTS_RGB },
- { DRM_FORMAT_RGBA8888, COGL_PIXEL_FORMAT_RGBA_8888_PRE, COGL_TEXTURE_COMPONENTS_RGBA },
- { DRM_FORMAT_RGBX8888, COGL_PIXEL_FORMAT_RGBA_8888_PRE, COGL_TEXTURE_COMPONENTS_RGB },
-#else
-#error "unexpected G_BYTE_ORDER"
-#endif
-};
-
-gboolean
-meta_cogl_pixel_format_from_drm_format (uint32_t drm_format,
- CoglPixelFormat *out_format,
- CoglTextureComponents *out_components)
-{
- const size_t n = G_N_ELEMENTS (pixel_format_map);
- size_t i;
-
- for (i = 0; i < n; i++)
- {
- if (pixel_format_map[i].drm_format == drm_format)
- break;
- }
-
- if (i == n)
- return FALSE;
-
- if (out_format)
- *out_format = pixel_format_map[i].cogl_format;
-
- if (out_components)
- *out_components = pixel_format_map[i].cogl_components;
-
- return TRUE;
-}
diff --git a/src/backends/native/meta-cogl-utils.h b/src/backends/native/meta-cogl-utils.h
deleted file mode 100644
index b5fe6296f..000000000
--- a/src/backends/native/meta-cogl-utils.h
+++ /dev/null
@@ -1,38 +0,0 @@
-/* meta-cogl-utils.h
- *
- * Copyright 2020 Georges Basile Stavracas Neto <georges.stavracas@gmail.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * SPDX-License-Identifier: GPL-2.0-or-later
- *
- */
-
-#ifndef META_COGL_UTILS_H
-#define META_COGL_UTILS_H
-
-#include "cogl/cogl.h"
-
-G_BEGIN_DECLS
-
-gboolean
-meta_cogl_pixel_format_from_drm_format (uint32_t drm_format,
- CoglPixelFormat *out_format,
- CoglTextureComponents *out_components);
-
-G_END_DECLS
-
-#endif /* META_COGL_UTILS_H */
diff --git a/src/backends/native/meta-crtc-kms.c b/src/backends/native/meta-crtc-kms.c
deleted file mode 100644
index f1bc79146..000000000
--- a/src/backends/native/meta-crtc-kms.c
+++ /dev/null
@@ -1,386 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2013-2017 Red Hat
- * Copyright (C) 2018 DisplayLink (UK) Ltd.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-
-#include "config.h"
-
-#include "backends/native/meta-crtc-kms.h"
-
-#include "backends/meta-backend-private.h"
-#include "backends/meta-logical-monitor.h"
-#include "backends/native/meta-crtc-mode-kms.h"
-#include "backends/native/meta-gpu-kms.h"
-#include "backends/native/meta-output-kms.h"
-#include "backends/native/meta-kms-device.h"
-#include "backends/native/meta-kms-mode.h"
-#include "backends/native/meta-kms-plane.h"
-#include "backends/native/meta-kms-update.h"
-#include "backends/native/meta-kms.h"
-#include "backends/native/meta-monitor-manager-native.h"
-
-#define ALL_TRANSFORMS_MASK ((1 << META_MONITOR_N_TRANSFORMS) - 1)
-
-struct _MetaCrtcKms
-{
- MetaCrtcNative parent;
-
- MetaKmsCrtc *kms_crtc;
-
- MetaKmsPlane *primary_plane;
-
- gpointer cursor_renderer_private;
- GDestroyNotify cursor_renderer_private_destroy_notify;
-
- gboolean is_gamma_valid;
-};
-
-static GQuark kms_crtc_crtc_kms_quark;
-
-G_DEFINE_TYPE (MetaCrtcKms, meta_crtc_kms, META_TYPE_CRTC_NATIVE)
-
-gpointer
-meta_crtc_kms_get_cursor_renderer_private (MetaCrtcKms *crtc_kms)
-{
- return crtc_kms->cursor_renderer_private;
-}
-
-void
-meta_crtc_kms_set_cursor_renderer_private (MetaCrtcKms *crtc_kms,
- gpointer cursor_renderer_private,
- GDestroyNotify destroy_notify)
-{
- g_clear_pointer (&crtc_kms->cursor_renderer_private,
- crtc_kms->cursor_renderer_private_destroy_notify);
-
- crtc_kms->cursor_renderer_private = cursor_renderer_private;
- crtc_kms->cursor_renderer_private_destroy_notify = destroy_notify;
-}
-
-static gboolean
-is_transform_handled (MetaCrtcKms *crtc_kms,
- MetaMonitorTransform transform)
-{
- if (!crtc_kms->primary_plane)
- return FALSE;
-
- return meta_kms_plane_is_transform_handled (crtc_kms->primary_plane,
- transform);
-}
-
-static gboolean
-meta_crtc_kms_is_transform_handled (MetaCrtcNative *crtc_native,
- MetaMonitorTransform transform)
-{
- MetaCrtcKms *crtc_kms = META_CRTC_KMS (crtc_native);
-
- return is_transform_handled (crtc_kms, transform);
-}
-
-void
-meta_crtc_kms_apply_transform (MetaCrtcKms *crtc_kms,
- MetaKmsPlaneAssignment *kms_plane_assignment)
-{
- MetaCrtc *crtc = META_CRTC (crtc_kms);
- const MetaCrtcConfig *crtc_config;
- MetaMonitorTransform hw_transform;
-
- crtc_config = meta_crtc_get_config (crtc);
-
- hw_transform = crtc_config->transform;
- if (!is_transform_handled (crtc_kms, hw_transform))
- hw_transform = META_MONITOR_TRANSFORM_NORMAL;
- if (!is_transform_handled (crtc_kms, hw_transform))
- return;
-
- meta_kms_plane_update_set_rotation (crtc_kms->primary_plane,
- kms_plane_assignment,
- hw_transform);
-}
-
-void
-meta_crtc_kms_assign_primary_plane (MetaCrtcKms *crtc_kms,
- MetaDrmBuffer *buffer,
- MetaKmsUpdate *kms_update)
-{
- MetaCrtc *crtc = META_CRTC (crtc_kms);
- const MetaCrtcConfig *crtc_config;
- const MetaCrtcModeInfo *crtc_mode_info;
- MetaFixed16Rectangle src_rect;
- MetaRectangle dst_rect;
- MetaKmsAssignPlaneFlag flags;
- MetaKmsCrtc *kms_crtc;
- MetaKmsDevice *kms_device;
- MetaKmsPlane *primary_kms_plane;
- MetaKmsPlaneAssignment *plane_assignment;
-
- crtc_config = meta_crtc_get_config (crtc);
- crtc_mode_info = meta_crtc_mode_get_info (crtc_config->mode);
-
- src_rect = (MetaFixed16Rectangle) {
- .x = meta_fixed_16_from_int (0),
- .y = meta_fixed_16_from_int (0),
- .width = meta_fixed_16_from_int (crtc_mode_info->width),
- .height = meta_fixed_16_from_int (crtc_mode_info->height),
- };
- dst_rect = (MetaRectangle) {
- .x = 0,
- .y = 0,
- .width = crtc_mode_info->width,
- .height = crtc_mode_info->height,
- };
-
- flags = META_KMS_ASSIGN_PLANE_FLAG_NONE;
-
- kms_crtc = meta_crtc_kms_get_kms_crtc (crtc_kms);
- kms_device = meta_kms_crtc_get_device (kms_crtc);
- primary_kms_plane = meta_kms_device_get_primary_plane_for (kms_device,
- kms_crtc);
- plane_assignment = meta_kms_update_assign_plane (kms_update,
- kms_crtc,
- primary_kms_plane,
- buffer,
- src_rect,
- dst_rect,
- flags);
- meta_crtc_kms_apply_transform (crtc_kms, plane_assignment);
-}
-
-static GList *
-generate_crtc_connector_list (MetaGpu *gpu,
- MetaCrtc *crtc)
-{
- GList *connectors = NULL;
- GList *l;
-
- for (l = meta_gpu_get_outputs (gpu); l; l = l->next)
- {
- MetaOutput *output = l->data;
- MetaCrtc *assigned_crtc;
-
- assigned_crtc = meta_output_get_assigned_crtc (output);
- if (assigned_crtc == crtc)
- {
- MetaKmsConnector *kms_connector =
- meta_output_kms_get_kms_connector (META_OUTPUT_KMS (output));
-
- connectors = g_list_prepend (connectors, kms_connector);
- }
- }
-
- return connectors;
-}
-
-void
-meta_crtc_kms_maybe_set_gamma (MetaCrtcKms *crtc_kms,
- MetaKmsDevice *kms_device)
-{
- MetaGpu *gpu = meta_crtc_get_gpu (META_CRTC (crtc_kms));
- MetaBackend *backend = meta_gpu_get_backend (gpu);
- MetaMonitorManager *monitor_manager =
- meta_backend_get_monitor_manager (backend);
- MetaMonitorManagerNative *monitor_manager_native =
- META_MONITOR_MANAGER_NATIVE (monitor_manager);
- MetaKms *kms = meta_kms_device_get_kms (kms_device);
- MetaKmsUpdate *kms_update;
- MetaKmsCrtcGamma *gamma;
-
- if (crtc_kms->is_gamma_valid)
- return;
-
- gamma = meta_monitor_manager_native_get_cached_crtc_gamma (monitor_manager_native,
- crtc_kms);
- if (!gamma)
- return;
-
- kms_update = meta_kms_ensure_pending_update (kms, kms_device);
- meta_kms_update_set_crtc_gamma (kms_update,
- meta_crtc_kms_get_kms_crtc (crtc_kms),
- gamma->size,
- gamma->red,
- gamma->green,
- gamma->blue);
-
- crtc_kms->is_gamma_valid = TRUE;
-}
-
-void
-meta_crtc_kms_set_mode (MetaCrtcKms *crtc_kms,
- MetaKmsUpdate *kms_update)
-{
- MetaCrtc *crtc = META_CRTC (crtc_kms);
- MetaGpu *gpu = meta_crtc_get_gpu (crtc);
- GList *connectors;
- MetaKmsMode *kms_mode;
-
- connectors = generate_crtc_connector_list (gpu, crtc);
-
- if (connectors)
- {
- const MetaCrtcConfig *crtc_config = meta_crtc_get_config (crtc);
- MetaCrtcModeKms *crtc_mode_kms = META_CRTC_MODE_KMS (crtc_config->mode);
-
- kms_mode = meta_crtc_mode_kms_get_kms_mode (crtc_mode_kms);
-
- meta_topic (META_DEBUG_KMS,
- "Setting CRTC (%" G_GUINT64_FORMAT ") mode to %s",
- meta_crtc_get_id (crtc), meta_kms_mode_get_name (kms_mode));
- }
- else
- {
- kms_mode = NULL;
-
- meta_topic (META_DEBUG_KMS,
- "Unsetting CRTC (%" G_GUINT64_FORMAT ") mode",
- meta_crtc_get_id (crtc));
- }
-
- meta_kms_update_mode_set (kms_update,
- meta_crtc_kms_get_kms_crtc (crtc_kms),
- g_steal_pointer (&connectors),
- kms_mode);
-}
-
-MetaKmsCrtc *
-meta_crtc_kms_get_kms_crtc (MetaCrtcKms *crtc_kms)
-{
- return crtc_kms->kms_crtc;
-}
-
-/**
- * meta_crtc_kms_get_modifiers:
- * @crtc_kms: a #MetaCrtc object that has to be a #MetaCrtcKms
- * @format: a DRM pixel format
- *
- * Returns a pointer to a #GArray containing all the supported
- * modifiers for the given DRM pixel format on the CRTC's primary
- * plane. The array element type is uint64_t.
- *
- * The caller must not modify or destroy the array or its contents.
- *
- * Returns NULL if the modifiers are not known or the format is not
- * supported.
- */
-GArray *
-meta_crtc_kms_get_modifiers (MetaCrtcKms *crtc_kms,
- uint32_t format)
-{
- return meta_kms_plane_get_modifiers_for_format (crtc_kms->primary_plane,
- format);
-}
-
-/**
- * meta_crtc_kms_copy_drm_format_list:
- * @crtc_kms: a #MetaCrtc object that has to be a #MetaCrtcKms
- *
- * Returns a new #GArray that the caller must destroy. The array
- * contains all the DRM pixel formats the CRTC supports on
- * its primary plane. The array element type is uint32_t.
- */
-GArray *
-meta_crtc_kms_copy_drm_format_list (MetaCrtcKms *crtc_kms)
-{
- return meta_kms_plane_copy_drm_format_list (crtc_kms->primary_plane);
-}
-
-/**
- * meta_crtc_kms_supports_format:
- * @crtc_kms: a #MetaCrtcKms
- * @drm_format: a DRM pixel format
- *
- * Returns true if the CRTC supports the format on its primary plane.
- */
-gboolean
-meta_crtc_kms_supports_format (MetaCrtcKms *crtc_kms,
- uint32_t drm_format)
-{
- return meta_kms_plane_is_format_supported (crtc_kms->primary_plane,
- drm_format);
-}
-
-void
-meta_crtc_kms_invalidate_gamma (MetaCrtcKms *crtc_kms)
-{
- crtc_kms->is_gamma_valid = FALSE;
-}
-
-MetaCrtcKms *
-meta_crtc_kms_from_kms_crtc (MetaKmsCrtc *kms_crtc)
-{
- return g_object_get_qdata (G_OBJECT (kms_crtc), kms_crtc_crtc_kms_quark);
-}
-
-MetaCrtcKms *
-meta_crtc_kms_new (MetaGpuKms *gpu_kms,
- MetaKmsCrtc *kms_crtc)
-{
- MetaGpu *gpu = META_GPU (gpu_kms);
- MetaKmsDevice *kms_device;
- MetaCrtcKms *crtc_kms;
- MetaKmsPlane *primary_plane;
-
- kms_device = meta_gpu_kms_get_kms_device (gpu_kms);
- primary_plane = meta_kms_device_get_primary_plane_for (kms_device,
- kms_crtc);
- crtc_kms = g_object_new (META_TYPE_CRTC_KMS,
- "id", (uint64_t) meta_kms_crtc_get_id (kms_crtc),
- "gpu", gpu,
- NULL);
-
- crtc_kms->kms_crtc = kms_crtc;
- crtc_kms->primary_plane = primary_plane;
-
- if (!kms_crtc_crtc_kms_quark)
- {
- kms_crtc_crtc_kms_quark =
- g_quark_from_static_string ("meta-kms-crtc-crtc-kms-quark");
- }
-
- g_object_set_qdata (G_OBJECT (kms_crtc), kms_crtc_crtc_kms_quark, crtc_kms);
-
- return crtc_kms;
-}
-
-static void
-meta_crtc_kms_dispose (GObject *object)
-{
- MetaCrtcKms *crtc_kms = META_CRTC_KMS (object);
-
- g_clear_pointer (&crtc_kms->cursor_renderer_private,
- crtc_kms->cursor_renderer_private_destroy_notify);
-
- G_OBJECT_CLASS (meta_crtc_kms_parent_class)->dispose (object);
-}
-
-static void
-meta_crtc_kms_init (MetaCrtcKms *crtc_kms)
-{
-}
-
-static void
-meta_crtc_kms_class_init (MetaCrtcKmsClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
- MetaCrtcNativeClass *crtc_native_class = META_CRTC_NATIVE_CLASS (klass);
-
- object_class->dispose = meta_crtc_kms_dispose;
-
- crtc_native_class->is_transform_handled = meta_crtc_kms_is_transform_handled;
-}
diff --git a/src/backends/native/meta-crtc-kms.h b/src/backends/native/meta-crtc-kms.h
deleted file mode 100644
index f8d241bbb..000000000
--- a/src/backends/native/meta-crtc-kms.h
+++ /dev/null
@@ -1,83 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2017 Red Hat
- * Copyright (C) 2018 DisplayLink (UK) Ltd.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-
-#ifndef META_CRTC_KMS_H
-#define META_CRTC_KMS_H
-
-#include <xf86drm.h>
-#include <xf86drmMode.h>
-
-#include "backends/meta-backend-types.h"
-#include "backends/meta-crtc.h"
-#include "backends/native/meta-crtc-native.h"
-#include "backends/native/meta-drm-buffer.h"
-#include "backends/native/meta-gpu-kms.h"
-#include "backends/native/meta-kms-crtc.h"
-#include "backends/native/meta-kms-update.h"
-
-#define META_TYPE_CRTC_KMS (meta_crtc_kms_get_type ())
-G_DECLARE_FINAL_TYPE (MetaCrtcKms, meta_crtc_kms,
- META, CRTC_KMS,
- MetaCrtcNative)
-
-gpointer meta_crtc_kms_get_cursor_renderer_private (MetaCrtcKms *crtc_kms);
-
-void meta_crtc_kms_set_cursor_renderer_private (MetaCrtcKms *crtc_kms,
- gpointer cursor_renderer_private,
- GDestroyNotify destroy_notify);
-
-void meta_crtc_kms_apply_transform (MetaCrtcKms *crtc_kms,
- MetaKmsPlaneAssignment *kms_plane_assignment);
-
-void meta_crtc_kms_assign_primary_plane (MetaCrtcKms *crtc_kms,
- MetaDrmBuffer *buffer,
- MetaKmsUpdate *kms_update);
-
-void meta_crtc_kms_set_mode (MetaCrtcKms *crtc_kms,
- MetaKmsUpdate *kms_update);
-
-void meta_crtc_kms_set_is_underscanning (MetaCrtcKms *crtc_kms,
- gboolean is_underscanning);
-
-MetaKmsCrtc * meta_crtc_kms_get_kms_crtc (MetaCrtcKms *crtc_kms);
-
-GArray * meta_crtc_kms_get_modifiers (MetaCrtcKms *crtc_kms,
- uint32_t format);
-
-GArray *
-meta_crtc_kms_copy_drm_format_list (MetaCrtcKms *crtc_kms);
-
-gboolean
-meta_crtc_kms_supports_format (MetaCrtcKms *crtc_kms,
- uint32_t drm_format);
-
-void meta_crtc_kms_invalidate_gamma (MetaCrtcKms *crtc_kms);
-
-void meta_crtc_kms_maybe_set_gamma (MetaCrtcKms *crtc_kms,
- MetaKmsDevice *kms_device);
-
-MetaCrtcKms * meta_crtc_kms_from_kms_crtc (MetaKmsCrtc *kms_crtc);
-
-MetaCrtcKms * meta_crtc_kms_new (MetaGpuKms *gpu_kms,
- MetaKmsCrtc *kms_crtc);
-
-#endif /* META_CRTC_KMS_H */
diff --git a/src/backends/native/meta-crtc-mode-kms.c b/src/backends/native/meta-crtc-mode-kms.c
deleted file mode 100644
index 053367cfd..000000000
--- a/src/backends/native/meta-crtc-mode-kms.c
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * Copyright (C) 2017-2020 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-
-#include "config.h"
-
-#include "backends/native/meta-crtc-mode-kms.h"
-
-#include "backends/native/meta-kms-mode.h"
-#include "backends/native/meta-kms-utils.h"
-
-struct _MetaCrtcModeKms
-{
- MetaCrtcMode parent;
-
- MetaKmsMode *kms_mode;
-};
-
-G_DEFINE_TYPE (MetaCrtcModeKms, meta_crtc_mode_kms,
- META_TYPE_CRTC_MODE)
-
-MetaKmsMode *
-meta_crtc_mode_kms_get_kms_mode (MetaCrtcModeKms *mode_kms)
-{
- return mode_kms->kms_mode;
-}
-
-MetaCrtcModeKms *
-meta_crtc_mode_kms_new (MetaKmsMode *kms_mode,
- uint64_t id)
-{
- const drmModeModeInfo *drm_mode = meta_kms_mode_get_drm_mode (kms_mode);
- g_autoptr (MetaCrtcModeInfo) crtc_mode_info = NULL;
- g_autofree char *crtc_mode_name = NULL;
- MetaCrtcModeKms *mode_kms;
-
- crtc_mode_info = meta_crtc_mode_info_new ();
- crtc_mode_info->width = drm_mode->hdisplay;
- crtc_mode_info->height = drm_mode->vdisplay;
- crtc_mode_info->flags = drm_mode->flags;
- crtc_mode_info->refresh_rate =
- meta_calculate_drm_mode_refresh_rate (drm_mode);
- crtc_mode_info->vblank_duration_us =
- meta_calculate_drm_mode_vblank_duration_us (drm_mode);
-
- crtc_mode_name = g_strndup (drm_mode->name, DRM_DISPLAY_MODE_LEN);
- mode_kms = g_object_new (META_TYPE_CRTC_MODE_KMS,
- "id", id,
- "name", crtc_mode_name,
- "info", crtc_mode_info,
- NULL);
-
- mode_kms->kms_mode = kms_mode;
-
- return mode_kms;
-}
-
-static void
-meta_crtc_mode_kms_init (MetaCrtcModeKms *mode_kms)
-{
-}
-
-static void
-meta_crtc_mode_kms_class_init (MetaCrtcModeKmsClass *klass)
-{
-}
diff --git a/src/backends/native/meta-crtc-mode-kms.h b/src/backends/native/meta-crtc-mode-kms.h
deleted file mode 100644
index f39268612..000000000
--- a/src/backends/native/meta-crtc-mode-kms.h
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Copyright (C) 2017-2020 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-
-#ifndef META_CRTC_MODE_KMS_H
-#define META_CRTC_MODE_KMS_H
-
-#include <xf86drm.h>
-#include <xf86drmMode.h>
-
-#include "backends/meta-crtc-mode.h"
-#include "backends/native/meta-kms-types.h"
-
-#define META_TYPE_CRTC_MODE_KMS (meta_crtc_mode_kms_get_type ())
-G_DECLARE_FINAL_TYPE (MetaCrtcModeKms, meta_crtc_mode_kms,
- META, CRTC_MODE_KMS,
- MetaCrtcMode)
-
-MetaKmsMode * meta_crtc_mode_kms_get_kms_mode (MetaCrtcModeKms *mode_kms);
-
-MetaCrtcModeKms * meta_crtc_mode_kms_new (MetaKmsMode *kms_mode,
- uint64_t id);
-
-#endif /* META_CRTC_MODE_KMS_H */
diff --git a/src/backends/native/meta-crtc-mode-virtual.c b/src/backends/native/meta-crtc-mode-virtual.c
deleted file mode 100644
index 3bb883049..000000000
--- a/src/backends/native/meta-crtc-mode-virtual.c
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Copyright (C) 2021 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-
-#include "config.h"
-
-#include "backends/native/meta-crtc-mode-virtual.h"
-
-#include "backends/meta-virtual-monitor.h"
-
-struct _MetaCrtcModeVirtual
-{
- MetaCrtcMode parent;
-};
-
-#define META_CRTC_MODE_VIRTUAL_ID_BIT (((uint64_t) 1) << 63)
-
-G_DEFINE_TYPE (MetaCrtcModeVirtual, meta_crtc_mode_virtual,
- META_TYPE_CRTC_MODE)
-
-MetaCrtcModeVirtual *
-meta_crtc_mode_virtual_new (uint64_t id,
- const MetaVirtualMonitorInfo *info)
-{
- g_autoptr (MetaCrtcModeInfo) crtc_mode_info = NULL;
- g_autofree char *crtc_mode_name = NULL;
- MetaCrtcModeVirtual *mode_virtual;
-
- crtc_mode_info = meta_crtc_mode_info_new ();
- crtc_mode_info->width = info->width;
- crtc_mode_info->height = info->height;
- crtc_mode_info->refresh_rate = info->refresh_rate;
-
- crtc_mode_name = g_strdup_printf ("%dx%d@%f",
- info->width,
- info->height,
- info->refresh_rate);
- mode_virtual = g_object_new (META_TYPE_CRTC_MODE_VIRTUAL,
- "id", META_CRTC_MODE_VIRTUAL_ID_BIT | id,
- "name", crtc_mode_name,
- "info", crtc_mode_info,
- NULL);
-
- return mode_virtual;
-}
-
-static void
-meta_crtc_mode_virtual_init (MetaCrtcModeVirtual *mode_virtual)
-{
-}
-
-static void
-meta_crtc_mode_virtual_class_init (MetaCrtcModeVirtualClass *klass)
-{
-}
diff --git a/src/backends/native/meta-crtc-mode-virtual.h b/src/backends/native/meta-crtc-mode-virtual.h
deleted file mode 100644
index e3ddb289c..000000000
--- a/src/backends/native/meta-crtc-mode-virtual.h
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright (C) 2021 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-
-#ifndef META_CRTC_MODE_VIRTUAL_H
-#define META_CRTC_MODE_VIRTUAL_H
-
-#include "backends/meta-backend-types.h"
-#include "backends/meta-crtc-mode.h"
-
-#define META_TYPE_CRTC_MODE_VIRTUAL (meta_crtc_mode_virtual_get_type ())
-G_DECLARE_FINAL_TYPE (MetaCrtcModeVirtual, meta_crtc_mode_virtual,
- META, CRTC_MODE_VIRTUAL,
- MetaCrtcMode)
-
-MetaCrtcModeVirtual * meta_crtc_mode_virtual_new (uint64_t id,
- const MetaVirtualMonitorInfo *info);
-
-#endif /* META_CRTC_MODE_VIRTUAL_H */
diff --git a/src/backends/native/meta-crtc-native.c b/src/backends/native/meta-crtc-native.c
deleted file mode 100644
index 5e5751780..000000000
--- a/src/backends/native/meta-crtc-native.c
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Copyright (C) 2021 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-
-#include "config.h"
-
-#include "backends/native/meta-crtc-native.h"
-
-G_DEFINE_ABSTRACT_TYPE (MetaCrtcNative, meta_crtc_native,
- META_TYPE_CRTC)
-
-gboolean
-meta_crtc_native_is_transform_handled (MetaCrtcNative *crtc_native,
- MetaMonitorTransform transform)
-{
- MetaCrtcNativeClass *klass = META_CRTC_NATIVE_GET_CLASS (crtc_native);
-
- return klass->is_transform_handled (crtc_native, transform);
-}
-
-static void
-meta_crtc_native_init (MetaCrtcNative *crtc_native)
-{
-}
-
-static void
-meta_crtc_native_class_init (MetaCrtcNativeClass *klass)
-{
-}
diff --git a/src/backends/native/meta-crtc-native.h b/src/backends/native/meta-crtc-native.h
deleted file mode 100644
index 0c16e5895..000000000
--- a/src/backends/native/meta-crtc-native.h
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright (C) 2021 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-
-#ifndef META_CRTC_NATIVE_H
-#define META_CRTC_NATIVE_H
-
-#include "backends/meta-crtc.h"
-
-#define META_TYPE_CRTC_NATIVE (meta_crtc_native_get_type ())
-G_DECLARE_DERIVABLE_TYPE (MetaCrtcNative, meta_crtc_native,
- META, CRTC_NATIVE,
- MetaCrtc)
-
-struct _MetaCrtcNativeClass
-{
- MetaCrtcClass parent_class;
-
- gboolean (* is_transform_handled) (MetaCrtcNative *crtc_native,
- MetaMonitorTransform monitor_transform);
-};
-
-gboolean meta_crtc_native_is_transform_handled (MetaCrtcNative *crtc_native,
- MetaMonitorTransform transform);
-
-#endif /* META_CRTC_NATIVE_H */
diff --git a/src/backends/native/meta-crtc-virtual.c b/src/backends/native/meta-crtc-virtual.c
deleted file mode 100644
index eee346a23..000000000
--- a/src/backends/native/meta-crtc-virtual.c
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Copyright (C) 2021 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-
-#include "config.h"
-
-#include "backends/native/meta-crtc-virtual.h"
-
-struct _MetaCrtcVirtual
-{
- MetaCrtcNative parent;
-};
-
-#define META_CRTC_VIRTUAL_ID_BIT (((uint64_t) 1) << 63)
-
-G_DEFINE_TYPE (MetaCrtcVirtual, meta_crtc_virtual, META_TYPE_CRTC_NATIVE)
-
-MetaCrtcVirtual *
-meta_crtc_virtual_new (uint64_t id)
-{
- return g_object_new (META_TYPE_CRTC_VIRTUAL,
- "id", META_CRTC_VIRTUAL_ID_BIT | id,
- NULL);
-}
-
-static gboolean
-meta_crtc_virtual_is_transform_handled (MetaCrtcNative *crtc_native,
- MetaMonitorTransform transform)
-{
- return transform == META_MONITOR_TRANSFORM_NORMAL;
-}
-
-static void
-meta_crtc_virtual_init (MetaCrtcVirtual *crtc_virtual)
-{
-}
-
-static void
-meta_crtc_virtual_class_init (MetaCrtcVirtualClass *klass)
-{
- MetaCrtcNativeClass *crtc_native_class = META_CRTC_NATIVE_CLASS (klass);
-
- crtc_native_class->is_transform_handled =
- meta_crtc_virtual_is_transform_handled;
-}
diff --git a/src/backends/native/meta-crtc-virtual.h b/src/backends/native/meta-crtc-virtual.h
deleted file mode 100644
index 89b1bcc7a..000000000
--- a/src/backends/native/meta-crtc-virtual.h
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Copyright (C) 2021 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-
-#ifndef META_CRTC_VIRTUAL_H
-#define META_CRTC_VIRTUAL_H
-
-#include "backends/native/meta-crtc-native.h"
-
-#define META_TYPE_CRTC_VIRTUAL (meta_crtc_virtual_get_type ())
-G_DECLARE_FINAL_TYPE (MetaCrtcVirtual, meta_crtc_virtual,
- META, CRTC_VIRTUAL,
- MetaCrtcNative)
-
-MetaCrtcVirtual * meta_crtc_virtual_new (uint64_t id);
-
-#endif /* META_CRTC_VIRTUAL_H */
diff --git a/src/backends/native/meta-cursor-renderer-native.c b/src/backends/native/meta-cursor-renderer-native.c
deleted file mode 100644
index effa0851d..000000000
--- a/src/backends/native/meta-cursor-renderer-native.c
+++ /dev/null
@@ -1,1878 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2014 Red Hat
- * Copyright 2020 DisplayLink (UK) Ltd.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Written by:
- * Jasper St. Pierre <jstpierre@mecheye.net>
- */
-
-#include "config.h"
-
-#include "backends/native/meta-cursor-renderer-native.h"
-
-#include <string.h>
-#include <gbm.h>
-#include <xf86drm.h>
-#include <errno.h>
-
-#include "backends/meta-backend-private.h"
-#include "backends/meta-cursor-sprite-xcursor.h"
-#include "backends/meta-logical-monitor.h"
-#include "backends/meta-monitor.h"
-#include "backends/meta-monitor-manager-private.h"
-#include "backends/meta-output.h"
-#include "backends/native/meta-backend-native-private.h"
-#include "backends/native/meta-crtc-kms.h"
-#include "backends/native/meta-device-pool.h"
-#include "backends/native/meta-drm-buffer-gbm.h"
-#include "backends/native/meta-kms-device.h"
-#include "backends/native/meta-kms-plane.h"
-#include "backends/native/meta-kms-update.h"
-#include "backends/native/meta-kms.h"
-#include "backends/native/meta-renderer-native.h"
-#include "core/boxes-private.h"
-#include "meta/boxes.h"
-#include "meta/meta-backend.h"
-#include "meta/util.h"
-
-#ifdef HAVE_WAYLAND
-#include "wayland/meta-cursor-sprite-wayland.h"
-#include "wayland/meta-wayland-buffer.h"
-#endif
-
-#ifndef DRM_CAP_CURSOR_WIDTH
-#define DRM_CAP_CURSOR_WIDTH 0x8
-#endif
-#ifndef DRM_CAP_CURSOR_HEIGHT
-#define DRM_CAP_CURSOR_HEIGHT 0x9
-#endif
-
-/* When animating a cursor, we usually call drmModeSetCursor2 once per frame.
- * Though, testing shows that we need to triple buffer the cursor buffer in
- * order to avoid glitches when animating the cursor, at least when running on
- * Intel. The reason for this might be (but is not confirmed to be) due to
- * the user space gbm_bo cache, making us reuse and overwrite the kernel side
- * buffer content before it was scanned out. To avoid this, we keep a user space
- * reference to each buffer we set until at least one frame after it was drawn.
- * In effect, this means we three active cursor gbm_bo's: one that that just has
- * been set, one that was previously set and may or may not have been scanned
- * out, and one pending that will be replaced if the cursor sprite changes.
- */
-#define HW_CURSOR_BUFFER_COUNT 3
-
-static GQuark quark_cursor_sprite = 0;
-
-typedef struct _CrtcCursorData
-{
- MetaDrmBuffer *buffer;
- gboolean needs_sync_position;
- gboolean hw_state_invalidated;
-} CrtcCursorData;
-
-struct _MetaCursorRendererNative
-{
- MetaCursorRenderer parent;
-};
-
-struct _MetaCursorRendererNativePrivate
-{
- MetaBackend *backend;
-
- gboolean has_hw_cursor;
-
- MetaCursorSprite *last_cursor;
- guint animation_timeout_id;
-};
-typedef struct _MetaCursorRendererNativePrivate MetaCursorRendererNativePrivate;
-
-typedef struct _MetaCursorRendererNativeGpuData
-{
- gboolean hw_cursor_broken;
-
- uint64_t cursor_width;
- uint64_t cursor_height;
-} MetaCursorRendererNativeGpuData;
-
-typedef enum _MetaCursorBufferState
-{
- META_CURSOR_BUFFER_STATE_NONE,
- META_CURSOR_BUFFER_STATE_SET,
- META_CURSOR_BUFFER_STATE_INVALIDATED,
-} MetaCursorBufferState;
-
-typedef struct _MetaCursorNativeGpuState
-{
- MetaGpu *gpu;
- unsigned int active_buffer_idx;
- MetaCursorBufferState pending_buffer_state;
- MetaDrmBuffer *buffers[HW_CURSOR_BUFFER_COUNT];
-} MetaCursorNativeGpuState;
-
-typedef struct _MetaCursorNativePrivate
-{
- GHashTable *gpu_states;
-
- struct {
- gboolean can_preprocess;
- float current_relative_scale;
- MetaMonitorTransform current_relative_transform;
- } preprocess_state;
-} MetaCursorNativePrivate;
-
-static GQuark quark_cursor_renderer_native_gpu_data = 0;
-
-G_DEFINE_TYPE_WITH_PRIVATE (MetaCursorRendererNative, meta_cursor_renderer_native, META_TYPE_CURSOR_RENDERER);
-
-static void
-on_kms_update_result (const MetaKmsFeedback *kms_feedback,
- gpointer user_data);
-
-static void
-realize_cursor_sprite (MetaCursorRenderer *renderer,
- MetaCursorSprite *cursor_sprite,
- GList *gpus);
-
-static MetaCursorNativeGpuState *
-get_cursor_gpu_state (MetaCursorNativePrivate *cursor_priv,
- MetaGpuKms *gpu_kms);
-
-static MetaCursorNativeGpuState *
-ensure_cursor_gpu_state (MetaCursorNativePrivate *cursor_priv,
- MetaGpuKms *gpu_kms);
-
-static void
-invalidate_cursor_gpu_state (MetaCursorSprite *cursor_sprite);
-
-static MetaCursorNativePrivate *
-ensure_cursor_priv (MetaCursorSprite *cursor_sprite);
-
-static MetaCursorNativePrivate *
-get_cursor_priv (MetaCursorSprite *cursor_sprite);
-
-static MetaCursorRendererNativeGpuData *
-meta_cursor_renderer_native_gpu_data_from_gpu (MetaGpuKms *gpu_kms)
-{
- return g_object_get_qdata (G_OBJECT (gpu_kms),
- quark_cursor_renderer_native_gpu_data);
-}
-
-static MetaCursorRendererNativeGpuData *
-meta_create_cursor_renderer_native_gpu_data (MetaGpuKms *gpu_kms)
-{
- MetaCursorRendererNativeGpuData *cursor_renderer_gpu_data;
-
- cursor_renderer_gpu_data = g_new0 (MetaCursorRendererNativeGpuData, 1);
- g_object_set_qdata_full (G_OBJECT (gpu_kms),
- quark_cursor_renderer_native_gpu_data,
- cursor_renderer_gpu_data,
- g_free);
-
- return cursor_renderer_gpu_data;
-}
-
-static void
-meta_cursor_renderer_native_finalize (GObject *object)
-{
- MetaCursorRendererNative *renderer = META_CURSOR_RENDERER_NATIVE (object);
- MetaCursorRendererNativePrivate *priv =
- meta_cursor_renderer_native_get_instance_private (renderer);
-
- g_clear_handle_id (&priv->animation_timeout_id, g_source_remove);
-
- G_OBJECT_CLASS (meta_cursor_renderer_native_parent_class)->finalize (object);
-}
-
-static unsigned int
-get_pending_cursor_sprite_buffer_index (MetaCursorNativeGpuState *cursor_gpu_state)
-{
- return (cursor_gpu_state->active_buffer_idx + 1) % HW_CURSOR_BUFFER_COUNT;
-}
-
-static MetaDrmBuffer *
-get_pending_cursor_sprite_buffer (MetaCursorNativeGpuState *cursor_gpu_state)
-{
- unsigned int pending_buffer_idx;
-
- pending_buffer_idx =
- get_pending_cursor_sprite_buffer_index (cursor_gpu_state);
- return cursor_gpu_state->buffers[pending_buffer_idx];
-}
-
-static MetaDrmBuffer *
-get_active_cursor_sprite_buffer (MetaCursorNativeGpuState *cursor_gpu_state)
-{
- return cursor_gpu_state->buffers[cursor_gpu_state->active_buffer_idx];
-}
-
-static void
-set_pending_cursor_sprite_buffer (MetaCursorSprite *cursor_sprite,
- MetaGpuKms *gpu_kms,
- MetaDrmBuffer *buffer)
-{
- MetaCursorNativePrivate *cursor_priv;
- MetaCursorNativeGpuState *cursor_gpu_state;
- unsigned int pending_buffer_idx;
-
- cursor_priv = ensure_cursor_priv (cursor_sprite);
- cursor_gpu_state = ensure_cursor_gpu_state (cursor_priv, gpu_kms);
-
- pending_buffer_idx =
- get_pending_cursor_sprite_buffer_index (cursor_gpu_state);
- cursor_gpu_state->buffers[pending_buffer_idx] = buffer;
- cursor_gpu_state->pending_buffer_state = META_CURSOR_BUFFER_STATE_SET;
-}
-
-static void
-calculate_crtc_cursor_hotspot (MetaCursorSprite *cursor_sprite,
- int *cursor_hotspot_x,
- int *cursor_hotspot_y)
-{
- MetaCursorNativePrivate *cursor_priv = get_cursor_priv (cursor_sprite);
- int hot_x, hot_y;
- int width, height;
- float scale;
- MetaMonitorTransform transform;
-
- scale = cursor_priv->preprocess_state.current_relative_scale;
- transform = cursor_priv->preprocess_state.current_relative_transform;
-
- meta_cursor_sprite_get_hotspot (cursor_sprite, &hot_x, &hot_y);
- width = meta_cursor_sprite_get_width (cursor_sprite);
- height = meta_cursor_sprite_get_height (cursor_sprite);
- meta_monitor_transform_transform_point (transform,
- width, height,
- hot_x, hot_y,
- &hot_x, &hot_y);
- *cursor_hotspot_x = (int) roundf (hot_x * scale);
- *cursor_hotspot_y = (int) roundf (hot_y * scale);
-}
-
-static CrtcCursorData *
-ensure_crtc_cursor_data (MetaCrtcKms *crtc_kms)
-{
- CrtcCursorData *crtc_cursor_data;
-
- crtc_cursor_data = meta_crtc_kms_get_cursor_renderer_private (crtc_kms);
- if (!crtc_cursor_data)
- {
- crtc_cursor_data = g_new0 (CrtcCursorData, 1);
- crtc_cursor_data->hw_state_invalidated = TRUE;
- meta_crtc_kms_set_cursor_renderer_private (crtc_kms,
- crtc_cursor_data,
- g_free);
- }
-
- return crtc_cursor_data;
-}
-
-static void
-assign_cursor_plane (MetaCursorRendererNative *native,
- MetaCrtcKms *crtc_kms,
- int x,
- int y,
- MetaCursorSprite *cursor_sprite)
-{
- MetaCrtc *crtc = META_CRTC (crtc_kms);
- MetaCursorNativePrivate *cursor_priv = get_cursor_priv (cursor_sprite);
- MetaGpuKms *gpu_kms = META_GPU_KMS (meta_crtc_get_gpu (crtc));
- MetaCursorRendererNativeGpuData *cursor_renderer_gpu_data =
- meta_cursor_renderer_native_gpu_data_from_gpu (gpu_kms);
- MetaCursorNativeGpuState *cursor_gpu_state =
- get_cursor_gpu_state (cursor_priv, gpu_kms);
- MetaKmsCrtc *kms_crtc;
- MetaKmsDevice *kms_device;
- MetaKmsPlane *cursor_plane;
- MetaDrmBuffer *buffer;
- int cursor_width, cursor_height;
- MetaFixed16Rectangle src_rect;
- MetaRectangle dst_rect;
- MetaDrmBuffer *crtc_buffer;
- MetaKmsAssignPlaneFlag flags;
- CrtcCursorData *crtc_cursor_data;
- int cursor_hotspot_x;
- int cursor_hotspot_y;
- MetaKmsUpdate *kms_update;
- MetaKmsPlaneAssignment *plane_assignment;
-
- if (cursor_gpu_state->pending_buffer_state == META_CURSOR_BUFFER_STATE_SET)
- buffer = get_pending_cursor_sprite_buffer (cursor_gpu_state);
- else
- buffer = get_active_cursor_sprite_buffer (cursor_gpu_state);
-
- kms_crtc = meta_crtc_kms_get_kms_crtc (crtc_kms);
- kms_device = meta_kms_crtc_get_device (kms_crtc);
- cursor_plane = meta_kms_device_get_cursor_plane_for (kms_device, kms_crtc);
- g_return_if_fail (cursor_plane);
-
- cursor_width = cursor_renderer_gpu_data->cursor_width;
- cursor_height = cursor_renderer_gpu_data->cursor_height;
- src_rect = (MetaFixed16Rectangle) {
- .x = meta_fixed_16_from_int (0),
- .y = meta_fixed_16_from_int (0),
- .width = meta_fixed_16_from_int (cursor_width),
- .height = meta_fixed_16_from_int (cursor_height),
- };
- dst_rect = (MetaRectangle) {
- .x = x,
- .y = y,
- .width = cursor_width,
- .height = cursor_height,
- };
-
- flags = META_KMS_ASSIGN_PLANE_FLAG_ALLOW_FAIL;
- crtc_cursor_data = ensure_crtc_cursor_data (crtc_kms);
- crtc_buffer = crtc_cursor_data->buffer;
- if (!crtc_cursor_data->hw_state_invalidated && buffer == crtc_buffer)
- flags |= META_KMS_ASSIGN_PLANE_FLAG_FB_UNCHANGED;
-
- kms_update =
- meta_kms_ensure_pending_update (meta_kms_device_get_kms (kms_device),
- meta_kms_crtc_get_device (kms_crtc));
- plane_assignment = meta_kms_update_assign_plane (kms_update,
- kms_crtc,
- cursor_plane,
- buffer,
- src_rect,
- dst_rect,
- flags);
-
- calculate_crtc_cursor_hotspot (cursor_sprite,
- &cursor_hotspot_x,
- &cursor_hotspot_y);
- meta_kms_plane_assignment_set_cursor_hotspot (plane_assignment,
- cursor_hotspot_x,
- cursor_hotspot_y);
-
- meta_kms_update_add_result_listener (kms_update,
- on_kms_update_result,
- native);
-
- crtc_cursor_data->buffer = buffer;
-
- if (cursor_gpu_state->pending_buffer_state == META_CURSOR_BUFFER_STATE_SET)
- {
- cursor_gpu_state->active_buffer_idx =
- (cursor_gpu_state->active_buffer_idx + 1) % HW_CURSOR_BUFFER_COUNT;
- cursor_gpu_state->pending_buffer_state = META_CURSOR_BUFFER_STATE_NONE;
- }
-}
-
-static float
-calculate_cursor_crtc_sprite_scale (MetaCursorSprite *cursor_sprite,
- MetaLogicalMonitor *logical_monitor)
-{
- if (meta_is_stage_views_scaled ())
- {
- return (meta_logical_monitor_get_scale (logical_monitor) *
- meta_cursor_sprite_get_texture_scale (cursor_sprite));
- }
- else
- {
- return 1.0;
- }
-}
-
-static void
-set_crtc_cursor (MetaCursorRendererNative *cursor_renderer_native,
- MetaRendererView *view,
- MetaCrtc *crtc,
- MetaCursorSprite *cursor_sprite)
-{
- MetaCursorRenderer *cursor_renderer =
- META_CURSOR_RENDERER (cursor_renderer_native);
- MetaOutput *output = meta_crtc_get_outputs (crtc)->data;
- MetaMonitor *monitor = meta_output_get_monitor (output);
- MetaLogicalMonitor *logical_monitor =
- meta_monitor_get_logical_monitor (monitor);
- const MetaCrtcConfig *crtc_config = meta_crtc_get_config (crtc);
- graphene_rect_t rect;
- graphene_rect_t local_crtc_rect;
- graphene_rect_t local_cursor_rect;
- float view_scale;
- float crtc_cursor_x, crtc_cursor_y;
- CoglTexture *texture;
- int tex_width, tex_height;
- float cursor_crtc_scale;
- MetaRectangle cursor_rect;
- MetaMonitorTransform transform;
- MetaMonitorTransform inverted_transform;
- MetaMonitorMode *monitor_mode;
- MetaMonitorCrtcMode *monitor_crtc_mode;
- const MetaCrtcModeInfo *crtc_mode_info;
-
- view_scale = clutter_stage_view_get_scale (CLUTTER_STAGE_VIEW (view));
-
- rect = meta_cursor_renderer_calculate_rect (cursor_renderer, cursor_sprite);
- local_cursor_rect =
- GRAPHENE_RECT_INIT (rect.origin.x - logical_monitor->rect.x,
- rect.origin.y - logical_monitor->rect.y,
- rect.size.width,
- rect.size.height);
-
- local_crtc_rect = crtc_config->layout;
- graphene_rect_offset (&local_crtc_rect,
- -logical_monitor->rect.x,
- -logical_monitor->rect.y);
-
- crtc_cursor_x = (local_cursor_rect.origin.x -
- local_crtc_rect.origin.x) * view_scale;
- crtc_cursor_y = (local_cursor_rect.origin.y -
- local_crtc_rect.origin.y) * view_scale;
-
- texture = meta_cursor_sprite_get_cogl_texture (cursor_sprite);
- tex_width = cogl_texture_get_width (texture);
- tex_height = cogl_texture_get_height (texture);
-
- cursor_crtc_scale =
- calculate_cursor_crtc_sprite_scale (cursor_sprite,
- logical_monitor);
-
- cursor_rect = (MetaRectangle) {
- .x = floorf (crtc_cursor_x),
- .y = floorf (crtc_cursor_y),
- .width = roundf (tex_width * cursor_crtc_scale),
- .height = roundf (tex_height * cursor_crtc_scale)
- };
-
- transform = meta_logical_monitor_get_transform (logical_monitor);
- transform = meta_monitor_logical_to_crtc_transform (monitor, transform);
-
- inverted_transform = meta_monitor_transform_invert (transform);
-
- monitor_mode = meta_monitor_get_current_mode (monitor);
- monitor_crtc_mode = meta_monitor_get_crtc_mode_for_output (monitor,
- monitor_mode,
- output);
- crtc_mode_info = meta_crtc_mode_get_info (monitor_crtc_mode->crtc_mode);
- meta_rectangle_transform (&cursor_rect,
- inverted_transform,
- crtc_mode_info->width,
- crtc_mode_info->height,
- &cursor_rect);
-
- assign_cursor_plane (cursor_renderer_native,
- META_CRTC_KMS (crtc),
- cursor_rect.x,
- cursor_rect.y,
- cursor_sprite);
-}
-
-static void
-unset_crtc_cursor (MetaCursorRendererNative *native,
- MetaCrtc *crtc)
-{
- MetaCrtcKms *crtc_kms = META_CRTC_KMS (crtc);
- CrtcCursorData *crtc_cursor_data;
- MetaKmsCrtc *kms_crtc;
- MetaKmsDevice *kms_device;
- MetaKmsPlane *cursor_plane;
- MetaDrmBuffer *crtc_buffer;
-
- crtc_cursor_data = ensure_crtc_cursor_data (crtc_kms);
- crtc_buffer = crtc_cursor_data->buffer;
- if (!crtc_cursor_data->hw_state_invalidated && !crtc_buffer)
- return;
-
- kms_crtc = meta_crtc_kms_get_kms_crtc (crtc_kms);
- kms_device = meta_kms_crtc_get_device (kms_crtc);
- cursor_plane = meta_kms_device_get_cursor_plane_for (kms_device, kms_crtc);
-
- if (cursor_plane)
- {
- MetaKms *kms = meta_kms_device_get_kms (kms_device);
- MetaKmsUpdate *kms_update;
-
- kms_update = meta_kms_ensure_pending_update (kms, kms_device);
- meta_kms_update_unassign_plane (kms_update, kms_crtc, cursor_plane);
- }
-
- crtc_cursor_data->buffer = NULL;
-}
-
-static void
-disable_hw_cursor_for_crtc (MetaKmsCrtc *kms_crtc,
- const GError *error)
-{
- MetaCrtcKms *crtc_kms = meta_crtc_kms_from_kms_crtc (kms_crtc);
- MetaCrtc *crtc = META_CRTC (crtc_kms);
- MetaGpuKms *gpu_kms = META_GPU_KMS (meta_crtc_get_gpu (crtc));
- MetaCursorRendererNativeGpuData *cursor_renderer_gpu_data =
- meta_cursor_renderer_native_gpu_data_from_gpu (gpu_kms);
-
- g_warning ("Failed to set hardware cursor (%s), "
- "using OpenGL from now on",
- error->message);
- cursor_renderer_gpu_data->hw_cursor_broken = TRUE;
-}
-
-void
-meta_cursor_renderer_native_prepare_frame (MetaCursorRendererNative *cursor_renderer_native,
- MetaRendererView *view)
-{
- MetaCursorRenderer *cursor_renderer =
- META_CURSOR_RENDERER (cursor_renderer_native);
- MetaCursorRendererNativePrivate *priv =
- meta_cursor_renderer_native_get_instance_private (cursor_renderer_native);
- MetaBackend *backend = priv->backend;
- MetaMonitorManager *monitor_manager =
- meta_backend_get_monitor_manager (backend);
- MetaCrtc *crtc = meta_renderer_view_get_crtc (view);
- MetaCursorSprite *cursor_sprite;
- graphene_rect_t cursor_rect;
- cairo_rectangle_int_t view_layout;
- graphene_rect_t view_rect;
- CrtcCursorData *crtc_cursor_data;
-
- if (meta_monitor_manager_get_power_save_mode (monitor_manager) !=
- META_POWER_SAVE_ON)
- return;
-
- if (!meta_crtc_get_gpu (crtc))
- return;
-
- crtc_cursor_data = ensure_crtc_cursor_data (META_CRTC_KMS (crtc));
- if (!crtc_cursor_data->hw_state_invalidated &&
- !crtc_cursor_data->needs_sync_position)
- return;
-
- cursor_sprite = meta_cursor_renderer_get_cursor (cursor_renderer);
- if (!cursor_sprite)
- goto unset_cursor;
-
- if (!priv->has_hw_cursor)
- goto unset_cursor;
-
- cursor_rect = meta_cursor_renderer_calculate_rect (cursor_renderer,
- cursor_sprite);
- clutter_stage_view_get_layout (CLUTTER_STAGE_VIEW (view), &view_layout);
- view_rect = GRAPHENE_RECT_INIT (view_layout.x, view_layout.y,
- view_layout.width, view_layout.height);
- if (!graphene_rect_intersection (&cursor_rect, &view_rect, NULL))
- goto unset_cursor;
-
- set_crtc_cursor (cursor_renderer_native, view, crtc, cursor_sprite);
-
- meta_cursor_renderer_emit_painted (cursor_renderer,
- cursor_sprite,
- CLUTTER_STAGE_VIEW (view));
-
- crtc_cursor_data->needs_sync_position = FALSE;
- crtc_cursor_data->hw_state_invalidated = FALSE;
- return;
-
-unset_cursor:
- unset_crtc_cursor (cursor_renderer_native, crtc);
-
- crtc_cursor_data = ensure_crtc_cursor_data (META_CRTC_KMS (crtc));
- crtc_cursor_data->hw_state_invalidated = FALSE;
-}
-
-static gboolean
-has_valid_cursor_sprite_buffer (MetaCursorSprite *cursor_sprite,
- MetaGpuKms *gpu_kms)
-{
- MetaCursorNativePrivate *cursor_priv;
- MetaCursorNativeGpuState *cursor_gpu_state;
-
- cursor_priv = get_cursor_priv (cursor_sprite);
- if (!cursor_priv)
- return FALSE;
-
- cursor_gpu_state = get_cursor_gpu_state (cursor_priv, gpu_kms);
- if (!cursor_gpu_state)
- return FALSE;
-
- switch (cursor_gpu_state->pending_buffer_state)
- {
- case META_CURSOR_BUFFER_STATE_NONE:
- return get_active_cursor_sprite_buffer (cursor_gpu_state) != NULL;
- case META_CURSOR_BUFFER_STATE_SET:
- return TRUE;
- case META_CURSOR_BUFFER_STATE_INVALIDATED:
- return FALSE;
- }
-
- g_assert_not_reached ();
-
- return FALSE;
-}
-
-static void
-set_can_preprocess (MetaCursorSprite *cursor_sprite,
- float scale,
- MetaMonitorTransform transform)
-{
- MetaCursorNativePrivate *cursor_priv = get_cursor_priv (cursor_sprite);
-
- cursor_priv->preprocess_state.current_relative_scale = scale;
- cursor_priv->preprocess_state.current_relative_transform = transform;
- cursor_priv->preprocess_state.can_preprocess = TRUE;
-
- invalidate_cursor_gpu_state (cursor_sprite);
-}
-
-static void
-unset_can_preprocess (MetaCursorSprite *cursor_sprite)
-{
- MetaCursorNativePrivate *cursor_priv = get_cursor_priv (cursor_sprite);
-
- memset (&cursor_priv->preprocess_state,
- 0,
- sizeof (cursor_priv->preprocess_state));
- cursor_priv->preprocess_state.can_preprocess = FALSE;
-
- invalidate_cursor_gpu_state (cursor_sprite);
-}
-
-static gboolean
-get_can_preprocess (MetaCursorSprite *cursor_sprite)
-{
- MetaCursorNativePrivate *cursor_priv = get_cursor_priv (cursor_sprite);
-
- return cursor_priv->preprocess_state.can_preprocess;
-}
-
-static float
-get_current_relative_scale (MetaCursorSprite *cursor_sprite)
-{
- MetaCursorNativePrivate *cursor_priv = get_cursor_priv (cursor_sprite);
-
- return cursor_priv->preprocess_state.current_relative_scale;
-}
-
-static MetaMonitorTransform
-get_current_relative_transform (MetaCursorSprite *cursor_sprite)
-{
- MetaCursorNativePrivate *cursor_priv = get_cursor_priv (cursor_sprite);
-
- return cursor_priv->preprocess_state.current_relative_transform;
-}
-
-static void
-has_cursor_plane (MetaLogicalMonitor *logical_monitor,
- MetaMonitor *monitor,
- MetaOutput *output,
- MetaCrtc *crtc,
- gpointer user_data)
-{
- gboolean *has_cursor_planes = user_data;
- MetaCrtcKms *crtc_kms = META_CRTC_KMS (crtc);
- MetaKmsCrtc *kms_crtc = meta_crtc_kms_get_kms_crtc (crtc_kms);
- MetaKmsDevice *kms_device = meta_kms_crtc_get_device (kms_crtc);
-
- *has_cursor_planes &= !!meta_kms_device_get_cursor_plane_for (kms_device,
- kms_crtc);
-}
-
-static gboolean
-crtcs_has_cursor_planes (MetaCursorRenderer *renderer,
- MetaCursorSprite *cursor_sprite)
-{
- MetaCursorRendererNative *cursor_renderer_native =
- META_CURSOR_RENDERER_NATIVE (renderer);
- MetaCursorRendererNativePrivate *priv =
- meta_cursor_renderer_native_get_instance_private (cursor_renderer_native);
- MetaBackend *backend = priv->backend;
- MetaMonitorManager *monitor_manager =
- meta_backend_get_monitor_manager (backend);
- GList *logical_monitors;
- GList *l;
- graphene_rect_t cursor_rect;
-
- cursor_rect = meta_cursor_renderer_calculate_rect (renderer, cursor_sprite);
-
- logical_monitors =
- meta_monitor_manager_get_logical_monitors (monitor_manager);
- for (l = logical_monitors; l; l = l->next)
- {
- MetaLogicalMonitor *logical_monitor = l->data;
- MetaRectangle logical_monitor_layout;
- graphene_rect_t logical_monitor_rect;
- gboolean has_cursor_planes;
-
- logical_monitor_layout =
- meta_logical_monitor_get_layout (logical_monitor);
- logical_monitor_rect =
- meta_rectangle_to_graphene_rect (&logical_monitor_layout);
-
- if (!graphene_rect_intersection (&cursor_rect, &logical_monitor_rect,
- NULL))
- continue;
-
- has_cursor_planes = TRUE;
- meta_logical_monitor_foreach_crtc (logical_monitor,
- has_cursor_plane,
- &has_cursor_planes);
- if (!has_cursor_planes)
- return FALSE;
- }
-
- return TRUE;
-}
-
-static gboolean
-get_common_crtc_sprite_scale_for_logical_monitors (MetaCursorRenderer *renderer,
- MetaCursorSprite *cursor_sprite,
- float *out_scale)
-{
- MetaCursorRendererNative *cursor_renderer_native =
- META_CURSOR_RENDERER_NATIVE (renderer);
- MetaCursorRendererNativePrivate *priv =
- meta_cursor_renderer_native_get_instance_private (cursor_renderer_native);
- MetaBackend *backend = priv->backend;
- MetaMonitorManager *monitor_manager =
- meta_backend_get_monitor_manager (backend);
- graphene_rect_t cursor_rect;
- float scale = 1.0;
- gboolean has_visible_crtc_sprite = FALSE;
- GList *logical_monitors;
- GList *l;
-
- cursor_rect = meta_cursor_renderer_calculate_rect (renderer, cursor_sprite);
-
- logical_monitors =
- meta_monitor_manager_get_logical_monitors (monitor_manager);
-
- for (l = logical_monitors; l; l = l->next)
- {
- MetaLogicalMonitor *logical_monitor = l->data;
- graphene_rect_t logical_monitor_rect =
- meta_rectangle_to_graphene_rect (&logical_monitor->rect);
- float tmp_scale;
-
- if (!graphene_rect_intersection (&cursor_rect,
- &logical_monitor_rect,
- NULL))
- continue;
-
- tmp_scale =
- calculate_cursor_crtc_sprite_scale (cursor_sprite, logical_monitor);
-
- if (has_visible_crtc_sprite && scale != tmp_scale)
- return FALSE;
-
- has_visible_crtc_sprite = TRUE;
- scale = tmp_scale;
- }
-
- if (!has_visible_crtc_sprite)
- return FALSE;
-
- *out_scale = scale;
- return TRUE;
-}
-
-static gboolean
-get_common_crtc_sprite_transform_for_logical_monitors (MetaCursorRenderer *renderer,
- MetaCursorSprite *cursor_sprite,
- MetaMonitorTransform *out_transform)
-{
- MetaCursorRendererNative *cursor_renderer_native =
- META_CURSOR_RENDERER_NATIVE (renderer);
- MetaCursorRendererNativePrivate *priv =
- meta_cursor_renderer_native_get_instance_private (cursor_renderer_native);
- MetaBackend *backend = priv->backend;
- MetaMonitorManager *monitor_manager =
- meta_backend_get_monitor_manager (backend);
- graphene_rect_t cursor_rect;
- MetaMonitorTransform transform = META_MONITOR_TRANSFORM_NORMAL;
- gboolean has_visible_crtc_sprite = FALSE;
- GList *logical_monitors;
- GList *l;
-
- cursor_rect = meta_cursor_renderer_calculate_rect (renderer, cursor_sprite);
-
- logical_monitors =
- meta_monitor_manager_get_logical_monitors (monitor_manager);
-
- for (l = logical_monitors; l; l = l->next)
- {
- MetaLogicalMonitor *logical_monitor = l->data;
- graphene_rect_t logical_monitor_rect =
- meta_rectangle_to_graphene_rect (&logical_monitor->rect);
- MetaMonitorTransform logical_transform, tmp_transform;
- GList *monitors, *l_mon;
-
- if (!graphene_rect_intersection (&cursor_rect,
- &logical_monitor_rect,
- NULL))
- continue;
-
- logical_transform = meta_logical_monitor_get_transform (logical_monitor);
- monitors = meta_logical_monitor_get_monitors (logical_monitor);
- for (l_mon = monitors; l_mon; l_mon = l_mon->next)
- {
- MetaMonitor *monitor = l_mon->data;
-
- tmp_transform = meta_monitor_transform_relative_transform (
- meta_cursor_sprite_get_texture_transform (cursor_sprite),
- meta_monitor_logical_to_crtc_transform (monitor, logical_transform));
-
- if (has_visible_crtc_sprite && transform != tmp_transform)
- return FALSE;
-
- has_visible_crtc_sprite = TRUE;
- transform = tmp_transform;
- }
- }
-
- if (!has_visible_crtc_sprite)
- return FALSE;
-
- *out_transform = transform;
- return TRUE;
-}
-
-static gboolean
-should_have_hw_cursor (MetaCursorRenderer *renderer,
- MetaCursorSprite *cursor_sprite,
- GList *gpus)
-{
- MetaCursorRendererNative *cursor_renderer_native =
- META_CURSOR_RENDERER_NATIVE (renderer);
- MetaCursorRendererNativePrivate *priv =
- meta_cursor_renderer_native_get_instance_private (cursor_renderer_native);
- CoglTexture *texture;
- MetaMonitorTransform transform;
- float scale;
- GList *l;
-
- if (!gpus)
- return FALSE;
-
- if (!cursor_sprite)
- return FALSE;
-
- if (meta_backend_is_hw_cursors_inhibited (priv->backend))
- return FALSE;
-
- for (l = gpus; l; l = l->next)
- {
- MetaGpuKms *gpu_kms = l->data;
- MetaCursorRendererNativeGpuData *cursor_renderer_gpu_data;
-
- cursor_renderer_gpu_data =
- meta_cursor_renderer_native_gpu_data_from_gpu (gpu_kms);
- if (!cursor_renderer_gpu_data)
- return FALSE;
-
- if (cursor_renderer_gpu_data->hw_cursor_broken)
- return FALSE;
-
- if (!has_valid_cursor_sprite_buffer (cursor_sprite, gpu_kms))
- return FALSE;
- }
-
- if (!crtcs_has_cursor_planes (renderer, cursor_sprite))
- return FALSE;
-
- texture = meta_cursor_sprite_get_cogl_texture (cursor_sprite);
- if (!texture)
- return FALSE;
-
- if (!get_common_crtc_sprite_scale_for_logical_monitors (renderer,
- cursor_sprite,
- &scale))
- return FALSE;
-
- if (!get_common_crtc_sprite_transform_for_logical_monitors (renderer,
- cursor_sprite,
- &transform))
- return FALSE;
-
- if (G_APPROX_VALUE (scale, 1.f, FLT_EPSILON) &&
- transform == META_MONITOR_TRANSFORM_NORMAL)
- return TRUE;
- else
- return get_can_preprocess (cursor_sprite);
-
- return TRUE;
-}
-
-static gboolean
-meta_cursor_renderer_native_update_animation (MetaCursorRendererNative *native)
-{
- MetaCursorRendererNativePrivate *priv =
- meta_cursor_renderer_native_get_instance_private (native);
- MetaCursorRenderer *renderer = META_CURSOR_RENDERER (native);
- MetaCursorSprite *cursor_sprite = meta_cursor_renderer_get_cursor (renderer);
-
- priv->animation_timeout_id = 0;
- meta_cursor_sprite_tick_frame (cursor_sprite);
- meta_cursor_renderer_force_update (renderer);
-
- return G_SOURCE_REMOVE;
-}
-
-static void
-maybe_schedule_cursor_sprite_animation_frame (MetaCursorRendererNative *native,
- MetaCursorSprite *cursor_sprite)
-{
- MetaCursorRendererNativePrivate *priv =
- meta_cursor_renderer_native_get_instance_private (native);
- gboolean cursor_change;
- guint delay;
-
- cursor_change = cursor_sprite != priv->last_cursor;
- priv->last_cursor = cursor_sprite;
-
- if (!cursor_change && priv->animation_timeout_id)
- return;
-
- g_clear_handle_id (&priv->animation_timeout_id, g_source_remove);
-
- if (cursor_sprite && meta_cursor_sprite_is_animated (cursor_sprite))
- {
- delay = meta_cursor_sprite_get_current_frame_time (cursor_sprite);
-
- if (delay == 0)
- return;
-
- priv->animation_timeout_id =
- g_timeout_add (delay,
- (GSourceFunc) meta_cursor_renderer_native_update_animation,
- native);
- g_source_set_name_by_id (priv->animation_timeout_id,
- "[mutter] meta_cursor_renderer_native_update_animation");
- }
-}
-
-static GList *
-calculate_cursor_sprite_gpus (MetaCursorRenderer *renderer,
- MetaCursorSprite *cursor_sprite)
-{
- MetaCursorRendererNative *native = META_CURSOR_RENDERER_NATIVE (renderer);
- MetaCursorRendererNativePrivate *priv =
- meta_cursor_renderer_native_get_instance_private (native);
- MetaBackend *backend = priv->backend;
- MetaMonitorManager *monitor_manager =
- meta_backend_get_monitor_manager (backend);
- GList *gpus = NULL;
- GList *logical_monitors;
- GList *l;
- graphene_rect_t cursor_rect;
-
- cursor_rect = meta_cursor_renderer_calculate_rect (renderer, cursor_sprite);
-
- logical_monitors =
- meta_monitor_manager_get_logical_monitors (monitor_manager);
- for (l = logical_monitors; l; l = l->next)
- {
- MetaLogicalMonitor *logical_monitor = l->data;
- MetaRectangle logical_monitor_layout;
- graphene_rect_t logical_monitor_rect;
- GList *monitors, *l_mon;
-
- logical_monitor_layout =
- meta_logical_monitor_get_layout (logical_monitor);
- logical_monitor_rect =
- meta_rectangle_to_graphene_rect (&logical_monitor_layout);
-
- if (!graphene_rect_intersection (&cursor_rect, &logical_monitor_rect,
- NULL))
- continue;
-
- monitors = meta_logical_monitor_get_monitors (logical_monitor);
- for (l_mon = monitors; l_mon; l_mon = l_mon->next)
- {
- MetaMonitor *monitor = l_mon->data;
- MetaOutput *output = meta_monitor_get_main_output (monitor);
- MetaGpu *gpu;
-
- gpu = meta_output_get_gpu (output);
- if (gpu && !g_list_find (gpus, gpu))
- gpus = g_list_prepend (gpus, gpu);
- }
- }
-
- return gpus;
-}
-
-static void
-on_kms_update_result (const MetaKmsFeedback *kms_feedback,
- gpointer user_data)
-{
- MetaCursorRendererNative *cursor_renderer_native = user_data;
- MetaCursorRenderer *cursor_renderer =
- META_CURSOR_RENDERER (cursor_renderer_native);
- MetaCursorRendererNativePrivate *priv =
- meta_cursor_renderer_native_get_instance_private (cursor_renderer_native);
- gboolean has_hw_cursor_failure = FALSE;
- GList *l;
-
- for (l = meta_kms_feedback_get_failed_planes (kms_feedback); l; l = l->next)
- {
- MetaKmsPlaneFeedback *plane_feedback = l->data;
-
- switch (meta_kms_plane_get_plane_type (plane_feedback->plane))
- {
- case META_KMS_PLANE_TYPE_CURSOR:
- break;
- case META_KMS_PLANE_TYPE_PRIMARY:
- case META_KMS_PLANE_TYPE_OVERLAY:
- continue;
- }
-
- disable_hw_cursor_for_crtc (plane_feedback->crtc,
- plane_feedback->error);
- has_hw_cursor_failure = TRUE;
- }
-
- if (has_hw_cursor_failure)
- {
- priv->has_hw_cursor = FALSE;
- meta_cursor_renderer_force_update (cursor_renderer);
- }
-}
-
-static void
-schedule_sync_position (MetaCursorRendererNative *cursor_renderer_native)
-{
- MetaCursorRendererNativePrivate *priv =
- meta_cursor_renderer_native_get_instance_private (cursor_renderer_native);
- GList *l;
-
- for (l = meta_backend_get_gpus (priv->backend); l; l = l->next)
- {
- MetaGpu *gpu = l->data;
- GList *l_crtc;
-
- for (l_crtc = meta_gpu_get_crtcs (gpu); l_crtc; l_crtc = l_crtc->next)
- {
- MetaCrtcKms *crtc_kms = META_CRTC_KMS (l_crtc->data);
- CrtcCursorData *crtc_cursor_data;
-
- crtc_cursor_data = ensure_crtc_cursor_data (crtc_kms);
- crtc_cursor_data->needs_sync_position = TRUE;
- }
- }
-}
-
-static gboolean
-meta_cursor_renderer_native_update_cursor (MetaCursorRenderer *renderer,
- MetaCursorSprite *cursor_sprite)
-{
- MetaCursorRendererNative *native = META_CURSOR_RENDERER_NATIVE (renderer);
- MetaCursorRendererNativePrivate *priv =
- meta_cursor_renderer_native_get_instance_private (native);
- ClutterStage *stage = CLUTTER_STAGE (meta_backend_get_stage (priv->backend));
- g_autoptr (GList) gpus = NULL;
-
- if (cursor_sprite)
- {
- meta_cursor_sprite_realize_texture (cursor_sprite);
- gpus = calculate_cursor_sprite_gpus (renderer, cursor_sprite);
- realize_cursor_sprite (renderer, cursor_sprite, gpus);
- }
-
- maybe_schedule_cursor_sprite_animation_frame (native, cursor_sprite);
-
- priv->has_hw_cursor = should_have_hw_cursor (renderer, cursor_sprite, gpus);
-
- schedule_sync_position (native);
- clutter_stage_schedule_update (stage);
-
- return (priv->has_hw_cursor ||
- !cursor_sprite ||
- !meta_cursor_sprite_get_cogl_texture (cursor_sprite));
-}
-
-static void
-unset_crtc_cursor_renderer_privates (MetaGpu *gpu,
- MetaDrmBuffer *buffer)
-{
- GList *l;
-
- for (l = meta_gpu_get_crtcs (gpu); l; l = l->next)
- {
- MetaCrtcKms *crtc_kms = META_CRTC_KMS (l->data);
- MetaDrmBuffer *crtc_buffer;
-
- crtc_buffer = meta_crtc_kms_get_cursor_renderer_private (crtc_kms);
- if (buffer == crtc_buffer)
- meta_crtc_kms_set_cursor_renderer_private (crtc_kms, NULL, NULL);
- }
-}
-
-static void
-cursor_gpu_state_free (MetaCursorNativeGpuState *cursor_gpu_state)
-{
- int i;
- MetaDrmBuffer *active_buffer;
-
- active_buffer = get_active_cursor_sprite_buffer (cursor_gpu_state);
- if (active_buffer)
- unset_crtc_cursor_renderer_privates (cursor_gpu_state->gpu,
- active_buffer);
-
- for (i = 0; i < HW_CURSOR_BUFFER_COUNT; i++)
- g_clear_object (&cursor_gpu_state->buffers[i]);
- g_free (cursor_gpu_state);
-}
-
-static MetaCursorNativeGpuState *
-get_cursor_gpu_state (MetaCursorNativePrivate *cursor_priv,
- MetaGpuKms *gpu_kms)
-{
- return g_hash_table_lookup (cursor_priv->gpu_states, gpu_kms);
-}
-
-static MetaCursorNativeGpuState *
-ensure_cursor_gpu_state (MetaCursorNativePrivate *cursor_priv,
- MetaGpuKms *gpu_kms)
-{
- MetaCursorNativeGpuState *cursor_gpu_state;
-
- cursor_gpu_state = get_cursor_gpu_state (cursor_priv, gpu_kms);
- if (cursor_gpu_state)
- return cursor_gpu_state;
-
- cursor_gpu_state = g_new0 (MetaCursorNativeGpuState, 1);
- cursor_gpu_state->gpu = META_GPU (gpu_kms);
- g_hash_table_insert (cursor_priv->gpu_states, gpu_kms, cursor_gpu_state);
-
- return cursor_gpu_state;
-}
-
-static void
-invalidate_cursor_gpu_state (MetaCursorSprite *cursor_sprite)
-{
- MetaCursorNativePrivate *cursor_priv = get_cursor_priv (cursor_sprite);
- GHashTableIter iter;
- MetaCursorNativeGpuState *cursor_gpu_state;
-
- g_hash_table_iter_init (&iter, cursor_priv->gpu_states);
- while (g_hash_table_iter_next (&iter, NULL, (gpointer *) &cursor_gpu_state))
- {
- unsigned int pending_buffer_idx;
-
- pending_buffer_idx = get_pending_cursor_sprite_buffer_index (cursor_gpu_state);
- g_clear_object (&cursor_gpu_state->buffers[pending_buffer_idx]);
- cursor_gpu_state->pending_buffer_state =
- META_CURSOR_BUFFER_STATE_INVALIDATED;
- }
-}
-
-static void
-on_cursor_sprite_texture_changed (MetaCursorSprite *cursor_sprite)
-{
- invalidate_cursor_gpu_state (cursor_sprite);
-}
-
-static void
-cursor_priv_free (MetaCursorNativePrivate *cursor_priv)
-{
- g_hash_table_destroy (cursor_priv->gpu_states);
- g_free (cursor_priv);
-}
-
-static MetaCursorNativePrivate *
-get_cursor_priv (MetaCursorSprite *cursor_sprite)
-{
- return g_object_get_qdata (G_OBJECT (cursor_sprite), quark_cursor_sprite);
-}
-
-static MetaCursorNativePrivate *
-ensure_cursor_priv (MetaCursorSprite *cursor_sprite)
-{
- MetaCursorNativePrivate *cursor_priv;
-
- cursor_priv = get_cursor_priv (cursor_sprite);
- if (cursor_priv)
- return cursor_priv;
-
- cursor_priv = g_new0 (MetaCursorNativePrivate, 1);
- cursor_priv->gpu_states =
- g_hash_table_new_full (g_direct_hash,
- g_direct_equal,
- NULL,
- (GDestroyNotify) cursor_gpu_state_free);
- g_object_set_qdata_full (G_OBJECT (cursor_sprite),
- quark_cursor_sprite,
- cursor_priv,
- (GDestroyNotify) cursor_priv_free);
-
- g_signal_connect (cursor_sprite, "texture-changed",
- G_CALLBACK (on_cursor_sprite_texture_changed), NULL);
-
- unset_can_preprocess (cursor_sprite);
-
- return cursor_priv;
-}
-
-static void
-load_cursor_sprite_gbm_buffer_for_gpu (MetaCursorRendererNative *native,
- MetaGpuKms *gpu_kms,
- MetaCursorSprite *cursor_sprite,
- uint8_t *pixels,
- uint width,
- uint height,
- int rowstride,
- uint32_t gbm_format)
-{
- MetaCursorRendererNativePrivate *priv =
- meta_cursor_renderer_native_get_instance_private (native);
- uint64_t cursor_width, cursor_height;
- MetaCursorRendererNativeGpuData *cursor_renderer_gpu_data;
- struct gbm_device *gbm_device;
-
- cursor_renderer_gpu_data =
- meta_cursor_renderer_native_gpu_data_from_gpu (gpu_kms);
- if (!cursor_renderer_gpu_data)
- return;
-
- cursor_width = (uint64_t) cursor_renderer_gpu_data->cursor_width;
- cursor_height = (uint64_t) cursor_renderer_gpu_data->cursor_height;
-
- if (width > cursor_width || height > cursor_height)
- {
- meta_warning ("Invalid theme cursor size (must be at most %ux%u)",
- (unsigned int)cursor_width, (unsigned int)cursor_height);
- return;
- }
-
- gbm_device = meta_gbm_device_from_gpu (gpu_kms);
- if (gbm_device_is_format_supported (gbm_device, gbm_format,
- GBM_BO_USE_CURSOR | GBM_BO_USE_WRITE))
- {
- MetaBackendNative *backend_native = META_BACKEND_NATIVE (priv->backend);
- MetaDevicePool *device_pool =
- meta_backend_native_get_device_pool (backend_native);
- g_autoptr (MetaDeviceFile) device_file = NULL;
- struct gbm_bo *bo;
- uint8_t buf[4 * cursor_width * cursor_height];
- uint i;
- g_autoptr (GError) error = NULL;
- MetaDrmBufferGbm *buffer_gbm;
-
- device_file = meta_device_pool_open (device_pool,
- meta_gpu_kms_get_file_path (gpu_kms),
- META_DEVICE_FILE_FLAG_TAKE_CONTROL,
- &error);
- if (!device_file)
- {
- g_warning ("Failed to open '%s' for updating the cursor: %s",
- meta_gpu_kms_get_file_path (gpu_kms),
- error->message);
- return;
- }
-
- bo = gbm_bo_create (gbm_device, cursor_width, cursor_height,
- gbm_format, GBM_BO_USE_CURSOR | GBM_BO_USE_WRITE);
- if (!bo)
- {
- meta_warning ("Failed to allocate HW cursor buffer");
- return;
- }
-
- memset (buf, 0, sizeof(buf));
- for (i = 0; i < height; i++)
- memcpy (buf + i * 4 * cursor_width, pixels + i * rowstride, width * 4);
- if (gbm_bo_write (bo, buf, cursor_width * cursor_height * 4) != 0)
- {
- meta_warning ("Failed to write cursors buffer data: %s",
- g_strerror (errno));
- gbm_bo_destroy (bo);
- return;
- }
-
- buffer_gbm = meta_drm_buffer_gbm_new_take (device_file, bo, FALSE, &error);
- if (!buffer_gbm)
- {
- meta_warning ("Failed to create DRM buffer wrapper: %s",
- error->message);
- gbm_bo_destroy (bo);
- return;
- }
-
- set_pending_cursor_sprite_buffer (cursor_sprite, gpu_kms,
- META_DRM_BUFFER (buffer_gbm));
- }
- else
- {
- meta_warning ("HW cursor for format %d not supported", gbm_format);
- }
-}
-
-static gboolean
-is_cursor_hw_state_valid (MetaCursorSprite *cursor_sprite,
- MetaGpuKms *gpu_kms)
-{
- MetaCursorNativePrivate *cursor_priv;
- MetaCursorNativeGpuState *cursor_gpu_state;
-
- cursor_priv = get_cursor_priv (cursor_sprite);
- if (!cursor_priv)
- return FALSE;
-
- cursor_gpu_state = get_cursor_gpu_state (cursor_priv, gpu_kms);
- if (!cursor_gpu_state)
- return FALSE;
-
- switch (cursor_gpu_state->pending_buffer_state)
- {
- case META_CURSOR_BUFFER_STATE_SET:
- case META_CURSOR_BUFFER_STATE_NONE:
- return TRUE;
- case META_CURSOR_BUFFER_STATE_INVALIDATED:
- return FALSE;
- }
-
- g_assert_not_reached ();
- return FALSE;
-}
-
-static gboolean
-is_cursor_scale_and_transform_valid (MetaCursorRenderer *renderer,
- MetaCursorSprite *cursor_sprite)
-{
- MetaMonitorTransform transform;
- float scale;
-
- if (!get_common_crtc_sprite_scale_for_logical_monitors (renderer,
- cursor_sprite,
- &scale))
- return FALSE;
-
- if (!get_common_crtc_sprite_transform_for_logical_monitors (renderer,
- cursor_sprite,
- &transform))
- return FALSE;
-
- return (scale == get_current_relative_scale (cursor_sprite) &&
- transform == get_current_relative_transform (cursor_sprite));
-}
-
-static cairo_surface_t *
-scale_and_transform_cursor_sprite_cpu (uint8_t *pixels,
- int width,
- int height,
- int rowstride,
- float scale,
- MetaMonitorTransform transform)
-{
- cairo_t *cr;
- cairo_surface_t *source_surface;
- cairo_surface_t *target_surface;
- int image_width;
- int image_height;
-
- image_width = ceilf (width * scale);
- image_height = ceilf (height * scale);
-
- target_surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
- image_width,
- image_height);
-
- cr = cairo_create (target_surface);
- if (transform != META_MONITOR_TRANSFORM_NORMAL)
- {
- cairo_translate (cr, 0.5 * image_width, 0.5 * image_height);
- switch (transform)
- {
- case META_MONITOR_TRANSFORM_90:
- cairo_rotate (cr, M_PI * 1.5);
- break;
- case META_MONITOR_TRANSFORM_180:
- cairo_rotate (cr, M_PI);
- break;
- case META_MONITOR_TRANSFORM_270:
- cairo_rotate (cr, M_PI * 0.5);
- break;
- case META_MONITOR_TRANSFORM_FLIPPED:
- cairo_scale (cr, 1, -1);
- break;
- case META_MONITOR_TRANSFORM_FLIPPED_90:
- cairo_rotate (cr, M_PI * 1.5);
- cairo_scale (cr, -1, 1);
- break;
- case META_MONITOR_TRANSFORM_FLIPPED_180:
- cairo_rotate (cr, M_PI);
- cairo_scale (cr, 1, -1);
- break;
- case META_MONITOR_TRANSFORM_FLIPPED_270:
- cairo_rotate (cr, M_PI * 0.5);
- cairo_scale (cr, -1, 1);
- break;
- case META_MONITOR_TRANSFORM_NORMAL:
- g_assert_not_reached ();
- }
- cairo_translate (cr, -0.5 * image_width, -0.5 * image_height);
- }
- cairo_scale (cr, scale, scale);
-
- source_surface = cairo_image_surface_create_for_data (pixels,
- CAIRO_FORMAT_ARGB32,
- width,
- height,
- rowstride);
-
- cairo_set_source_surface (cr, source_surface, 0, 0);
- cairo_paint (cr);
- cairo_destroy (cr);
- cairo_surface_destroy (source_surface);
-
- return target_surface;
-}
-
-static void
-load_scaled_and_transformed_cursor_sprite (MetaCursorRendererNative *native,
- MetaGpuKms *gpu_kms,
- MetaCursorSprite *cursor_sprite,
- float relative_scale,
- MetaMonitorTransform relative_transform,
- uint8_t *data,
- int width,
- int height,
- int rowstride,
- uint32_t gbm_format)
-{
- if (!G_APPROX_VALUE (relative_scale, 1.f, FLT_EPSILON) ||
- relative_transform != META_MONITOR_TRANSFORM_NORMAL)
- {
- cairo_surface_t *surface;
-
- surface = scale_and_transform_cursor_sprite_cpu (data,
- width,
- height,
- rowstride,
- relative_scale,
- relative_transform);
-
- load_cursor_sprite_gbm_buffer_for_gpu (native,
- gpu_kms,
- cursor_sprite,
- cairo_image_surface_get_data (surface),
- cairo_image_surface_get_width (surface),
- cairo_image_surface_get_width (surface),
- cairo_image_surface_get_stride (surface),
- gbm_format);
-
- cairo_surface_destroy (surface);
- }
- else
- {
- load_cursor_sprite_gbm_buffer_for_gpu (native,
- gpu_kms,
- cursor_sprite,
- data,
- width,
- height,
- rowstride,
- gbm_format);
- }
-}
-
-#ifdef HAVE_WAYLAND
-static void
-realize_cursor_sprite_from_wl_buffer_for_gpu (MetaCursorRenderer *renderer,
- MetaGpuKms *gpu_kms,
- MetaCursorSpriteWayland *sprite_wayland)
-{
- MetaCursorRendererNative *native = META_CURSOR_RENDERER_NATIVE (renderer);
- MetaCursorRendererNativePrivate *priv =
- meta_cursor_renderer_native_get_instance_private (native);
- MetaCursorSprite *cursor_sprite = META_CURSOR_SPRITE (sprite_wayland);
- MetaCursorRendererNativeGpuData *cursor_renderer_gpu_data;
- uint64_t cursor_width, cursor_height;
- CoglTexture *texture;
- uint width, height;
- MetaWaylandBuffer *buffer;
- struct wl_resource *buffer_resource;
- struct wl_shm_buffer *shm_buffer;
-
- cursor_renderer_gpu_data =
- meta_cursor_renderer_native_gpu_data_from_gpu (gpu_kms);
- if (!cursor_renderer_gpu_data || cursor_renderer_gpu_data->hw_cursor_broken)
- return;
-
- if (is_cursor_hw_state_valid (cursor_sprite, gpu_kms) &&
- is_cursor_scale_and_transform_valid (renderer, cursor_sprite))
- return;
-
- buffer = meta_cursor_sprite_wayland_get_buffer (sprite_wayland);
- if (!buffer)
- return;
-
- buffer_resource = meta_wayland_buffer_get_resource (buffer);
- if (!buffer_resource)
- return;
-
- ensure_cursor_priv (cursor_sprite);
-
- shm_buffer = wl_shm_buffer_get (buffer_resource);
- if (shm_buffer)
- {
- int rowstride = wl_shm_buffer_get_stride (shm_buffer);
- uint8_t *buffer_data;
- float relative_scale;
- MetaMonitorTransform relative_transform;
- uint32_t gbm_format;
-
- if (!get_common_crtc_sprite_scale_for_logical_monitors (renderer,
- cursor_sprite,
- &relative_scale))
- {
- unset_can_preprocess (cursor_sprite);
- return;
- }
-
- if (!get_common_crtc_sprite_transform_for_logical_monitors (renderer,
- cursor_sprite,
- &relative_transform))
- {
- unset_can_preprocess (cursor_sprite);
- return;
- }
-
- set_can_preprocess (cursor_sprite,
- relative_scale,
- relative_transform);
-
- wl_shm_buffer_begin_access (shm_buffer);
- buffer_data = wl_shm_buffer_get_data (shm_buffer);
-
- width = wl_shm_buffer_get_width (shm_buffer);
- height = wl_shm_buffer_get_height (shm_buffer);
-
- switch (wl_shm_buffer_get_format (shm_buffer))
- {
- case WL_SHM_FORMAT_ARGB8888:
- gbm_format = GBM_FORMAT_ARGB8888;
- break;
- case WL_SHM_FORMAT_XRGB8888:
- gbm_format = GBM_FORMAT_XRGB8888;
- break;
- default:
- g_warn_if_reached ();
- gbm_format = GBM_FORMAT_ARGB8888;
- }
-
- load_scaled_and_transformed_cursor_sprite (native,
- gpu_kms,
- cursor_sprite,
- relative_scale,
- relative_transform,
- buffer_data,
- width,
- height,
- rowstride,
- gbm_format);
-
- wl_shm_buffer_end_access (shm_buffer);
- }
- else
- {
- MetaBackendNative *backend_native = META_BACKEND_NATIVE (priv->backend);
- MetaDevicePool *device_pool =
- meta_backend_native_get_device_pool (backend_native);
- g_autoptr (MetaDeviceFile) device_file = NULL;
- struct gbm_device *gbm_device;
- struct gbm_bo *bo;
- g_autoptr (GError) error = NULL;
- MetaDrmBufferGbm *buffer_gbm;
-
- device_file = meta_device_pool_open (device_pool,
- meta_gpu_kms_get_file_path (gpu_kms),
- META_DEVICE_FILE_FLAG_TAKE_CONTROL,
- &error);
- if (!device_file)
- {
- g_warning ("Failed to open '%s' for updating the cursor: %s",
- meta_gpu_kms_get_file_path (gpu_kms),
- error->message);
- return;
- }
-
- /* HW cursors have a predefined size (at least 64x64), which usually is
- * bigger than cursor theme size, so themed cursors must be padded with
- * transparent pixels to fill the overlay. This is trivial if we have CPU
- * access to the data, but it's not possible if the buffer is in GPU
- * memory (and possibly tiled too), so if we don't get the right size, we
- * fallback to GL. */
- cursor_width = (uint64_t) cursor_renderer_gpu_data->cursor_width;
- cursor_height = (uint64_t) cursor_renderer_gpu_data->cursor_height;
-
- texture = meta_cursor_sprite_get_cogl_texture (cursor_sprite);
- width = cogl_texture_get_width (texture);
- height = cogl_texture_get_height (texture);
-
- if (width != cursor_width || height != cursor_height)
- {
- meta_warning ("Invalid cursor size (must be 64x64), falling back to software (GL) cursors");
- return;
- }
-
- gbm_device = meta_gbm_device_from_gpu (gpu_kms);
- bo = gbm_bo_import (gbm_device,
- GBM_BO_IMPORT_WL_BUFFER,
- buffer,
- GBM_BO_USE_CURSOR);
- if (!bo)
- {
- meta_warning ("Importing HW cursor from wl_buffer failed");
- return;
- }
-
- unset_can_preprocess (cursor_sprite);
-
- buffer_gbm = meta_drm_buffer_gbm_new_take (device_file, bo, FALSE, &error);
- if (!buffer_gbm)
- {
- meta_warning ("Failed to create DRM buffer wrapper: %s",
- error->message);
- gbm_bo_destroy (bo);
- return;
- }
-
- set_pending_cursor_sprite_buffer (cursor_sprite, gpu_kms,
- META_DRM_BUFFER (buffer_gbm));
- }
-}
-#endif
-
-static void
-realize_cursor_sprite_from_xcursor_for_gpu (MetaCursorRenderer *renderer,
- MetaGpuKms *gpu_kms,
- MetaCursorSpriteXcursor *sprite_xcursor)
-{
- MetaCursorRendererNative *native = META_CURSOR_RENDERER_NATIVE (renderer);
- MetaCursorRendererNativeGpuData *cursor_renderer_gpu_data;
- MetaCursorSprite *cursor_sprite = META_CURSOR_SPRITE (sprite_xcursor);
- XcursorImage *xc_image;
- float relative_scale;
- MetaMonitorTransform relative_transform;
-
- ensure_cursor_priv (cursor_sprite);
-
- cursor_renderer_gpu_data =
- meta_cursor_renderer_native_gpu_data_from_gpu (gpu_kms);
- if (!cursor_renderer_gpu_data || cursor_renderer_gpu_data->hw_cursor_broken)
- return;
-
- if (is_cursor_hw_state_valid (cursor_sprite, gpu_kms) &&
- is_cursor_scale_and_transform_valid (renderer, cursor_sprite))
- return;
-
- if (!get_common_crtc_sprite_scale_for_logical_monitors (renderer,
- cursor_sprite,
- &relative_scale))
- {
- unset_can_preprocess (cursor_sprite);
- return;
- }
-
- if (!get_common_crtc_sprite_transform_for_logical_monitors (renderer,
- cursor_sprite,
- &relative_transform))
- {
- unset_can_preprocess (cursor_sprite);
- return;
- }
-
- set_can_preprocess (cursor_sprite,
- relative_scale,
- relative_transform);
-
- xc_image = meta_cursor_sprite_xcursor_get_current_image (sprite_xcursor);
-
- load_scaled_and_transformed_cursor_sprite (native,
- gpu_kms,
- cursor_sprite,
- relative_scale,
- relative_transform,
- (uint8_t *) xc_image->pixels,
- xc_image->width,
- xc_image->height,
- xc_image->width * 4,
- GBM_FORMAT_ARGB8888);
-}
-
-static void
-realize_cursor_sprite_for_gpu (MetaCursorRenderer *renderer,
- MetaGpuKms *gpu_kms,
- MetaCursorSprite *cursor_sprite)
-{
- if (META_IS_CURSOR_SPRITE_XCURSOR (cursor_sprite))
- {
- MetaCursorSpriteXcursor *sprite_xcursor =
- META_CURSOR_SPRITE_XCURSOR (cursor_sprite);
-
- realize_cursor_sprite_from_xcursor_for_gpu (renderer,
- gpu_kms,
- sprite_xcursor);
- }
-#ifdef HAVE_WAYLAND
- else if (META_IS_CURSOR_SPRITE_WAYLAND (cursor_sprite))
- {
- MetaCursorSpriteWayland *sprite_wayland =
- META_CURSOR_SPRITE_WAYLAND (cursor_sprite);
-
- realize_cursor_sprite_from_wl_buffer_for_gpu (renderer,
- gpu_kms,
- sprite_wayland);
- }
-#endif
-}
-
-static void
-realize_cursor_sprite (MetaCursorRenderer *renderer,
- MetaCursorSprite *cursor_sprite,
- GList *gpus)
-{
- GList *l;
-
- for (l = gpus; l; l = l->next)
- {
- MetaGpuKms *gpu_kms = l->data;
-
- realize_cursor_sprite_for_gpu (renderer, gpu_kms, cursor_sprite);
- }
-}
-
-static void
-meta_cursor_renderer_native_class_init (MetaCursorRendererNativeClass *klass)
-{
- MetaCursorRendererClass *renderer_class = META_CURSOR_RENDERER_CLASS (klass);
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- object_class->finalize = meta_cursor_renderer_native_finalize;
- renderer_class->update_cursor = meta_cursor_renderer_native_update_cursor;
-
- quark_cursor_sprite = g_quark_from_static_string ("-meta-cursor-native");
- quark_cursor_renderer_native_gpu_data =
- g_quark_from_static_string ("-meta-cursor-renderer-native-gpu-data");
-}
-
-static void
-force_update_hw_cursor (MetaCursorRendererNative *native)
-{
- MetaCursorRenderer *renderer = META_CURSOR_RENDERER (native);
- MetaCursorRendererNativePrivate *priv =
- meta_cursor_renderer_native_get_instance_private (native);
- GList *l;
-
- for (l = meta_backend_get_gpus (priv->backend); l; l = l->next)
- {
- MetaGpu *gpu = l->data;
- GList *l_crtc;
-
- for (l_crtc = meta_gpu_get_crtcs (gpu); l_crtc; l_crtc = l_crtc->next)
- {
- MetaCrtcKms *crtc_kms = META_CRTC_KMS (l_crtc->data);
- CrtcCursorData *crtc_cursor_data;
-
- crtc_cursor_data = ensure_crtc_cursor_data (crtc_kms);
- crtc_cursor_data->hw_state_invalidated = TRUE;
- }
- }
-
- meta_cursor_renderer_force_update (renderer);
-}
-
-static void
-on_monitors_changed (MetaMonitorManager *monitors,
- MetaCursorRendererNative *native)
-{
- force_update_hw_cursor (native);
-}
-
-static void
-init_hw_cursor_support_for_gpu (MetaGpuKms *gpu_kms)
-{
- MetaKmsDevice *kms_device = meta_gpu_kms_get_kms_device (gpu_kms);
- MetaCursorRendererNativeGpuData *cursor_renderer_gpu_data;
- struct gbm_device *gbm_device;
- uint64_t width, height;
-
- gbm_device = meta_gbm_device_from_gpu (gpu_kms);
- if (!gbm_device)
- return;
-
- cursor_renderer_gpu_data =
- meta_create_cursor_renderer_native_gpu_data (gpu_kms);
-
- if (!meta_kms_device_get_cursor_size (kms_device, &width, &height))
- {
- width = 64;
- height = 64;
- }
-
- cursor_renderer_gpu_data->cursor_width = width;
- cursor_renderer_gpu_data->cursor_height = height;
-}
-
-static void
-on_gpu_added_for_cursor (MetaBackend *backend,
- MetaGpuKms *gpu_kms)
-{
- init_hw_cursor_support_for_gpu (gpu_kms);
-}
-
-static void
-init_hw_cursor_support (MetaCursorRendererNative *cursor_renderer_native)
-{
- MetaCursorRendererNativePrivate *priv =
- meta_cursor_renderer_native_get_instance_private (cursor_renderer_native);
- GList *gpus;
- GList *l;
-
- gpus = meta_backend_get_gpus (priv->backend);
- for (l = gpus; l; l = l->next)
- {
- MetaGpuKms *gpu_kms = l->data;
-
- init_hw_cursor_support_for_gpu (gpu_kms);
- }
-}
-
-MetaCursorRendererNative *
-meta_cursor_renderer_native_new (MetaBackend *backend,
- ClutterInputDevice *device)
-{
- MetaMonitorManager *monitor_manager =
- meta_backend_get_monitor_manager (backend);
- MetaCursorRendererNative *cursor_renderer_native;
- MetaCursorRendererNativePrivate *priv;
-
- cursor_renderer_native = g_object_new (META_TYPE_CURSOR_RENDERER_NATIVE,
- "backend", backend,
- "device", device,
- NULL);
- priv =
- meta_cursor_renderer_native_get_instance_private (cursor_renderer_native);
-
- g_signal_connect_object (monitor_manager, "monitors-changed-internal",
- G_CALLBACK (on_monitors_changed),
- cursor_renderer_native, 0);
- g_signal_connect (backend, "gpu-added",
- G_CALLBACK (on_gpu_added_for_cursor), NULL);
-
- priv->backend = backend;
-
- init_hw_cursor_support (cursor_renderer_native);
-
- return cursor_renderer_native;
-}
-
-static void
-meta_cursor_renderer_native_init (MetaCursorRendererNative *native)
-{
-}
diff --git a/src/backends/native/meta-cursor-renderer-native.h b/src/backends/native/meta-cursor-renderer-native.h
deleted file mode 100644
index 5113b96ce..000000000
--- a/src/backends/native/meta-cursor-renderer-native.h
+++ /dev/null
@@ -1,42 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2014 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Written by:
- * Jasper St. Pierre <jstpierre@mecheye.net>
- */
-
-#ifndef META_CURSOR_RENDERER_NATIVE_H
-#define META_CURSOR_RENDERER_NATIVE_H
-
-#include "backends/meta-cursor-renderer.h"
-#include "meta/meta-backend.h"
-
-#define META_TYPE_CURSOR_RENDERER_NATIVE (meta_cursor_renderer_native_get_type ())
-G_DECLARE_FINAL_TYPE (MetaCursorRendererNative, meta_cursor_renderer_native,
- META, CURSOR_RENDERER_NATIVE,
- MetaCursorRenderer)
-
-void meta_cursor_renderer_native_prepare_frame (MetaCursorRendererNative *cursor_renderer_native,
- MetaRendererView *view);
-
-MetaCursorRendererNative * meta_cursor_renderer_native_new (MetaBackend *backend,
- ClutterInputDevice *device);
-
-#endif /* META_CURSOR_RENDERER_NATIVE_H */
diff --git a/src/backends/native/meta-device-pool-private.h b/src/backends/native/meta-device-pool-private.h
deleted file mode 100644
index 06a43f6f4..000000000
--- a/src/backends/native/meta-device-pool-private.h
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Copyright (C) 2021 Red Hat, Inc.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-
-#ifndef META_DEVICE_POOL_PRIVATE_H
-#define META_DEVICE_POOL_PRIVATE_H
-
-#include <glib-object.h>
-
-#include "backends/native/meta-device-pool.h"
-#include "backends/native/meta-launcher.h"
-
-#define META_TYPE_DEVICE_POOL (meta_device_pool_get_type ())
-G_DECLARE_FINAL_TYPE (MetaDevicePool, meta_device_pool,
- META, DEVICE_POOL,
- GObject)
-
-MetaDevicePool * meta_device_pool_new (MetaLauncher *launcher);
-
-#endif /* META_DEVICE_POOL_PRIVATE_H */
diff --git a/src/backends/native/meta-device-pool.c b/src/backends/native/meta-device-pool.c
deleted file mode 100644
index 8bbbe3e34..000000000
--- a/src/backends/native/meta-device-pool.c
+++ /dev/null
@@ -1,390 +0,0 @@
-/*
- * Copyright (C) 2013-2021 Red Hat, Inc.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-
-#include "config.h"
-
-#include "backends/native/meta-device-pool-private.h"
-
-#include <fcntl.h>
-#include <gio/gunixfdlist.h>
-#include <sys/stat.h>
-#include <sys/stat.h>
-#include <sys/sysmacros.h>
-#include <sys/types.h>
-
-#include "backends/native/meta-launcher.h"
-#include "meta/util.h"
-
-#include "meta-dbus-login1.h"
-
-struct _MetaDeviceFile
-{
- MetaDevicePool *pool;
-
- grefcount ref_count;
-
- char *path;
- int major;
- int minor;
- int fd;
- MetaDeviceFileFlags flags;
- uint32_t tags[META_DEVICE_FILE_N_TAGS];
-};
-
-struct _MetaDevicePool
-{
- GObject parent;
-
- MetaDbusLogin1Session *session_proxy;
-
- GMutex mutex;
-
- GList *files;
-};
-
-G_DEFINE_TYPE (MetaDevicePool, meta_device_pool, G_TYPE_OBJECT)
-
-static void
-release_device_file (MetaDevicePool *pool,
- MetaDeviceFile *file);
-
-static MetaDeviceFile *
-meta_device_file_new (MetaDevicePool *pool,
- const char *path,
- int major,
- int minor,
- int fd,
- MetaDeviceFileFlags flags)
-{
- MetaDeviceFile *file;
-
- file = g_new0 (MetaDeviceFile, 1);
-
- file->pool = pool;
- g_ref_count_init (&file->ref_count);
-
- file->path = g_strdup (path);
- file->major = major;
- file->minor = minor;
- file->fd = fd;
- file->flags = flags;
-
- return file;
-}
-
-static void
-meta_device_file_free (MetaDeviceFile *file)
-{
- g_free (file->path);
- g_free (file);
-}
-
-int
-meta_device_file_get_fd (MetaDeviceFile *device_file)
-{
- g_assert (!g_ref_count_compare (&device_file->ref_count, 0));
-
- return device_file->fd;
-}
-
-const char *
-meta_device_file_get_path (MetaDeviceFile *device_file)
-{
- return device_file->path;
-}
-
-void
-meta_device_file_tag (MetaDeviceFile *device_file,
- MetaDeviceFileTags tag,
- uint32_t value)
-{
- device_file->tags[tag] |= value;
-}
-
-uint32_t
-meta_device_file_has_tag (MetaDeviceFile *device_file,
- MetaDeviceFileTags tag,
- uint32_t value)
-{
- return (device_file->tags[tag] & value) == value;
-}
-
-static MetaDeviceFile *
-meta_device_file_acquire_locked (MetaDeviceFile *file)
-{
- g_ref_count_inc (&file->ref_count);
- return file;
-}
-
-MetaDeviceFile *
-meta_device_file_acquire (MetaDeviceFile *file)
-{
- g_mutex_lock (&file->pool->mutex);
- meta_topic (META_DEBUG_BACKEND, "Acquiring device file '%s'", file->path);
- meta_device_file_acquire_locked (file);
- g_mutex_unlock (&file->pool->mutex);
-
- return file;
-}
-
-void
-meta_device_file_release (MetaDeviceFile *file)
-{
- g_warn_if_fail (file->fd != -1);
-
- release_device_file (file->pool, file);
-}
-
-MetaDevicePool *
-meta_device_file_get_pool (MetaDeviceFile *device_file)
-{
- return device_file->pool;
-}
-
-static MetaDeviceFile *
-find_device_file_from_path (MetaDevicePool *pool,
- const char *path)
-{
- GList *l;
-
- for (l = pool->files; l; l = l->next)
- {
- MetaDeviceFile *file = l->data;
-
- if (g_strcmp0 (file->path, path) == 0)
- return file;
- }
-
- return NULL;
-}
-
-static gboolean
-take_device (MetaDbusLogin1Session *session_proxy,
- int dev_major,
- int dev_minor,
- int *out_fd,
- GCancellable *cancellable,
- GError **error)
-{
- g_autoptr (GVariant) fd_variant = NULL;
- g_autoptr (GUnixFDList) fd_list = NULL;
- int fd = -1;
-
- if (!meta_dbus_login1_session_call_take_device_sync (session_proxy,
- dev_major,
- dev_minor,
- NULL,
- &fd_variant,
- NULL, /* paused */
- &fd_list,
- cancellable,
- error))
- return FALSE;
-
- fd = g_unix_fd_list_get (fd_list, g_variant_get_handle (fd_variant), error);
- if (fd == -1)
- return FALSE;
-
- *out_fd = fd;
- return TRUE;
-}
-
-static gboolean
-get_device_info_from_path (const char *path,
- int *out_major,
- int *out_minor)
-{
- int ret;
- struct stat st;
-
- ret = stat (path, &st);
- if (ret < 0 || !S_ISCHR (st.st_mode))
- return FALSE;
-
- *out_major = major (st.st_rdev);
- *out_minor = minor (st.st_rdev);
- return TRUE;
-}
-
-MetaDeviceFile *
-meta_device_pool_open (MetaDevicePool *pool,
- const char *path,
- MetaDeviceFileFlags flags,
- GError **error)
-{
- g_autoptr (GMutexLocker) locker = NULL;
- MetaDeviceFile *file;
- int major = -1, minor = -1;
- int fd;
-
- locker = g_mutex_locker_new (&pool->mutex);
-
- file = find_device_file_from_path (pool, path);
- if (file)
- {
- g_warn_if_fail (file->flags == flags);
- meta_device_file_acquire_locked (file);
- return file;
- }
-
- if (flags & META_DEVICE_FILE_FLAG_TAKE_CONTROL)
- {
- meta_topic (META_DEBUG_BACKEND,
- "Opening and taking control of device file '%s'",
- path);
-
- if (!pool->session_proxy)
- {
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
- "Can't take control without logind session");
- return NULL;
- }
-
- if (!get_device_info_from_path (path, &major, &minor))
- {
- g_set_error (error,
- G_IO_ERROR,
- G_IO_ERROR_NOT_FOUND,
- "Could not get device info for path %s: %m", path);
- return NULL;
- }
-
- if (!take_device (pool->session_proxy, major, minor, &fd, NULL, error))
- return NULL;
- }
- else
- {
- int open_flags;
-
- meta_topic (META_DEBUG_BACKEND,
- "Opening device file '%s'",
- path);
-
- if (flags & META_DEVICE_FILE_FLAG_READ_ONLY)
- open_flags = O_RDONLY;
- else
- open_flags = O_RDWR;
- open_flags |= O_CLOEXEC;
-
- do
- {
- fd = open (path, open_flags);
- }
- while (fd == -1 && errno == EINTR);
-
- if (fd == -1)
- {
- g_set_error (error, G_IO_ERROR, g_io_error_from_errno (errno),
- "Failed to open device '%s': %s",
- path, g_strerror (errno));
- return NULL;
- }
- }
-
- file = meta_device_file_new (pool, path, major, minor, fd, flags);
- pool->files = g_list_prepend (pool->files, file);
-
- return file;
-}
-
-static void
-release_device_file (MetaDevicePool *pool,
- MetaDeviceFile *file)
-{
- g_autoptr (GMutexLocker) locker = NULL;
- g_autoptr (GError) error = NULL;
-
- locker = g_mutex_locker_new (&pool->mutex);
-
- meta_topic (META_DEBUG_BACKEND, "Releasing device file '%s'", file->path);
-
- if (!g_ref_count_dec (&file->ref_count))
- return;
-
- pool->files = g_list_remove (pool->files, file);
-
- if (file->flags & META_DEVICE_FILE_FLAG_TAKE_CONTROL)
- {
- MetaDbusLogin1Session *session_proxy;
-
- meta_topic (META_DEBUG_BACKEND,
- "Releasing control of and closing device file '%s'",
- file->path);
-
- session_proxy = pool->session_proxy;
- if (!meta_dbus_login1_session_call_release_device_sync (session_proxy,
- file->major,
- file->minor,
- NULL, &error))
- {
- g_warning ("Could not release device '%s' (%d,%d): %s",
- file->path,
- file->major, file->minor,
- error->message);
- }
- }
- else
- {
- meta_topic (META_DEBUG_BACKEND,
- "Closing device file '%s'",
- file->path);
- }
-
- close (file->fd);
-
- meta_device_file_free (file);
-}
-
-MetaDevicePool *
-meta_device_pool_new (MetaLauncher *launcher)
-{
- MetaDevicePool *pool;
-
- pool = g_object_new (META_TYPE_DEVICE_POOL, NULL);
-
- if (launcher)
- pool->session_proxy = meta_launcher_get_session_proxy (launcher);
-
- return pool;
-}
-
-static void
-meta_device_pool_finalize (GObject *object)
-{
- MetaDevicePool *pool = META_DEVICE_POOL (object);
-
- g_mutex_clear (&pool->mutex);
- g_warn_if_fail (!pool->files);
-
- G_OBJECT_CLASS (meta_device_pool_parent_class)->finalize (object);
-}
-
-static void
-meta_device_pool_init (MetaDevicePool *pool)
-{
- g_mutex_init (&pool->mutex);
-}
-
-static void
-meta_device_pool_class_init (MetaDevicePoolClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- object_class->finalize = meta_device_pool_finalize;
-}
diff --git a/src/backends/native/meta-device-pool.h b/src/backends/native/meta-device-pool.h
deleted file mode 100644
index 0e9653bd6..000000000
--- a/src/backends/native/meta-device-pool.h
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * Copyright (C) 2021 Red Hat, Inc.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-
-#ifndef META_DEVICE_POOL_H
-#define META_DEVICE_POOL_H
-
-#include <glib-object.h>
-#include <stdint.h>
-
-typedef enum _MetaDeviceFileFlags
-{
- META_DEVICE_FILE_FLAG_NONE = 0,
- META_DEVICE_FILE_FLAG_TAKE_CONTROL = 1 << 0,
- META_DEVICE_FILE_FLAG_READ_ONLY = 1 << 1,
-} MetaDeviceFileFlags;
-
-typedef enum _MetaDeviceFileTags
-{
- META_DEVICE_FILE_TAG_KMS,
-
- META_DEVICE_FILE_N_TAGS,
-} MetaDeviceFileTags;
-
-typedef struct _MetaDeviceFile MetaDeviceFile;
-typedef struct _MetaDevicePool MetaDevicePool;
-
-int meta_device_file_get_fd (MetaDeviceFile *device_file);
-
-const char * meta_device_file_get_path (MetaDeviceFile *device_file);
-
-void meta_device_file_tag (MetaDeviceFile *device_file,
- MetaDeviceFileTags tag,
- uint32_t value);
-
-uint32_t meta_device_file_has_tag (MetaDeviceFile *device_file,
- MetaDeviceFileTags tag,
- uint32_t value);
-
-MetaDeviceFile * meta_device_file_acquire (MetaDeviceFile *file);
-
-void meta_device_file_release (MetaDeviceFile *device_file);
-
-MetaDevicePool * meta_device_file_get_pool (MetaDeviceFile *device_file);
-
-MetaDeviceFile * meta_device_pool_open (MetaDevicePool *pool,
- const char *path,
- MetaDeviceFileFlags flags,
- GError **error);
-
-G_DEFINE_AUTOPTR_CLEANUP_FUNC (MetaDeviceFile, meta_device_file_release)
-
-#endif /* META_DEVICE_FILE_POOL_H */
diff --git a/src/backends/native/meta-drm-buffer-dumb.c b/src/backends/native/meta-drm-buffer-dumb.c
deleted file mode 100644
index d2fcad2f0..000000000
--- a/src/backends/native/meta-drm-buffer-dumb.c
+++ /dev/null
@@ -1,287 +0,0 @@
-/*
- * Copyright (C) 2011 Intel Corporation.
- * Copyright (C) 2016 Red Hat
- * Copyright (C) 2018 DisplayLink (UK) Ltd.
- * Copyright (C) 2018 Canonical Ltd.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- */
-
-#include "config.h"
-
-#include "backends/native/meta-drm-buffer-dumb.h"
-
-#include <gio/gio.h>
-#include <xf86drm.h>
-#include <fcntl.h>
-#include <sys/mman.h>
-
-#include "backends/native/meta-device-pool.h"
-
-struct _MetaDrmBufferDumb
-{
- MetaDrmBuffer parent;
-
- uint32_t handle;
- void *map;
- uint64_t map_size;
- int width;
- int height;
- int stride_bytes;
- uint32_t drm_format;
- int dmabuf_fd;
-};
-
-G_DEFINE_TYPE (MetaDrmBufferDumb, meta_drm_buffer_dumb, META_TYPE_DRM_BUFFER)
-
-static int
-meta_drm_buffer_dumb_get_width (MetaDrmBuffer *buffer)
-{
- MetaDrmBufferDumb *buffer_dumb = META_DRM_BUFFER_DUMB (buffer);
-
- return buffer_dumb->width;
-}
-
-static int
-meta_drm_buffer_dumb_get_height (MetaDrmBuffer *buffer)
-{
- MetaDrmBufferDumb *buffer_dumb = META_DRM_BUFFER_DUMB (buffer);
-
- return buffer_dumb->height;
-}
-
-static int
-meta_drm_buffer_dumb_get_stride (MetaDrmBuffer *buffer)
-{
- MetaDrmBufferDumb *buffer_dumb = META_DRM_BUFFER_DUMB (buffer);
-
- return buffer_dumb->stride_bytes;
-}
-
-static uint32_t
-meta_drm_buffer_dumb_get_format (MetaDrmBuffer *buffer)
-{
- MetaDrmBufferDumb *buffer_dumb = META_DRM_BUFFER_DUMB (buffer);
-
- return buffer_dumb->drm_format;
-}
-
-static int
-handle_to_dmabuf_fd (MetaDrmBufferDumb *buffer_dumb,
- GError **error)
-{
- MetaDrmBuffer *buffer = META_DRM_BUFFER (buffer_dumb);
- MetaDeviceFile *device_file;
- int fd;
- int ret;
- int dmabuf_fd;
-
- device_file = meta_drm_buffer_get_device_file (buffer);
- fd = meta_device_file_get_fd (device_file);
-
- ret = drmPrimeHandleToFD (fd, buffer_dumb->handle, DRM_CLOEXEC,
- &dmabuf_fd);
- if (ret)
- {
- g_set_error (error, G_IO_ERROR, g_io_error_from_errno (-ret),
- "drmPrimeHandleToFd: %s", g_strerror (-ret));
- return -1;
- }
-
- return dmabuf_fd;
-}
-
-int
-meta_drm_buffer_dumb_ensure_dmabuf_fd (MetaDrmBufferDumb *buffer_dumb,
- GError **error)
-{
- if (buffer_dumb->dmabuf_fd != -1)
- return buffer_dumb->dmabuf_fd;
-
- buffer_dumb->dmabuf_fd = handle_to_dmabuf_fd (buffer_dumb, error);
- return buffer_dumb->dmabuf_fd;
-}
-
-void *
-meta_drm_buffer_dumb_get_data (MetaDrmBufferDumb *buffer_dumb)
-{
- return buffer_dumb->map;
-}
-
-static gboolean
-init_dumb_buffer (MetaDrmBufferDumb *buffer_dumb,
- int width,
- int height,
- uint32_t format,
- GError **error)
-{
- MetaDrmBuffer *buffer = META_DRM_BUFFER (buffer_dumb);
- MetaDeviceFile *device_file;
- int fd;
- struct drm_mode_create_dumb create_arg;
- struct drm_mode_destroy_dumb destroy_arg;
- struct drm_mode_map_dumb map_arg;
- void *map;
- MetaDrmFbArgs fb_args;
-
- device_file = meta_drm_buffer_get_device_file (buffer);
- fd = meta_device_file_get_fd (device_file);
-
- create_arg = (struct drm_mode_create_dumb) {
- .bpp = 32, /* RGBX8888 */
- .width = width,
- .height = height
- };
- if (drmIoctl (fd, DRM_IOCTL_MODE_CREATE_DUMB, &create_arg) != 0)
- {
- g_set_error (error, G_IO_ERROR,
- G_IO_ERROR_FAILED,
- "Failed to create dumb drm buffer: %s",
- g_strerror (errno));
- goto err_ioctl;
- }
-
- fb_args = (MetaDrmFbArgs) {
- .width = width,
- .height = height,
- .format = format,
- .handles = { create_arg.handle },
- .strides = { create_arg.pitch },
- };
- if (!meta_drm_buffer_ensure_fb_id (buffer, FALSE, &fb_args, error))
- goto err_add_fb;
-
- map_arg = (struct drm_mode_map_dumb) {
- .handle = create_arg.handle
- };
- if (drmIoctl (fd, DRM_IOCTL_MODE_MAP_DUMB,
- &map_arg) != 0)
- {
- g_set_error (error, G_IO_ERROR,
- G_IO_ERROR_FAILED,
- "Failed to map dumb drm buffer: %s",
- g_strerror (errno));
- goto err_map_dumb;
- }
-
- map = mmap (NULL, create_arg.size, PROT_WRITE, MAP_SHARED,
- fd, map_arg.offset);
- if (map == MAP_FAILED)
- {
- g_set_error (error, G_IO_ERROR,
- G_IO_ERROR_FAILED,
- "Failed to mmap dumb drm buffer memory: %s",
- g_strerror (errno));
- goto err_mmap;
- }
-
- buffer_dumb->handle = create_arg.handle;
- buffer_dumb->map = map;
- buffer_dumb->map_size = create_arg.size;
- buffer_dumb->width = width;
- buffer_dumb->height = height;
- buffer_dumb->stride_bytes = create_arg.pitch;
- buffer_dumb->drm_format = format;
-
- return TRUE;
-
-err_mmap:
-err_map_dumb:
-err_add_fb:
- destroy_arg = (struct drm_mode_destroy_dumb) {
- .handle = create_arg.handle
- };
- drmIoctl (fd, DRM_IOCTL_MODE_DESTROY_DUMB, &destroy_arg);
-
-err_ioctl:
- return FALSE;
-}
-
-MetaDrmBufferDumb *
-meta_drm_buffer_dumb_new (MetaDeviceFile *device_file,
- int width,
- int height,
- uint32_t format,
- GError **error)
-{
- MetaDrmBufferDumb *buffer_dumb;
-
- buffer_dumb = g_object_new (META_TYPE_DRM_BUFFER_DUMB,
- "device-file", device_file,
- NULL);
-
- if (!init_dumb_buffer (buffer_dumb, width, height, format, error))
- {
- g_object_unref (buffer_dumb);
- return NULL;
- }
-
- return buffer_dumb;
-}
-
-static void
-destroy_dumb_buffer (MetaDrmBufferDumb *buffer_dumb)
-{
- MetaDrmBuffer *buffer = META_DRM_BUFFER (buffer_dumb);
- MetaDeviceFile *device_file;
- int fd;
- struct drm_mode_destroy_dumb destroy_arg;
-
- device_file = meta_drm_buffer_get_device_file (buffer);
- fd = meta_device_file_get_fd (device_file);
-
- munmap (buffer_dumb->map, buffer_dumb->map_size);
-
- destroy_arg = (struct drm_mode_destroy_dumb) {
- .handle = buffer_dumb->handle
- };
- drmIoctl (fd, DRM_IOCTL_MODE_DESTROY_DUMB, &destroy_arg);
-
- if (buffer_dumb->dmabuf_fd != -1)
- close (buffer_dumb->dmabuf_fd);
-}
-
-static void
-meta_drm_buffer_dumb_finalize (GObject *object)
-{
- MetaDrmBufferDumb *buffer_dumb = META_DRM_BUFFER_DUMB (object);
-
- if (buffer_dumb->handle)
- destroy_dumb_buffer (buffer_dumb);
-
- G_OBJECT_CLASS (meta_drm_buffer_dumb_parent_class)->finalize (object);
-}
-
-static void
-meta_drm_buffer_dumb_init (MetaDrmBufferDumb *buffer_dumb)
-{
- buffer_dumb->dmabuf_fd = -1;
-}
-
-static void
-meta_drm_buffer_dumb_class_init (MetaDrmBufferDumbClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
- MetaDrmBufferClass *buffer_class = META_DRM_BUFFER_CLASS (klass);
-
- object_class->finalize = meta_drm_buffer_dumb_finalize;
-
- buffer_class->get_width = meta_drm_buffer_dumb_get_width;
- buffer_class->get_height = meta_drm_buffer_dumb_get_height;
- buffer_class->get_stride = meta_drm_buffer_dumb_get_stride;
- buffer_class->get_format = meta_drm_buffer_dumb_get_format;
-}
diff --git a/src/backends/native/meta-drm-buffer-dumb.h b/src/backends/native/meta-drm-buffer-dumb.h
deleted file mode 100644
index afc14660b..000000000
--- a/src/backends/native/meta-drm-buffer-dumb.h
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Copyright (C) 2018 Canonical Ltd.
- * Copyright (C) 2019 Red Hat Inc.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- */
-
-#ifndef META_DRM_BUFFER_DUMB_H
-#define META_DRM_BUFFER_DUMB_H
-
-#include "backends/native/meta-backend-native-types.h"
-#include "backends/native/meta-drm-buffer-private.h"
-
-#define META_TYPE_DRM_BUFFER_DUMB (meta_drm_buffer_dumb_get_type ())
-G_DECLARE_FINAL_TYPE (MetaDrmBufferDumb,
- meta_drm_buffer_dumb,
- META, DRM_BUFFER_DUMB,
- MetaDrmBuffer)
-
-MetaDrmBufferDumb * meta_drm_buffer_dumb_new (MetaDeviceFile *device,
- int width,
- int height,
- uint32_t format,
- GError **error);
-
-int meta_drm_buffer_dumb_ensure_dmabuf_fd (MetaDrmBufferDumb *buffer_dumb,
- GError **error);
-
-void * meta_drm_buffer_dumb_get_data (MetaDrmBufferDumb *buffer_dumb);
-
-#endif /* META_DRM_BUFFER_DUMB_H */
diff --git a/src/backends/native/meta-drm-buffer-gbm.c b/src/backends/native/meta-drm-buffer-gbm.c
deleted file mode 100644
index f011afaca..000000000
--- a/src/backends/native/meta-drm-buffer-gbm.c
+++ /dev/null
@@ -1,474 +0,0 @@
-/*
- * Copyright (C) 2011 Intel Corporation.
- * Copyright (C) 2016 Red Hat
- * Copyright (C) 2018 DisplayLink (UK) Ltd.
- * Copyright (C) 2018 Canonical Ltd.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- */
-
-#include "config.h"
-
-#include "backends/native/meta-drm-buffer-gbm.h"
-
-#include <drm_fourcc.h>
-#include <errno.h>
-#include <gio/gio.h>
-#include <xf86drm.h>
-#include <xf86drmMode.h>
-
-#include "backends/meta-backend-private.h"
-#include "backends/native/meta-cogl-utils.h"
-#include "backends/native/meta-drm-buffer-private.h"
-
-struct _MetaDrmBufferGbm
-{
- MetaDrmBuffer parent;
-
- struct gbm_surface *surface;
-
- struct gbm_bo *bo;
-};
-
-static void
-cogl_scanout_iface_init (CoglScanoutInterface *iface);
-
-G_DEFINE_TYPE_WITH_CODE (MetaDrmBufferGbm, meta_drm_buffer_gbm, META_TYPE_DRM_BUFFER,
- G_IMPLEMENT_INTERFACE (COGL_TYPE_SCANOUT,
- cogl_scanout_iface_init))
-
-struct gbm_bo *
-meta_drm_buffer_gbm_get_bo (MetaDrmBufferGbm *buffer_gbm)
-{
- return buffer_gbm->bo;
-}
-
-static int
-meta_drm_buffer_gbm_get_width (MetaDrmBuffer *buffer)
-{
- MetaDrmBufferGbm *buffer_gbm = META_DRM_BUFFER_GBM (buffer);
-
- return gbm_bo_get_width (buffer_gbm->bo);
-}
-
-static int
-meta_drm_buffer_gbm_get_height (MetaDrmBuffer *buffer)
-{
- MetaDrmBufferGbm *buffer_gbm = META_DRM_BUFFER_GBM (buffer);
-
- return gbm_bo_get_height (buffer_gbm->bo);
-}
-
-static int
-meta_drm_buffer_gbm_get_stride (MetaDrmBuffer *buffer)
-{
- MetaDrmBufferGbm *buffer_gbm = META_DRM_BUFFER_GBM (buffer);
-
- return gbm_bo_get_stride (buffer_gbm->bo);
-}
-
-static uint32_t
-meta_drm_buffer_gbm_get_format (MetaDrmBuffer *buffer)
-{
- MetaDrmBufferGbm *buffer_gbm = META_DRM_BUFFER_GBM (buffer);
-
- return gbm_bo_get_format (buffer_gbm->bo);
-}
-
-static gboolean
-init_fb_id (MetaDrmBufferGbm *buffer_gbm,
- struct gbm_bo *bo,
- gboolean use_modifiers,
- GError **error)
-{
- MetaDrmFbArgs fb_args = { 0, };
-
- if (gbm_bo_get_handle_for_plane (bo, 0).s32 == -1)
- {
- /* Failed to fetch handle to plane, falling back to old method */
- fb_args.strides[0] = gbm_bo_get_stride (bo);
- fb_args.handles[0] = gbm_bo_get_handle (bo).u32;
- fb_args.offsets[0] = 0;
- fb_args.modifiers[0] = DRM_FORMAT_MOD_INVALID;
- }
- else
- {
- int i;
-
- for (i = 0; i < gbm_bo_get_plane_count (bo); i++)
- {
- fb_args.strides[i] = gbm_bo_get_stride_for_plane (bo, i);
- fb_args.handles[i] = gbm_bo_get_handle_for_plane (bo, i).u32;
- fb_args.offsets[i] = gbm_bo_get_offset (bo, i);
- fb_args.modifiers[i] = gbm_bo_get_modifier (bo);
- }
- }
-
- fb_args.width = gbm_bo_get_width (bo);
- fb_args.height = gbm_bo_get_height (bo);
- fb_args.format = gbm_bo_get_format (bo);
-
- if (!meta_drm_buffer_ensure_fb_id (META_DRM_BUFFER (buffer_gbm),
- use_modifiers, &fb_args, error))
- return FALSE;
-
- return TRUE;
-}
-
-static gboolean
-lock_front_buffer (MetaDrmBufferGbm *buffer_gbm,
- gboolean use_modifiers,
- GError **error)
-{
- buffer_gbm->bo = gbm_surface_lock_front_buffer (buffer_gbm->surface);
- if (!buffer_gbm->bo)
- {
- g_set_error (error,
- G_IO_ERROR,
- G_IO_ERROR_FAILED,
- "gbm_surface_lock_front_buffer failed");
- return FALSE;
- }
-
- return init_fb_id (buffer_gbm, buffer_gbm->bo, use_modifiers, error);
-}
-
-MetaDrmBufferGbm *
-meta_drm_buffer_gbm_new_lock_front (MetaDeviceFile *device_file,
- struct gbm_surface *gbm_surface,
- gboolean use_modifiers,
- GError **error)
-{
- MetaDrmBufferGbm *buffer_gbm;
-
- buffer_gbm = g_object_new (META_TYPE_DRM_BUFFER_GBM,
- "device-file", device_file,
- NULL);
- buffer_gbm->surface = gbm_surface;
-
- if (!lock_front_buffer (buffer_gbm, use_modifiers, error))
- {
- g_object_unref (buffer_gbm);
- return NULL;
- }
-
- return buffer_gbm;
-}
-
-MetaDrmBufferGbm *
-meta_drm_buffer_gbm_new_take (MetaDeviceFile *device_file,
- struct gbm_bo *bo,
- gboolean use_modifiers,
- GError **error)
-{
- MetaDrmBufferGbm *buffer_gbm;
-
- buffer_gbm = g_object_new (META_TYPE_DRM_BUFFER_GBM,
- "device-file", device_file,
- NULL);
-
- if (!init_fb_id (buffer_gbm, bo, use_modifiers, error))
- {
- g_object_unref (buffer_gbm);
- return NULL;
- }
-
- buffer_gbm->bo = bo;
-
- return buffer_gbm;
-}
-
-static gboolean
-meta_drm_buffer_gbm_fill_timings (MetaDrmBuffer *buffer,
- CoglFrameInfo *info,
- GError **error)
-{
- MetaDrmBufferGbm *buffer_gbm = META_DRM_BUFFER_GBM (buffer);
- MetaBackend *backend = meta_get_backend ();
- MetaEgl *egl = meta_backend_get_egl (backend);
- ClutterBackend *clutter_backend =
- meta_backend_get_clutter_backend (backend);
- CoglContext *cogl_context =
- clutter_backend_get_cogl_context (clutter_backend);
- CoglDisplay *cogl_display = cogl_context->display;
- CoglRenderer *cogl_renderer = cogl_display->renderer;
- CoglRendererEGL *cogl_renderer_egl = cogl_renderer->winsys;
- EGLDisplay egl_display = cogl_renderer_egl->edpy;
- EGLImageKHR egl_image;
- CoglPixelFormat cogl_format;
- CoglEglImageFlags flags;
- g_autoptr (CoglOffscreen) cogl_fbo = NULL;
- CoglTexture2D *cogl_tex;
- uint32_t n_planes;
- uint64_t *modifiers;
- uint32_t *strides;
- uint32_t *offsets;
- uint32_t width;
- uint32_t height;
- uint32_t drm_format;
- int *fds;
- gboolean result;
- int dmabuf_fd = -1;
- uint32_t i;
-
- dmabuf_fd = gbm_bo_get_fd (buffer_gbm->bo);
- if (dmabuf_fd == -1)
- {
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- "Failed to export buffer's DMA fd: %s",
- g_strerror (errno));
- return FALSE;
- }
-
- drm_format = gbm_bo_get_format (buffer_gbm->bo);
- result = meta_cogl_pixel_format_from_drm_format (drm_format,
- &cogl_format,
- NULL);
- g_assert (result);
-
- width = gbm_bo_get_width (buffer_gbm->bo);
- height = gbm_bo_get_height (buffer_gbm->bo);
- n_planes = gbm_bo_get_plane_count (buffer_gbm->bo);
- fds = g_alloca (sizeof (int) * n_planes);
- strides = g_alloca (sizeof (uint32_t) * n_planes);
- offsets = g_alloca (sizeof (uint32_t) * n_planes);
- modifiers = g_alloca (sizeof (uint64_t) * n_planes);
-
- for (i = 0; i < n_planes; i++)
- {
- fds[i] = dmabuf_fd;
- strides[i] = gbm_bo_get_stride_for_plane (buffer_gbm->bo, i);
- offsets[i] = gbm_bo_get_offset (buffer_gbm->bo, i);
- modifiers[i] = gbm_bo_get_modifier (buffer_gbm->bo);
- }
-
- egl_image = meta_egl_create_dmabuf_image (egl,
- egl_display,
- width,
- height,
- drm_format,
- n_planes,
- fds,
- strides,
- offsets,
- modifiers,
- error);
- if (egl_image == EGL_NO_IMAGE_KHR)
- goto out;
-
- flags = COGL_EGL_IMAGE_FLAG_NO_GET_DATA;
- cogl_tex = cogl_egl_texture_2d_new_from_image (cogl_context,
- width,
- height,
- cogl_format,
- egl_image,
- flags,
- error);
-
- meta_egl_destroy_image (egl, egl_display, egl_image, NULL);
-
- if (!cogl_tex)
- goto out;
-
- cogl_fbo = cogl_offscreen_new_with_texture (COGL_TEXTURE (cogl_tex));
- cogl_object_unref (cogl_tex);
-
- if (cogl_has_feature (cogl_context, COGL_FEATURE_ID_GET_GPU_TIME))
- {
- info->gpu_time_before_buffer_swap_ns =
- cogl_context_get_gpu_time_ns (cogl_context);
- }
-
- info->cpu_time_before_buffer_swap_us = g_get_monotonic_time ();
-
- /* Set up a timestamp query for when all rendering will be finished. */
- if (cogl_has_feature (cogl_context, COGL_FEATURE_ID_TIMESTAMP_QUERY))
- {
- info->timestamp_query =
- cogl_framebuffer_create_timestamp_query (COGL_FRAMEBUFFER (cogl_fbo));
- }
-
-out:
- close (dmabuf_fd);
-
- return TRUE;
-}
-
-static gboolean
-meta_drm_buffer_gbm_blit_to_framebuffer (CoglScanout *scanout,
- CoglFramebuffer *framebuffer,
- int x,
- int y,
- GError **error)
-{
- MetaDrmBufferGbm *buffer_gbm = META_DRM_BUFFER_GBM (scanout);
- MetaBackend *backend = meta_get_backend ();
- MetaEgl *egl = meta_backend_get_egl (backend);
- ClutterBackend *clutter_backend =
- meta_backend_get_clutter_backend (backend);
- CoglContext *cogl_context =
- clutter_backend_get_cogl_context (clutter_backend);
- CoglDisplay *cogl_display = cogl_context->display;
- CoglRenderer *cogl_renderer = cogl_display->renderer;
- CoglRendererEGL *cogl_renderer_egl = cogl_renderer->winsys;
- EGLDisplay egl_display = cogl_renderer_egl->edpy;
- EGLImageKHR egl_image;
- CoglPixelFormat cogl_format;
- CoglEglImageFlags flags;
- CoglOffscreen *cogl_fbo = NULL;
- CoglTexture2D *cogl_tex;
- uint32_t n_planes;
- uint64_t *modifiers;
- uint32_t *strides;
- uint32_t *offsets;
- uint32_t width;
- uint32_t height;
- uint32_t drm_format;
- int *fds;
- gboolean result;
- int dmabuf_fd = -1;
- uint32_t i;
-
- dmabuf_fd = gbm_bo_get_fd (buffer_gbm->bo);
- if (dmabuf_fd == -1)
- {
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_EXISTS,
- "Failed to export buffer's DMA fd: %s",
- g_strerror (errno));
- return FALSE;
- }
-
- drm_format = gbm_bo_get_format (buffer_gbm->bo);
- result = meta_cogl_pixel_format_from_drm_format (drm_format,
- &cogl_format,
- NULL);
- g_assert (result);
-
- width = gbm_bo_get_width (buffer_gbm->bo);
- height = gbm_bo_get_height (buffer_gbm->bo);
- n_planes = gbm_bo_get_plane_count (buffer_gbm->bo);
- fds = g_alloca (sizeof (int) * n_planes);
- strides = g_alloca (sizeof (uint32_t) * n_planes);
- offsets = g_alloca (sizeof (uint32_t) * n_planes);
- modifiers = g_alloca (sizeof (uint64_t) * n_planes);
-
- for (i = 0; i < n_planes; i++)
- {
- fds[i] = dmabuf_fd;
- strides[i] = gbm_bo_get_stride_for_plane (buffer_gbm->bo, i);
- offsets[i] = gbm_bo_get_offset (buffer_gbm->bo, i);
- modifiers[i] = gbm_bo_get_modifier (buffer_gbm->bo);
- }
-
- egl_image = meta_egl_create_dmabuf_image (egl,
- egl_display,
- width,
- height,
- drm_format,
- n_planes,
- fds,
- strides,
- offsets,
- modifiers,
- error);
- if (egl_image == EGL_NO_IMAGE_KHR)
- {
- result = FALSE;
- goto out;
- }
-
- flags = COGL_EGL_IMAGE_FLAG_NO_GET_DATA;
- cogl_tex = cogl_egl_texture_2d_new_from_image (cogl_context,
- width,
- height,
- cogl_format,
- egl_image,
- flags,
- error);
-
- meta_egl_destroy_image (egl, egl_display, egl_image, NULL);
-
- if (!cogl_tex)
- {
- result = FALSE;
- goto out;
- }
-
- cogl_fbo = cogl_offscreen_new_with_texture (COGL_TEXTURE (cogl_tex));
- cogl_object_unref (cogl_tex);
-
- if (!cogl_framebuffer_allocate (COGL_FRAMEBUFFER (cogl_fbo), error))
- {
- result = FALSE;
- goto out;
- }
-
- result = cogl_blit_framebuffer (COGL_FRAMEBUFFER (cogl_fbo),
- framebuffer,
- 0, 0,
- x, y,
- width, height,
- error);
-
-out:
- g_clear_object (&cogl_fbo);
- close (dmabuf_fd);
-
- return result;
-}
-
-static void
-cogl_scanout_iface_init (CoglScanoutInterface *iface)
-{
- iface->blit_to_framebuffer = meta_drm_buffer_gbm_blit_to_framebuffer;
-}
-
-static void
-meta_drm_buffer_gbm_finalize (GObject *object)
-{
- MetaDrmBufferGbm *buffer_gbm = META_DRM_BUFFER_GBM (object);
-
- if (buffer_gbm->bo)
- {
- if (buffer_gbm->surface)
- gbm_surface_release_buffer (buffer_gbm->surface, buffer_gbm->bo);
- else
- gbm_bo_destroy (buffer_gbm->bo);
- }
-
- G_OBJECT_CLASS (meta_drm_buffer_gbm_parent_class)->finalize (object);
-}
-
-static void
-meta_drm_buffer_gbm_init (MetaDrmBufferGbm *buffer_gbm)
-{
-}
-
-static void
-meta_drm_buffer_gbm_class_init (MetaDrmBufferGbmClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
- MetaDrmBufferClass *buffer_class = META_DRM_BUFFER_CLASS (klass);
-
- object_class->finalize = meta_drm_buffer_gbm_finalize;
-
- buffer_class->get_width = meta_drm_buffer_gbm_get_width;
- buffer_class->get_height = meta_drm_buffer_gbm_get_height;
- buffer_class->get_stride = meta_drm_buffer_gbm_get_stride;
- buffer_class->get_format = meta_drm_buffer_gbm_get_format;
- buffer_class->fill_timings = meta_drm_buffer_gbm_fill_timings;
-}
diff --git a/src/backends/native/meta-drm-buffer-gbm.h b/src/backends/native/meta-drm-buffer-gbm.h
deleted file mode 100644
index 0413c9fa2..000000000
--- a/src/backends/native/meta-drm-buffer-gbm.h
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Copyright (C) 2018 Canonical Ltd.
- * Copyright (C) 2019 Red Hat Inc.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- */
-
-#ifndef META_DRM_BUFFER_GBM_H
-#define META_DRM_BUFFER_GBM_H
-
-#include <gbm.h>
-
-#include "backends/native/meta-backend-native-types.h"
-#include "backends/native/meta-drm-buffer-private.h"
-
-#define META_TYPE_DRM_BUFFER_GBM (meta_drm_buffer_gbm_get_type ())
-G_DECLARE_FINAL_TYPE (MetaDrmBufferGbm,
- meta_drm_buffer_gbm,
- META, DRM_BUFFER_GBM,
- MetaDrmBuffer)
-
-MetaDrmBufferGbm * meta_drm_buffer_gbm_new_lock_front (MetaDeviceFile *device_file,
- struct gbm_surface *gbm_surface,
- gboolean use_modifiers,
- GError **error);
-
-
-MetaDrmBufferGbm * meta_drm_buffer_gbm_new_take (MetaDeviceFile *device_file,
- struct gbm_bo *gbm_bo,
- gboolean use_modifiers,
- GError **error);
-
-struct gbm_bo * meta_drm_buffer_gbm_get_bo (MetaDrmBufferGbm *buffer_gbm);
-
-#endif /* META_DRM_BUFFER_GBM_H */
diff --git a/src/backends/native/meta-drm-buffer-import.c b/src/backends/native/meta-drm-buffer-import.c
deleted file mode 100644
index 77cd138d2..000000000
--- a/src/backends/native/meta-drm-buffer-import.c
+++ /dev/null
@@ -1,209 +0,0 @@
-/*
- * Copyright (C) 2011 Intel Corporation.
- * Copyright (C) 2016,2017 Red Hat
- * Copyright (C) 2018,2019 DisplayLink (UK) Ltd.
- * Copyright (C) 2018 Canonical Ltd.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- */
-
-#include "config.h"
-
-#include "backends/native/meta-drm-buffer-import.h"
-
-#include <drm_fourcc.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <xf86drm.h>
-
-#include "backends/native/meta-drm-buffer-gbm.h"
-#include "backends/native/meta-kms-utils.h"
-#include "backends/native/meta-renderer-native.h"
-
-struct _MetaDrmBufferImport
-{
- MetaDrmBuffer parent;
-
- MetaDrmBufferGbm *importee;
-};
-
-G_DEFINE_TYPE (MetaDrmBufferImport, meta_drm_buffer_import,
- META_TYPE_DRM_BUFFER)
-
-static int
-meta_drm_buffer_import_get_width (MetaDrmBuffer *buffer)
-{
- MetaDrmBufferImport *buffer_import = META_DRM_BUFFER_IMPORT (buffer);
-
- return meta_drm_buffer_get_width (META_DRM_BUFFER (buffer_import->importee));
-}
-
-static int
-meta_drm_buffer_import_get_height (MetaDrmBuffer *buffer)
-{
- MetaDrmBufferImport *buffer_import = META_DRM_BUFFER_IMPORT (buffer);
-
- return meta_drm_buffer_get_height (META_DRM_BUFFER (buffer_import->importee));
-}
-
-static int
-meta_drm_buffer_import_get_stride (MetaDrmBuffer *buffer)
-{
- MetaDrmBufferImport *buffer_import = META_DRM_BUFFER_IMPORT (buffer);
-
- return meta_drm_buffer_get_stride (META_DRM_BUFFER (buffer_import->importee));
-}
-
-static uint32_t
-meta_drm_buffer_import_get_format (MetaDrmBuffer *buffer)
-{
- MetaDrmBufferImport *buffer_import = META_DRM_BUFFER_IMPORT (buffer);
-
- return meta_drm_buffer_get_format (META_DRM_BUFFER (buffer_import->importee));
-}
-
-static struct gbm_bo *
-dmabuf_to_gbm_bo (struct gbm_device *importer,
- int dmabuf_fd,
- uint32_t width,
- uint32_t height,
- uint32_t stride,
- uint32_t format)
-{
- struct gbm_import_fd_data data = {
- .fd = dmabuf_fd,
- .width = width,
- .height = height,
- .stride = stride,
- .format = format
- };
-
- return gbm_bo_import (importer,
- GBM_BO_IMPORT_FD,
- &data,
- GBM_BO_USE_SCANOUT);
-}
-
-static gboolean
-import_gbm_buffer (MetaDrmBufferImport *buffer_import,
- struct gbm_device *importer,
- GError **error)
-{
- MetaDrmFbArgs fb_args = { 0, };
- struct gbm_bo *primary_bo;
- struct gbm_bo *imported_bo;
- int dmabuf_fd;
- gboolean ret;
-
- primary_bo = meta_drm_buffer_gbm_get_bo (buffer_import->importee);
-
- dmabuf_fd = gbm_bo_get_fd (primary_bo);
- if (dmabuf_fd == -1)
- {
- g_set_error (error,
- G_IO_ERROR,
- G_IO_ERROR_FAILED,
- "getting dmabuf fd failed");
- return FALSE;
- }
-
- fb_args.strides[0] = gbm_bo_get_stride (primary_bo);
- fb_args.width = gbm_bo_get_width (primary_bo);
- fb_args.height = gbm_bo_get_height (primary_bo);
- fb_args.format = gbm_bo_get_format (primary_bo);
-
- imported_bo = dmabuf_to_gbm_bo (importer,
- dmabuf_fd,
- fb_args.width,
- fb_args.height,
- fb_args.strides[0],
- fb_args.format);
- if (!imported_bo)
- {
- g_set_error (error,
- G_IO_ERROR,
- G_IO_ERROR_FAILED,
- "importing dmabuf fd failed");
- ret = FALSE;
- goto out_close;
- }
-
- fb_args.handles[0] = gbm_bo_get_handle (imported_bo).u32;
-
- ret = meta_drm_buffer_ensure_fb_id (META_DRM_BUFFER (buffer_import),
- FALSE /* use_modifiers */,
- &fb_args,
- error);
-
- gbm_bo_destroy (imported_bo);
-
-out_close:
- close (dmabuf_fd);
-
- return ret;
-}
-
-MetaDrmBufferImport *
-meta_drm_buffer_import_new (MetaDeviceFile *device_file,
- struct gbm_device *gbm_device,
- MetaDrmBufferGbm *buffer_gbm,
- GError **error)
-{
- MetaDrmBufferImport *buffer_import;
-
- buffer_import = g_object_new (META_TYPE_DRM_BUFFER_IMPORT,
- "device-file", device_file,
- NULL);
- g_set_object (&buffer_import->importee, buffer_gbm);
-
- if (!import_gbm_buffer (buffer_import, gbm_device, error))
- {
- g_object_unref (buffer_import);
- return NULL;
- }
-
- return buffer_import;
-}
-
-static void
-meta_drm_buffer_import_finalize (GObject *object)
-{
- MetaDrmBufferImport *buffer_import = META_DRM_BUFFER_IMPORT (object);
-
- g_clear_object (&buffer_import->importee);
-
- G_OBJECT_CLASS (meta_drm_buffer_import_parent_class)->finalize (object);
-}
-
-static void
-meta_drm_buffer_import_init (MetaDrmBufferImport *buffer_import)
-{
-}
-
-static void
-meta_drm_buffer_import_class_init (MetaDrmBufferImportClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
- MetaDrmBufferClass *buffer_class = META_DRM_BUFFER_CLASS (klass);
-
- object_class->finalize = meta_drm_buffer_import_finalize;
-
- buffer_class->get_width = meta_drm_buffer_import_get_width;
- buffer_class->get_height = meta_drm_buffer_import_get_height;
- buffer_class->get_stride = meta_drm_buffer_import_get_stride;
- buffer_class->get_format = meta_drm_buffer_import_get_format;
-}
diff --git a/src/backends/native/meta-drm-buffer-import.h b/src/backends/native/meta-drm-buffer-import.h
deleted file mode 100644
index faff560fa..000000000
--- a/src/backends/native/meta-drm-buffer-import.h
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Copyright (C) 2018 Canonical Ltd.
- * Copyright (C) 2019 Red Hat Inc.
- * Copyright (C) 2019 DisplayLink (UK) Ltd.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- */
-
-#ifndef META_DRM_BUFFER_IMPORT_H
-#define META_DRM_BUFFER_IMPORT_H
-
-#include <gbm.h>
-
-#include "backends/native/meta-drm-buffer.h"
-#include "backends/native/meta-drm-buffer-gbm.h"
-#include "backends/native/meta-gpu-kms.h"
-
-#define META_TYPE_DRM_BUFFER_IMPORT (meta_drm_buffer_import_get_type ())
-G_DECLARE_FINAL_TYPE (MetaDrmBufferImport,
- meta_drm_buffer_import,
- META, DRM_BUFFER_IMPORT,
- MetaDrmBuffer)
-
-/*
- * MetaDrmBufferImport is a buffer that refers to the storage of a
- * MetaDrmBufferGbm buffer on another MetaGpuKms.
- *
- * When creating an imported buffer, the given GBM buffer is exported
- * as a dma_buf and then imported to the given MetaGpuKms. A reference
- * is kept to the GBM buffer so that it won't disappear while the
- * imported buffer exists.
- *
- * The import has a high chance of failing under normal operating
- * conditions and needs to be handled with fallbacks to something else.
- */
-MetaDrmBufferImport * meta_drm_buffer_import_new (MetaDeviceFile *device_file,
- struct gbm_device *gbm_device,
- MetaDrmBufferGbm *buffer_gbm,
- GError **error);
-
-#endif /* META_DRM_BUFFER_IMPORT_H */
diff --git a/src/backends/native/meta-drm-buffer-private.h b/src/backends/native/meta-drm-buffer-private.h
deleted file mode 100644
index a54ce7c31..000000000
--- a/src/backends/native/meta-drm-buffer-private.h
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * Copyright (C) 2018 Canonical Ltd.
- * Copyright (C) 2019-2020 Red Hat Inc.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-
-#ifndef META_DRM_BUFFER_PRIVATE_H
-#define META_DRM_BUFFER_PRIVATE_H
-
-#include "backends/native/meta-backend-native-types.h"
-#include "backends/native/meta-drm-buffer.h"
-
-typedef struct _MetaDrmFbArgs
-{
- uint32_t width;
- uint32_t height;
- uint32_t format;
- uint32_t handles[4];
- uint32_t offsets[4];
- uint32_t strides[4];
- uint64_t modifiers[4];
-} MetaDrmFbArgs;
-
-struct _MetaDrmBufferClass
-{
- GObjectClass parent_class;
-
- int (* get_width) (MetaDrmBuffer *buffer);
- int (* get_height) (MetaDrmBuffer *buffer);
- int (* get_stride) (MetaDrmBuffer *buffer);
- uint32_t (* get_format) (MetaDrmBuffer *buffer);
-
- gboolean (* fill_timings) (MetaDrmBuffer *buffer,
- CoglFrameInfo *info,
- GError **error);
-};
-
-MetaDeviceFile * meta_drm_buffer_get_device_file (MetaDrmBuffer *buffer);
-
-gboolean meta_drm_buffer_ensure_fb_id (MetaDrmBuffer *buffer,
- gboolean use_modifiers,
- const MetaDrmFbArgs *fb_args,
- GError **error);
-
-gboolean meta_drm_buffer_ensure_fb_in_impl (MetaDrmBuffer *buffer,
- gboolean use_modifiers,
- const MetaDrmFbArgs *fb_args,
- GError **error);
-
-#endif /* META_DRM_BUFFER_PRIVATE_H */
diff --git a/src/backends/native/meta-drm-buffer.c b/src/backends/native/meta-drm-buffer.c
deleted file mode 100644
index 1da622037..000000000
--- a/src/backends/native/meta-drm-buffer.c
+++ /dev/null
@@ -1,296 +0,0 @@
-/*
- * Copyright (C) 2011 Intel Corporation.
- * Copyright (C) 2016-2020 Red Hat
- * Copyright (C) 2018 DisplayLink (UK) Ltd.
- * Copyright (C) 2018 Canonical Ltd.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Author: Daniel van Vugt <daniel.van.vugt@canonical.com>
- */
-
-#include "config.h"
-
-#include "backends/native/meta-drm-buffer-private.h"
-
-#include <drm_fourcc.h>
-
-#include "backends/native/meta-device-pool.h"
-#include "backends/native/meta-kms-utils.h"
-
-#define INVALID_FB_ID 0U
-
-enum
-{
- PROP_0,
-
- PROP_DEVICE_FILE,
-
- N_PROPS
-};
-
-static GParamSpec *obj_props[N_PROPS];
-
-typedef struct _MetaDrmBufferPrivate
-{
- MetaDeviceFile *device_file;
- uint32_t fb_id;
-} MetaDrmBufferPrivate;
-
-G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (MetaDrmBuffer, meta_drm_buffer,
- G_TYPE_OBJECT)
-
-MetaDeviceFile *
-meta_drm_buffer_get_device_file (MetaDrmBuffer *buffer)
-{
- MetaDrmBufferPrivate *priv = meta_drm_buffer_get_instance_private (buffer);
-
- return priv->device_file;
-}
-
-gboolean
-meta_drm_buffer_ensure_fb_id (MetaDrmBuffer *buffer,
- gboolean use_modifiers,
- const MetaDrmFbArgs *fb_args,
- GError **error)
-{
- MetaDrmBufferPrivate *priv = meta_drm_buffer_get_instance_private (buffer);
- int fd;
- MetaDrmFormatBuf tmp;
- uint32_t fb_id;
-
- fd = meta_device_file_get_fd (priv->device_file);
-
- if (use_modifiers && fb_args->modifiers[0] != DRM_FORMAT_MOD_INVALID)
- {
- if (drmModeAddFB2WithModifiers (fd,
- fb_args->width,
- fb_args->height,
- fb_args->format,
- fb_args->handles,
- fb_args->strides,
- fb_args->offsets,
- fb_args->modifiers,
- &fb_id,
- DRM_MODE_FB_MODIFIERS))
- {
- g_set_error (error,
- G_IO_ERROR,
- g_io_error_from_errno (errno),
- "drmModeAddFB2WithModifiers failed: %s",
- g_strerror (errno));
- return FALSE;
- }
- }
- else if (drmModeAddFB2 (fd,
- fb_args->width,
- fb_args->height,
- fb_args->format,
- fb_args->handles,
- fb_args->strides,
- fb_args->offsets,
- &fb_id,
- 0))
- {
- if (fb_args->format != DRM_FORMAT_XRGB8888)
- {
- g_set_error (error,
- G_IO_ERROR,
- G_IO_ERROR_FAILED,
- "drmModeAddFB does not support format '%s' (0x%x)",
- meta_drm_format_to_string (&tmp, fb_args->format),
- fb_args->format);
- return FALSE;
- }
-
- if (drmModeAddFB (fd,
- fb_args->width,
- fb_args->height,
- 24,
- 32,
- fb_args->strides[0],
- fb_args->handles[0],
- &fb_id))
- {
- g_set_error (error,
- G_IO_ERROR,
- g_io_error_from_errno (errno),
- "drmModeAddFB failed: %s",
- g_strerror (errno));
- return FALSE;
- }
- }
-
- priv->fb_id = fb_id;
- return TRUE;
-}
-
-static void
-meta_drm_buffer_release_fb_id (MetaDrmBuffer *buffer)
-{
- MetaDrmBufferPrivate *priv = meta_drm_buffer_get_instance_private (buffer);
- int fd;
- int ret;
-
- fd = meta_device_file_get_fd (priv->device_file);
- ret = drmModeRmFB (fd, priv->fb_id);
- if (ret != 0)
- g_warning ("drmModeRmFB: %s", g_strerror (-ret));
-
- priv->fb_id = 0;
-}
-
-uint32_t
-meta_drm_buffer_get_fb_id (MetaDrmBuffer *buffer)
-{
- MetaDrmBufferPrivate *priv = meta_drm_buffer_get_instance_private (buffer);
-
- return priv->fb_id;
-}
-
-int
-meta_drm_buffer_get_width (MetaDrmBuffer *buffer)
-{
- return META_DRM_BUFFER_GET_CLASS (buffer)->get_width (buffer);
-}
-
-int
-meta_drm_buffer_get_height (MetaDrmBuffer *buffer)
-{
- return META_DRM_BUFFER_GET_CLASS (buffer)->get_height (buffer);
-}
-
-int
-meta_drm_buffer_get_stride (MetaDrmBuffer *buffer)
-{
- return META_DRM_BUFFER_GET_CLASS (buffer)->get_stride (buffer);
-}
-
-uint32_t
-meta_drm_buffer_get_format (MetaDrmBuffer *buffer)
-{
- return META_DRM_BUFFER_GET_CLASS (buffer)->get_format (buffer);
-}
-
-gboolean
-meta_drm_buffer_supports_fill_timings (MetaDrmBuffer *buffer)
-{
- return META_DRM_BUFFER_GET_CLASS (buffer)->fill_timings != NULL;
-}
-
-gboolean
-meta_drm_buffer_fill_timings (MetaDrmBuffer *buffer,
- CoglFrameInfo *info,
- GError **error)
-{
- if (!meta_drm_buffer_supports_fill_timings (buffer))
- {
- g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
- "Buffer doesn't support filling timing info");
- return FALSE;
- }
-
- return META_DRM_BUFFER_GET_CLASS (buffer)->fill_timings (buffer, info, error);
-}
-
-static void
-meta_drm_buffer_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- MetaDrmBuffer *buffer = META_DRM_BUFFER (object);
- MetaDrmBufferPrivate *priv = meta_drm_buffer_get_instance_private (buffer);
-
- switch (prop_id)
- {
- case PROP_DEVICE_FILE:
- g_value_set_pointer (value, priv->device_file);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-
-static void
-meta_drm_buffer_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- MetaDrmBuffer *buffer = META_DRM_BUFFER (object);
- MetaDrmBufferPrivate *priv = meta_drm_buffer_get_instance_private (buffer);
-
- switch (prop_id)
- {
- case PROP_DEVICE_FILE:
- priv->device_file = g_value_get_pointer (value);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-
-static void
-meta_drm_buffer_finalize (GObject *object)
-{
- MetaDrmBuffer *buffer = META_DRM_BUFFER (object);
- MetaDrmBufferPrivate *priv = meta_drm_buffer_get_instance_private (buffer);
-
- if (priv->fb_id != INVALID_FB_ID)
- meta_drm_buffer_release_fb_id (buffer);
- meta_device_file_release (priv->device_file);
-
- G_OBJECT_CLASS (meta_drm_buffer_parent_class)->finalize (object);
-}
-
-static void
-meta_drm_buffer_constructed (GObject *object)
-{
- MetaDrmBuffer *buffer = META_DRM_BUFFER (object);
- MetaDrmBufferPrivate *priv = meta_drm_buffer_get_instance_private (buffer);
-
- meta_device_file_acquire (priv->device_file);
-
- G_OBJECT_CLASS (meta_drm_buffer_parent_class)->constructed (object);
-}
-
-static void
-meta_drm_buffer_init (MetaDrmBuffer *buffer)
-{
-}
-
-static void
-meta_drm_buffer_class_init (MetaDrmBufferClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- object_class->get_property = meta_drm_buffer_get_property;
- object_class->set_property = meta_drm_buffer_set_property;
- object_class->constructed = meta_drm_buffer_constructed;
- object_class->finalize = meta_drm_buffer_finalize;
-
- obj_props[PROP_DEVICE_FILE] =
- g_param_spec_pointer ("device-file",
- "device file",
- "MetaDeviceFile",
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT_ONLY |
- G_PARAM_STATIC_STRINGS);
- g_object_class_install_properties (object_class, N_PROPS, obj_props);
-}
diff --git a/src/backends/native/meta-drm-buffer.h b/src/backends/native/meta-drm-buffer.h
deleted file mode 100644
index d32135591..000000000
--- a/src/backends/native/meta-drm-buffer.h
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Copyright (C) 2018 Canonical Ltd.
- * Copyright (C) 2019-2020 Red Hat Inc.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Author: Daniel van Vugt <daniel.van.vugt@canonical.com>
- */
-
-#ifndef META_DRM_BUFFER_H
-#define META_DRM_BUFFER_H
-
-#include <glib-object.h>
-#include <stdint.h>
-
-#include "cogl/cogl.h"
-
-#define META_TYPE_DRM_BUFFER (meta_drm_buffer_get_type ())
-G_DECLARE_DERIVABLE_TYPE (MetaDrmBuffer,
- meta_drm_buffer,
- META, DRM_BUFFER,
- GObject)
-
-uint32_t meta_drm_buffer_get_fb_id (MetaDrmBuffer *buffer);
-
-int meta_drm_buffer_get_width (MetaDrmBuffer *buffer);
-
-int meta_drm_buffer_get_height (MetaDrmBuffer *buffer);
-
-int meta_drm_buffer_get_stride (MetaDrmBuffer *buffer);
-
-uint32_t meta_drm_buffer_get_format (MetaDrmBuffer *buffer);
-
-gboolean meta_drm_buffer_supports_fill_timings (MetaDrmBuffer *buffer);
-
-gboolean meta_drm_buffer_fill_timings (MetaDrmBuffer *buffer,
- CoglFrameInfo *info,
- GError **error);
-
-#endif /* META_DRM_BUFFER_H */
diff --git a/src/backends/native/meta-gpu-kms.c b/src/backends/native/meta-gpu-kms.c
deleted file mode 100644
index 97b47f9f9..000000000
--- a/src/backends/native/meta-gpu-kms.c
+++ /dev/null
@@ -1,422 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2017 Red Hat
- * Copyright (c) 2018 DisplayLink (UK) Ltd.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-
-#include "config.h"
-
-#include "backends/native/meta-gpu-kms.h"
-
-#include <drm.h>
-#include <drm_fourcc.h>
-#include <errno.h>
-#include <poll.h>
-#include <string.h>
-#include <time.h>
-#include <xf86drm.h>
-#include <xf86drmMode.h>
-
-#include "backends/meta-crtc.h"
-#include "backends/meta-monitor-manager-private.h"
-#include "backends/meta-output.h"
-#include "backends/native/meta-backend-native.h"
-#include "backends/native/meta-crtc-kms.h"
-#include "backends/native/meta-crtc-mode-kms.h"
-#include "backends/native/meta-kms-connector.h"
-#include "backends/native/meta-kms-device.h"
-#include "backends/native/meta-kms-mode.h"
-#include "backends/native/meta-kms-update.h"
-#include "backends/native/meta-kms-utils.h"
-#include "backends/native/meta-kms.h"
-#include "backends/native/meta-launcher.h"
-#include "backends/native/meta-output-kms.h"
-
-struct _MetaGpuKms
-{
- MetaGpu parent;
-
- MetaKmsDevice *kms_device;
-
- uint32_t id;
- int fd;
-
- gboolean resources_init_failed_before;
-};
-
-G_DEFINE_TYPE (MetaGpuKms, meta_gpu_kms, META_TYPE_GPU)
-
-gboolean
-meta_gpu_kms_is_crtc_active (MetaGpuKms *gpu_kms,
- MetaCrtc *crtc)
-{
- MetaGpu *gpu = META_GPU (gpu_kms);
- MetaBackend *backend = meta_gpu_get_backend (gpu);
- MetaMonitorManager *monitor_manager =
- meta_backend_get_monitor_manager (backend);
- GList *l;
- gboolean connected_crtc_found;
-
- g_assert (meta_crtc_get_gpu (crtc) == META_GPU (gpu_kms));
-
- if (meta_monitor_manager_get_power_save_mode (monitor_manager))
- return FALSE;
-
- connected_crtc_found = FALSE;
- for (l = meta_gpu_get_outputs (gpu); l; l = l->next)
- {
- MetaOutput *output = l->data;
- MetaCrtc *assigned_crtc;
-
- assigned_crtc = meta_output_get_assigned_crtc (output);
- if (assigned_crtc == crtc)
- {
- connected_crtc_found = TRUE;
- break;
- }
- }
-
- if (!connected_crtc_found)
- return FALSE;
-
- return TRUE;
-}
-
-MetaKmsDevice *
-meta_gpu_kms_get_kms_device (MetaGpuKms *gpu_kms)
-{
- return gpu_kms->kms_device;
-}
-
-uint32_t
-meta_gpu_kms_get_id (MetaGpuKms *gpu_kms)
-{
- return gpu_kms->id;
-}
-
-const char *
-meta_gpu_kms_get_file_path (MetaGpuKms *gpu_kms)
-{
- return meta_kms_device_get_path (gpu_kms->kms_device);
-}
-
-gboolean
-meta_gpu_kms_is_boot_vga (MetaGpuKms *gpu_kms)
-{
- MetaKmsDeviceFlag flags;
-
- flags = meta_kms_device_get_flags (gpu_kms->kms_device);
- return !!(flags & META_KMS_DEVICE_FLAG_BOOT_VGA);
-}
-
-gboolean
-meta_gpu_kms_is_platform_device (MetaGpuKms *gpu_kms)
-{
- MetaKmsDeviceFlag flags;
-
- flags = meta_kms_device_get_flags (gpu_kms->kms_device);
- return !!(flags & META_KMS_DEVICE_FLAG_PLATFORM_DEVICE);
-}
-
-gboolean
-meta_gpu_kms_disable_modifiers (MetaGpuKms *gpu_kms)
-{
- MetaKmsDeviceFlag flags;
-
- flags = meta_kms_device_get_flags (gpu_kms->kms_device);
- return !!(flags & META_KMS_DEVICE_FLAG_DISABLE_MODIFIERS);
-}
-
-static int
-compare_outputs (gconstpointer one,
- gconstpointer two)
-{
- MetaOutput *o_one = (MetaOutput *) one;
- MetaOutput *o_two = (MetaOutput *) two;
- const MetaOutputInfo *output_info_one = meta_output_get_info (o_one);
- const MetaOutputInfo *output_info_two = meta_output_get_info (o_two);
-
- return strcmp (output_info_one->name, output_info_two->name);
-}
-
-MetaCrtcMode *
-meta_gpu_kms_get_mode_from_kms_mode (MetaGpuKms *gpu_kms,
- MetaKmsMode *kms_mode)
-{
- MetaGpu *gpu = META_GPU (gpu_kms);
- GList *l;
-
- for (l = meta_gpu_get_modes (gpu); l; l = l->next)
- {
- MetaCrtcModeKms *crtc_mode_kms = l->data;
-
- if (meta_kms_mode_equal (kms_mode,
- meta_crtc_mode_kms_get_kms_mode (crtc_mode_kms)))
- return META_CRTC_MODE (crtc_mode_kms);
- }
-
- g_assert_not_reached ();
- return NULL;
-}
-
-static MetaOutput *
-find_output_by_connector_id (GList *outputs,
- uint32_t connector_id)
-{
- GList *l;
-
- for (l = outputs; l; l = l->next)
- {
- MetaOutput *output = l->data;
-
- if (meta_output_kms_get_connector_id (META_OUTPUT_KMS (output)) ==
- connector_id)
- return output;
- }
-
- return NULL;
-}
-
-static void
-setup_output_clones (MetaGpu *gpu)
-{
- GList *l;
-
- for (l = meta_gpu_get_outputs (gpu); l; l = l->next)
- {
- MetaOutput *output = l->data;
- GList *k;
-
- for (k = meta_gpu_get_outputs (gpu); k; k = k->next)
- {
- MetaOutput *other_output = k->data;
-
- if (other_output == output)
- continue;
-
- if (meta_output_kms_can_clone (META_OUTPUT_KMS (output),
- META_OUTPUT_KMS (other_output)))
- meta_output_add_possible_clone (output, other_output);
- }
- }
-}
-
-static void
-init_modes (MetaGpuKms *gpu_kms)
-{
- MetaGpu *gpu = META_GPU (gpu_kms);
- MetaKmsDevice *kms_device = gpu_kms->kms_device;
- GHashTable *modes_table;
- GList *l;
- GList *modes;
- GHashTableIter iter;
- gpointer value;
- uint64_t mode_id;
-
- /*
- * Gather all modes on all connected connectors.
- */
- modes_table = g_hash_table_new ((GHashFunc) meta_kms_mode_hash,
- (GEqualFunc) meta_kms_mode_equal);
- for (l = meta_kms_device_get_connectors (kms_device); l; l = l->next)
- {
- MetaKmsConnector *kms_connector = l->data;
- const MetaKmsConnectorState *state;
- GList *l_mode;
-
- state = meta_kms_connector_get_current_state (kms_connector);
- if (!state)
- continue;
-
- for (l_mode = state->modes; l_mode; l_mode = l_mode->next)
- {
- MetaKmsMode *kms_mode = l_mode->data;
-
- g_hash_table_add (modes_table, kms_mode);
- }
- }
-
- for (l = meta_kms_device_get_fallback_modes (kms_device); l; l = l->next)
- {
- MetaKmsMode *fallback_mode = l->data;
-
- g_hash_table_add (modes_table, fallback_mode);
- }
-
- modes = NULL;
-
- g_hash_table_iter_init (&iter, modes_table);
- mode_id = 0;
- while (g_hash_table_iter_next (&iter, NULL, &value))
- {
- MetaKmsMode *kms_mode = value;
- MetaCrtcModeKms *mode;
-
- mode = meta_crtc_mode_kms_new (kms_mode, mode_id);
- modes = g_list_append (modes, mode);
-
- mode_id++;
- }
-
- g_hash_table_destroy (modes_table);
-
- meta_gpu_take_modes (gpu, modes);
-}
-
-static void
-init_crtcs (MetaGpuKms *gpu_kms)
-{
- MetaGpu *gpu = META_GPU (gpu_kms);
- MetaKmsDevice *kms_device = gpu_kms->kms_device;
- GList *l;
- GList *crtcs;
-
- crtcs = NULL;
-
- for (l = meta_kms_device_get_crtcs (kms_device); l; l = l->next)
- {
- MetaKmsCrtc *kms_crtc = l->data;
- MetaCrtcKms *crtc_kms;
-
- crtc_kms = meta_crtc_kms_new (gpu_kms, kms_crtc);
-
- crtcs = g_list_append (crtcs, crtc_kms);
- }
-
- meta_gpu_take_crtcs (gpu, crtcs);
-}
-
-static void
-init_outputs (MetaGpuKms *gpu_kms)
-{
- MetaGpu *gpu = META_GPU (gpu_kms);
- GList *old_outputs;
- GList *outputs;
- GList *l;
-
- old_outputs = meta_gpu_get_outputs (gpu);
-
- outputs = NULL;
-
- for (l = meta_kms_device_get_connectors (gpu_kms->kms_device); l; l = l->next)
- {
- MetaKmsConnector *kms_connector = l->data;
- const MetaKmsConnectorState *connector_state;
- MetaOutputKms *output_kms;
- MetaOutput *old_output;
- GError *error = NULL;
-
- connector_state = meta_kms_connector_get_current_state (kms_connector);
- if (!connector_state || connector_state->non_desktop)
- continue;
-
- old_output =
- find_output_by_connector_id (old_outputs,
- meta_kms_connector_get_id (kms_connector));
- output_kms = meta_output_kms_new (gpu_kms,
- kms_connector,
- old_output,
- &error);
- if (!output_kms)
- {
- g_warning ("Failed to create KMS output: %s", error->message);
- g_error_free (error);
- }
- else
- {
- outputs = g_list_prepend (outputs, output_kms);
- }
- }
-
-
- /* Sort the outputs for easier handling in MetaMonitorConfig */
- outputs = g_list_sort (outputs, compare_outputs);
- meta_gpu_take_outputs (gpu, outputs);
-
- setup_output_clones (gpu);
-}
-
-static gboolean
-meta_gpu_kms_read_current (MetaGpu *gpu,
- GError **error)
-{
- MetaGpuKms *gpu_kms = META_GPU_KMS (gpu);
-
- /* Note: we must not free the public structures (output, crtc, monitor
- mode and monitor info) here, they must be kept alive until the API
- users are done with them after we emit monitors-changed, and thus
- are freed by the platform-independent layer. */
-
- init_modes (gpu_kms);
- init_crtcs (gpu_kms);
- init_outputs (gpu_kms);
-
- return TRUE;
-}
-
-gboolean
-meta_gpu_kms_can_have_outputs (MetaGpuKms *gpu_kms)
-{
- GList *l;
- int n_connected_connectors = 0;
-
- for (l = meta_kms_device_get_connectors (gpu_kms->kms_device); l; l = l->next)
- {
- MetaKmsConnector *kms_connector = l->data;
-
- if (meta_kms_connector_get_current_state (kms_connector))
- n_connected_connectors++;
- }
-
- return n_connected_connectors > 0;
-}
-
-MetaGpuKms *
-meta_gpu_kms_new (MetaBackendNative *backend_native,
- MetaKmsDevice *kms_device,
- GError **error)
-{
- MetaGpuKms *gpu_kms;
-
- gpu_kms = g_object_new (META_TYPE_GPU_KMS,
- "backend", backend_native,
- NULL);
-
- gpu_kms->kms_device = kms_device;
-
- meta_gpu_kms_read_current (META_GPU (gpu_kms), NULL);
-
- return gpu_kms;
-}
-
-static void
-meta_gpu_kms_init (MetaGpuKms *gpu_kms)
-{
- static uint32_t id = 0;
-
- gpu_kms->id = ++id;
-}
-
-static void
-meta_gpu_kms_class_init (MetaGpuKmsClass *klass)
-{
- MetaGpuClass *gpu_class = META_GPU_CLASS (klass);
-
- gpu_class->read_current = meta_gpu_kms_read_current;
-}
diff --git a/src/backends/native/meta-gpu-kms.h b/src/backends/native/meta-gpu-kms.h
deleted file mode 100644
index 06f6e100a..000000000
--- a/src/backends/native/meta-gpu-kms.h
+++ /dev/null
@@ -1,74 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2017 Red Hat
- * Copyright (C) 2018 DisplayLink (UK) Ltd.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-
-#ifndef META_GPU_KMS_H
-#define META_GPU_KMS_H
-
-#include <glib-object.h>
-#include <xf86drm.h>
-#include <xf86drmMode.h>
-
-#include "backends/meta-gpu.h"
-#include "backends/native/meta-backend-native.h"
-#include "backends/native/meta-kms-types.h"
-
-#define META_TYPE_GPU_KMS (meta_gpu_kms_get_type ())
-G_DECLARE_FINAL_TYPE (MetaGpuKms, meta_gpu_kms, META, GPU_KMS, MetaGpu)
-
-typedef struct _MetaGpuKmsFlipClosureContainer MetaGpuKmsFlipClosureContainer;
-
-MetaGpuKms * meta_gpu_kms_new (MetaBackendNative *backend_native,
- MetaKmsDevice *kms_device,
- GError **error);
-
-gboolean meta_gpu_kms_can_have_outputs (MetaGpuKms *gpu_kms);
-
-gboolean meta_gpu_kms_is_crtc_active (MetaGpuKms *gpu_kms,
- MetaCrtc *crtc);
-
-gboolean meta_gpu_kms_is_boot_vga (MetaGpuKms *gpu_kms);
-gboolean meta_gpu_kms_is_platform_device (MetaGpuKms *gpu_kms);
-gboolean meta_gpu_kms_disable_modifiers (MetaGpuKms *gpu_kms);
-
-MetaKmsDevice * meta_gpu_kms_get_kms_device (MetaGpuKms *gpu_kms);
-
-uint32_t meta_gpu_kms_get_id (MetaGpuKms *gpu_kms);
-
-const char * meta_gpu_kms_get_file_path (MetaGpuKms *gpu_kms);
-
-void meta_gpu_kms_set_power_save_mode (MetaGpuKms *gpu_kms,
- uint64_t state,
- MetaKmsUpdate *kms_update);
-
-MetaCrtcMode * meta_gpu_kms_get_mode_from_kms_mode (MetaGpuKms *gpu_kms,
- MetaKmsMode *kms_mode);
-
-gboolean meta_drm_mode_equal (const drmModeModeInfo *one,
- const drmModeModeInfo *two);
-
-MetaGpuKmsFlipClosureContainer * meta_gpu_kms_wrap_flip_closure (MetaGpuKms *gpu_kms,
- MetaCrtc *crtc,
- GClosure *flip_closure);
-
-void meta_gpu_kms_flip_closure_container_free (MetaGpuKmsFlipClosureContainer *closure_container);
-
-#endif /* META_GPU_KMS_H */
diff --git a/src/backends/native/meta-input-device-native.c b/src/backends/native/meta-input-device-native.c
deleted file mode 100644
index 468aef557..000000000
--- a/src/backends/native/meta-input-device-native.c
+++ /dev/null
@@ -1,1599 +0,0 @@
-/*
- * Copyright (C) 2010 Intel Corp.
- * Copyright (C) 2014 Jonas Ådahl
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
- *
- * Author: Damien Lespiau <damien.lespiau@intel.com>
- * Author: Jonas Ådahl <jadahl@gmail.com>
- */
-
-#include "config.h"
-
-#include <math.h>
-#include <cairo-gobject.h>
-
-#include "backends/meta-backend-private.h"
-#include "backends/native/meta-input-thread.h"
-#include "clutter/clutter-mutter.h"
-
-G_DEFINE_TYPE (MetaInputDeviceNative,
- meta_input_device_native,
- META_TYPE_INPUT_DEVICE)
-
-enum
-{
- PROP_0,
- PROP_DEVICE_MATRIX,
- PROP_OUTPUT_ASPECT_RATIO,
- N_PROPS
-};
-
-static GParamSpec *obj_props[N_PROPS] = { 0 };
-
-typedef struct _SlowKeysEventPending
-{
- MetaInputDeviceNative *device;
- ClutterEvent *event;
- GSource *timer;
-} SlowKeysEventPending;
-
-typedef struct _PadFeature PadFeature;
-
-struct _PadFeature
-{
- ClutterInputDevicePadFeature feature;
- int n_feature;
- int group;
- gboolean mode_switch;
-};
-
-static void clear_slow_keys (MetaInputDeviceNative *device);
-static void stop_bounce_keys (MetaInputDeviceNative *device);
-static void stop_toggle_slowkeys (MetaInputDeviceNative *device);
-static void stop_mousekeys_move (MetaInputDeviceNative *device);
-
-static void
-meta_input_device_native_finalize (GObject *object)
-{
- MetaInputDeviceNative *device_evdev = META_INPUT_DEVICE_NATIVE (object);
-
- g_warn_if_fail (!device_evdev->libinput_device);
-
- clear_slow_keys (device_evdev);
- stop_bounce_keys (device_evdev);
- stop_toggle_slowkeys (device_evdev);
- stop_mousekeys_move (device_evdev);
-
- g_clear_pointer (&device_evdev->pad_features, g_array_unref);
- g_clear_pointer (&device_evdev->modes, g_array_unref);
-
- G_OBJECT_CLASS (meta_input_device_native_parent_class)->finalize (object);
-}
-
-static void
-meta_input_device_native_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- MetaInputDeviceNative *device = META_INPUT_DEVICE_NATIVE (object);
-
- switch (prop_id)
- {
- case PROP_DEVICE_MATRIX:
- {
- const cairo_matrix_t *matrix = g_value_get_boxed (value);
- cairo_matrix_init_identity (&device->device_matrix);
- cairo_matrix_multiply (&device->device_matrix,
- &device->device_matrix, matrix);
- break;
- }
- case PROP_OUTPUT_ASPECT_RATIO:
- device->output_ratio = g_value_get_double (value);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- }
-}
-
-static void
-meta_input_device_native_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- MetaInputDeviceNative *device = META_INPUT_DEVICE_NATIVE (object);
-
- switch (prop_id)
- {
- case PROP_DEVICE_MATRIX:
- g_value_set_boxed (value, &device->device_matrix);
- break;
- case PROP_OUTPUT_ASPECT_RATIO:
- g_value_set_double (value, device->output_ratio);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- }
-}
-
-static gboolean
-meta_input_device_native_is_mode_switch_button (ClutterInputDevice *device,
- uint32_t group,
- uint32_t button)
-{
- MetaInputDeviceNative *device_native = META_INPUT_DEVICE_NATIVE (device);
- int i;
-
- if (!device_native->pad_features)
- return FALSE;
-
- for (i = 0; i < device_native->pad_features->len; i++)
- {
- PadFeature *pad_feature;
-
- pad_feature = &g_array_index (device_native->pad_features, PadFeature, i);
-
- if (pad_feature->feature == CLUTTER_PAD_FEATURE_BUTTON &&
- pad_feature->group == group &&
- pad_feature->n_feature == button)
- return pad_feature->mode_switch;
- }
-
- return FALSE;
-}
-
-static int
-meta_input_device_native_get_group_n_modes (ClutterInputDevice *device,
- int group)
-{
- MetaInputDeviceNative *device_native = META_INPUT_DEVICE_NATIVE (device);
-
- if (!device_native->modes || group >= device_native->modes->len)
- return -1;
-
- return g_array_index (device_native->modes, int, group);
-}
-
-static gboolean
-meta_input_device_native_is_grouped (ClutterInputDevice *device,
- ClutterInputDevice *other_device)
-{
- MetaInputDeviceNative *device_native, *other_device_native;
-
- device_native = META_INPUT_DEVICE_NATIVE (device);
- other_device_native = META_INPUT_DEVICE_NATIVE (other_device);
-
- return device_native->group == other_device_native->group;
-}
-
-static int
-meta_input_device_native_get_pad_feature_group (ClutterInputDevice *device,
- ClutterInputDevicePadFeature feature,
- int n_feature)
-{
- MetaInputDeviceNative *device_native = META_INPUT_DEVICE_NATIVE (device);
- int i;
-
- if (!device_native->pad_features)
- return -1;
-
- for (i = 0; i < device_native->pad_features->len; i++)
- {
- PadFeature *pad_feature;
-
- pad_feature = &g_array_index (device_native->pad_features, PadFeature, i);
-
- if (pad_feature->feature == feature &&
- pad_feature->n_feature == n_feature)
- return pad_feature->group;
- }
-
- return -1;
-}
-
-static void
-meta_input_device_native_bell_notify (MetaInputDeviceNative *device)
-{
- meta_seat_impl_notify_bell_in_impl (device->seat_impl);
-}
-
-static void
-meta_input_device_native_free_pending_slow_key (gpointer data)
-{
- SlowKeysEventPending *slow_keys_event = data;
-
- clutter_event_free (slow_keys_event->event);
- g_clear_pointer (&slow_keys_event->timer, g_source_destroy);
- g_free (slow_keys_event);
-}
-
-static void
-clear_slow_keys (MetaInputDeviceNative *device)
-{
- g_list_free_full (device->slow_keys_list, meta_input_device_native_free_pending_slow_key);
- g_list_free (device->slow_keys_list);
- device->slow_keys_list = NULL;
-}
-
-static guint
-get_slow_keys_delay (ClutterInputDevice *device)
-{
- MetaInputDeviceNative *device_native = META_INPUT_DEVICE_NATIVE (device);
- MetaKbdA11ySettings a11y_settings;
- MetaInputSettings *input_settings;
-
- input_settings = meta_seat_impl_get_input_settings (device_native->seat_impl);
- meta_input_settings_get_kbd_a11y_settings (input_settings, &a11y_settings);
- /* Settings use int, we use uint, make sure we dont go negative */
- return MAX (0, a11y_settings.slowkeys_delay);
-}
-
-static gboolean
-trigger_slow_keys (gpointer data)
-{
- SlowKeysEventPending *slow_keys_event = data;
- MetaInputDeviceNative *device = slow_keys_event->device;
- ClutterKeyEvent *key_event = (ClutterKeyEvent *) slow_keys_event->event;
-
- /* Alter timestamp and emit the event */
- key_event->time = us2ms (g_get_monotonic_time ());
- _clutter_event_push (slow_keys_event->event, TRUE);
-
- /* Then remote the pending event */
- device->slow_keys_list = g_list_remove (device->slow_keys_list, slow_keys_event);
- meta_input_device_native_free_pending_slow_key (slow_keys_event);
-
- if (device->a11y_flags & META_A11Y_SLOW_KEYS_BEEP_ACCEPT)
- meta_input_device_native_bell_notify (device);
-
- return G_SOURCE_REMOVE;
-}
-
-static int
-find_pending_event_by_keycode (gconstpointer a,
- gconstpointer b)
-{
- const SlowKeysEventPending *pa = a;
- const ClutterKeyEvent *ka = (ClutterKeyEvent *) pa->event;
- const ClutterKeyEvent *kb = b;
-
- return kb->hardware_keycode - ka->hardware_keycode;
-}
-
-static GSource *
-timeout_source_new (MetaSeatImpl *seat_impl,
- guint interval,
- GSourceFunc func,
- gpointer user_data)
-{
- GSource *source;
-
- source = g_timeout_source_new (interval);
- g_source_set_callback (source,
- func,
- user_data, NULL);
- g_source_attach (source, seat_impl->input_context);
- g_source_unref (source);
-
- return source;
-}
-
-static gboolean
-start_slow_keys (ClutterEvent *event,
- MetaInputDeviceNative *device)
-{
- SlowKeysEventPending *slow_keys_event;
- ClutterKeyEvent *key_event = (ClutterKeyEvent *) event;
-
- if (key_event->flags & CLUTTER_EVENT_FLAG_REPEATED)
- return TRUE;
-
- slow_keys_event = g_new0 (SlowKeysEventPending, 1);
- slow_keys_event->device = device;
- slow_keys_event->event = clutter_event_copy (event);
- slow_keys_event->timer =
- timeout_source_new (device->seat_impl,
- get_slow_keys_delay (CLUTTER_INPUT_DEVICE (device)),
- trigger_slow_keys,
- slow_keys_event);
- device->slow_keys_list = g_list_append (device->slow_keys_list, slow_keys_event);
-
- if (device->a11y_flags & META_A11Y_SLOW_KEYS_BEEP_PRESS)
- meta_input_device_native_bell_notify (device);
-
- return TRUE;
-}
-
-static gboolean
-stop_slow_keys (ClutterEvent *event,
- MetaInputDeviceNative *device)
-{
- GList *item;
-
- /* Check if we have a slow key event queued for this key event */
- item = g_list_find_custom (device->slow_keys_list, event, find_pending_event_by_keycode);
- if (item)
- {
- SlowKeysEventPending *slow_keys_event = item->data;
-
- device->slow_keys_list = g_list_delete_link (device->slow_keys_list, item);
- meta_input_device_native_free_pending_slow_key (slow_keys_event);
-
- if (device->a11y_flags & META_A11Y_SLOW_KEYS_BEEP_REJECT)
- meta_input_device_native_bell_notify (device);
-
- return TRUE;
- }
-
- /* If no key press event was pending, just emit the key release as-is */
- return FALSE;
-}
-
-static guint
-get_debounce_delay (ClutterInputDevice *device)
-{
- MetaInputDeviceNative *device_native = META_INPUT_DEVICE_NATIVE (device);
- MetaKbdA11ySettings a11y_settings;
- MetaInputSettings *input_settings;
-
- input_settings = meta_seat_impl_get_input_settings (device_native->seat_impl);
- meta_input_settings_get_kbd_a11y_settings (input_settings, &a11y_settings);
- /* Settings use int, we use uint, make sure we dont go negative */
- return MAX (0, a11y_settings.debounce_delay);
-}
-
-static gboolean
-clear_bounce_keys (gpointer data)
-{
- MetaInputDeviceNative *device = data;
-
- device->debounce_key = 0;
- device->debounce_timer = 0;
-
- return G_SOURCE_REMOVE;
-}
-
-static void
-start_bounce_keys (ClutterEvent *event,
- MetaInputDeviceNative *device)
-{
- stop_bounce_keys (device);
-
- device->debounce_key = ((ClutterKeyEvent *) event)->hardware_keycode;
- device->debounce_timer =
- timeout_source_new (device->seat_impl,
- get_debounce_delay (CLUTTER_INPUT_DEVICE (device)),
- clear_bounce_keys,
- device);
-}
-
-static void
-stop_bounce_keys (MetaInputDeviceNative *device)
-{
- g_clear_pointer (&device->debounce_timer, g_source_destroy);
-}
-
-static void
-notify_bounce_keys_reject (MetaInputDeviceNative *device)
-{
- if (device->a11y_flags & META_A11Y_BOUNCE_KEYS_BEEP_REJECT)
- meta_input_device_native_bell_notify (device);
-}
-
-static gboolean
-debounce_key (ClutterEvent *event,
- MetaInputDeviceNative *device)
-{
- return (device->debounce_key == ((ClutterKeyEvent *) event)->hardware_keycode);
-}
-
-static gboolean
-key_event_is_modifier (ClutterEvent *event)
-{
- switch (event->key.keyval)
- {
- case XKB_KEY_Shift_L:
- case XKB_KEY_Shift_R:
- case XKB_KEY_Control_L:
- case XKB_KEY_Control_R:
- case XKB_KEY_Alt_L:
- case XKB_KEY_Alt_R:
- case XKB_KEY_Meta_L:
- case XKB_KEY_Meta_R:
- case XKB_KEY_Super_L:
- case XKB_KEY_Super_R:
- case XKB_KEY_Hyper_L:
- case XKB_KEY_Hyper_R:
- case XKB_KEY_Caps_Lock:
- case XKB_KEY_Shift_Lock:
- return TRUE;
- default:
- return FALSE;
- }
-}
-
-static void
-notify_stickykeys_mask (MetaInputDeviceNative *device)
-{
- meta_seat_impl_notify_kbd_a11y_mods_state_changed_in_impl (device->seat_impl,
- device->stickykeys_latched_mask,
- device->stickykeys_locked_mask);
-}
-
-static void
-update_internal_xkb_state (MetaInputDeviceNative *device,
- xkb_mod_mask_t new_latched_mask,
- xkb_mod_mask_t new_locked_mask)
-{
- MetaSeatImpl *seat_impl = device->seat_impl;
- xkb_mod_mask_t depressed_mods;
- xkb_mod_mask_t latched_mods;
- xkb_mod_mask_t locked_mods;
- xkb_mod_mask_t group_mods;
- struct xkb_state *xkb_state;
-
- g_rw_lock_writer_lock (&seat_impl->state_lock);
-
- xkb_state = meta_seat_impl_get_xkb_state_in_impl (seat_impl);
- depressed_mods = xkb_state_serialize_mods (xkb_state, XKB_STATE_MODS_DEPRESSED);
- latched_mods = xkb_state_serialize_mods (xkb_state, XKB_STATE_MODS_LATCHED);
- locked_mods = xkb_state_serialize_mods (xkb_state, XKB_STATE_MODS_LOCKED);
-
- latched_mods &= ~device->stickykeys_latched_mask;
- locked_mods &= ~device->stickykeys_locked_mask;
-
- device->stickykeys_latched_mask = new_latched_mask;
- device->stickykeys_locked_mask = new_locked_mask;
-
- latched_mods |= device->stickykeys_latched_mask;
- locked_mods |= device->stickykeys_locked_mask;
-
- group_mods = xkb_state_serialize_layout (xkb_state, XKB_STATE_LAYOUT_EFFECTIVE);
-
- xkb_state_update_mask (xkb_state,
- depressed_mods,
- latched_mods,
- locked_mods,
- 0, 0, group_mods);
- notify_stickykeys_mask (device);
-
- g_rw_lock_writer_unlock (&seat_impl->state_lock);
-}
-
-static void
-update_stickykeys_event (ClutterEvent *event,
- MetaInputDeviceNative *device,
- xkb_mod_mask_t new_latched_mask,
- xkb_mod_mask_t new_locked_mask)
-{
- MetaSeatImpl *seat_impl = device->seat_impl;
- xkb_mod_mask_t effective_mods;
- xkb_mod_mask_t latched_mods;
- xkb_mod_mask_t locked_mods;
- struct xkb_state *xkb_state;
-
- update_internal_xkb_state (device, new_latched_mask, new_locked_mask);
-
- xkb_state = meta_seat_impl_get_xkb_state_in_impl (seat_impl);
- effective_mods = xkb_state_serialize_mods (xkb_state, XKB_STATE_MODS_EFFECTIVE);
- latched_mods = xkb_state_serialize_mods (xkb_state, XKB_STATE_MODS_LATCHED);
- locked_mods = xkb_state_serialize_mods (xkb_state, XKB_STATE_MODS_LOCKED);
-
- _clutter_event_set_state_full (event,
- seat_impl->button_state,
- device->stickykeys_depressed_mask,
- latched_mods,
- locked_mods,
- effective_mods | seat_impl->button_state);
-}
-
-static void
-notify_stickykeys_change (MetaInputDeviceNative *device)
-{
- /* Every time sticky keys setting is changed, clear the masks */
- device->stickykeys_depressed_mask = 0;
- update_internal_xkb_state (device, 0, 0);
-
- meta_seat_impl_notify_kbd_a11y_flags_changed_in_impl (device->seat_impl,
- device->a11y_flags,
- META_A11Y_STICKY_KEYS_ENABLED);
-}
-
-static void
-set_stickykeys_off (MetaInputDeviceNative *device)
-{
- device->a11y_flags &= ~META_A11Y_STICKY_KEYS_ENABLED;
- notify_stickykeys_change (device);
-}
-
-static void
-set_stickykeys_on (MetaInputDeviceNative *device)
-{
- device->a11y_flags |= META_A11Y_STICKY_KEYS_ENABLED;
- notify_stickykeys_change (device);
-}
-
-static void
-clear_stickykeys_event (ClutterEvent *event,
- MetaInputDeviceNative *device)
-{
- set_stickykeys_off (device);
- update_stickykeys_event (event, device, 0, 0);
-}
-
-static void
-set_slowkeys_off (MetaInputDeviceNative *device)
-{
- device->a11y_flags &= ~META_A11Y_SLOW_KEYS_ENABLED;
-
- meta_seat_impl_notify_kbd_a11y_flags_changed_in_impl (device->seat_impl,
- device->a11y_flags,
- META_A11Y_SLOW_KEYS_ENABLED);
-}
-
-static void
-set_slowkeys_on (MetaInputDeviceNative *device)
-{
- device->a11y_flags |= META_A11Y_SLOW_KEYS_ENABLED;
-
- meta_seat_impl_notify_kbd_a11y_flags_changed_in_impl (device->seat_impl,
- device->a11y_flags,
- META_A11Y_SLOW_KEYS_ENABLED);
-}
-
-static void
-handle_stickykeys_press (ClutterEvent *event,
- MetaInputDeviceNative *device)
-{
- MetaSeatImpl *seat_impl = device->seat_impl;
- xkb_mod_mask_t depressed_mods;
- xkb_mod_mask_t new_latched_mask;
- xkb_mod_mask_t new_locked_mask;
- struct xkb_state *xkb_state;
-
- if (!key_event_is_modifier (event))
- return;
-
- if (device->stickykeys_depressed_mask &&
- (device->a11y_flags & META_A11Y_STICKY_KEYS_TWO_KEY_OFF))
- {
- clear_stickykeys_event (event, device);
- return;
- }
-
- xkb_state = meta_seat_impl_get_xkb_state_in_impl (seat_impl);
- depressed_mods = xkb_state_serialize_mods (xkb_state, XKB_STATE_MODS_DEPRESSED);
- /* Ignore the lock modifier mask, that one cannot be sticky, yet the
- * CAPS_LOCK key itself counts as a modifier as it might be remapped
- * to some other modifier which can be sticky.
- */
- depressed_mods &= ~CLUTTER_LOCK_MASK;
-
- new_latched_mask = device->stickykeys_latched_mask;
- new_locked_mask = device->stickykeys_locked_mask;
-
- device->stickykeys_depressed_mask = depressed_mods;
-
- if (new_locked_mask & depressed_mods)
- {
- new_locked_mask &= ~depressed_mods;
- }
- else if (new_latched_mask & depressed_mods)
- {
- new_locked_mask |= depressed_mods;
- new_latched_mask &= ~depressed_mods;
- }
- else
- {
- new_latched_mask |= depressed_mods;
- }
-
- update_stickykeys_event (event, device, new_latched_mask, new_locked_mask);
-}
-
-static void
-handle_stickykeys_release (ClutterEvent *event,
- MetaInputDeviceNative *device)
-{
- MetaSeatImpl *seat_impl = device->seat_impl;
- struct xkb_state *xkb_state;
-
- xkb_state = meta_seat_impl_get_xkb_state_in_impl (seat_impl);
- device->stickykeys_depressed_mask =
- xkb_state_serialize_mods (xkb_state, XKB_STATE_MODS_DEPRESSED);
-
- if (key_event_is_modifier (event))
- {
- if (device->a11y_flags & META_A11Y_STICKY_KEYS_BEEP)
- meta_input_device_native_bell_notify (device);
-
- return;
- }
-
- if (device->stickykeys_latched_mask == 0)
- return;
-
- update_stickykeys_event (event, device, 0, device->stickykeys_locked_mask);
-}
-
-static gboolean
-trigger_toggle_slowkeys (gpointer data)
-{
- MetaInputDeviceNative *device = data;
-
- device->toggle_slowkeys_timer = 0;
-
- if (device->a11y_flags & META_A11Y_FEATURE_STATE_CHANGE_BEEP)
- meta_input_device_native_bell_notify (device);
-
- if (device->a11y_flags & META_A11Y_SLOW_KEYS_ENABLED)
- set_slowkeys_off (device);
- else
- set_slowkeys_on (device);
-
- return G_SOURCE_REMOVE;
-}
-
-static void
-start_toggle_slowkeys (MetaInputDeviceNative *device)
-{
- if (device->toggle_slowkeys_timer != 0)
- return;
-
- device->toggle_slowkeys_timer =
- timeout_source_new (device->seat_impl,
- 8 * 1000 /* 8 secs */,
- trigger_toggle_slowkeys,
- device);
-}
-
-static void
-stop_toggle_slowkeys (MetaInputDeviceNative *device)
-{
- g_clear_pointer (&device->toggle_slowkeys_timer, g_source_destroy);
-}
-
-static void
-handle_enablekeys_press (ClutterEvent *event,
- MetaInputDeviceNative *device)
-{
- if (event->key.keyval == XKB_KEY_Shift_L || event->key.keyval == XKB_KEY_Shift_R)
- {
- start_toggle_slowkeys (device);
-
- if (event->key.time > device->last_shift_time + 15 * 1000 /* 15 secs */)
- device->shift_count = 1;
- else
- device->shift_count++;
-
- device->last_shift_time = event->key.time;
- }
- else
- {
- device->shift_count = 0;
- stop_toggle_slowkeys (device);
- }
-}
-
-static void
-handle_enablekeys_release (ClutterEvent *event,
- MetaInputDeviceNative *device)
-{
- if (event->key.keyval == XKB_KEY_Shift_L || event->key.keyval == XKB_KEY_Shift_R)
- {
- stop_toggle_slowkeys (device);
- if (device->shift_count >= 5)
- {
- device->shift_count = 0;
-
- if (device->a11y_flags & META_A11Y_FEATURE_STATE_CHANGE_BEEP)
- meta_input_device_native_bell_notify (device);
-
- if (device->a11y_flags & META_A11Y_STICKY_KEYS_ENABLED)
- set_stickykeys_off (device);
- else
- set_stickykeys_on (device);
- }
- }
-}
-
-static int
-get_button_index (int button)
-{
- switch (button)
- {
- case CLUTTER_BUTTON_PRIMARY:
- return 0;
- case CLUTTER_BUTTON_MIDDLE:
- return 1;
- case CLUTTER_BUTTON_SECONDARY:
- return 2;
- default:
- break;
- }
-
- g_warn_if_reached ();
- return 0;
-}
-
-static void
-emulate_button_press (MetaInputDeviceNative *device_evdev)
-{
- ClutterInputDevice *device = CLUTTER_INPUT_DEVICE (device_evdev);
- int btn = device_evdev->mousekeys_btn;
-
- if (device_evdev->mousekeys_btn_states[get_button_index (btn)])
- return;
-
- clutter_virtual_input_device_notify_button (device->accessibility_virtual_device,
- g_get_monotonic_time (), btn,
- CLUTTER_BUTTON_STATE_PRESSED);
- device_evdev->mousekeys_btn_states[get_button_index (btn)] = CLUTTER_BUTTON_STATE_PRESSED;
-}
-
-static void
-emulate_button_release (MetaInputDeviceNative *device_evdev)
-{
- ClutterInputDevice *device = CLUTTER_INPUT_DEVICE (device_evdev);
- int btn = device_evdev->mousekeys_btn;
-
- if (device_evdev->mousekeys_btn_states[get_button_index (btn)] == CLUTTER_BUTTON_STATE_RELEASED)
- return;
-
- clutter_virtual_input_device_notify_button (device->accessibility_virtual_device,
- g_get_monotonic_time (), btn,
- CLUTTER_BUTTON_STATE_RELEASED);
- device_evdev->mousekeys_btn_states[get_button_index (btn)] = CLUTTER_BUTTON_STATE_RELEASED;
-}
-
-static void
-emulate_button_click (MetaInputDeviceNative *device)
-{
- emulate_button_press (device);
- emulate_button_release (device);
-}
-
-#define MOUSEKEYS_CURVE (1.0 + (((double) 50.0) * 0.001))
-
-static void
-update_mousekeys_params (MetaInputDeviceNative *device,
- MetaKbdA11ySettings *settings)
-{
- /* Prevent us from broken settings values */
- device->mousekeys_max_speed = MAX (1, settings->mousekeys_max_speed);
- device->mousekeys_accel_time = MAX (1, settings->mousekeys_accel_time);
- device->mousekeys_init_delay = MAX (0, settings->mousekeys_init_delay);
-
- device->mousekeys_curve_factor =
- (((double) device->mousekeys_max_speed) /
- pow ((double) device->mousekeys_accel_time, MOUSEKEYS_CURVE));
-}
-
-static double
-mousekeys_get_speed_factor (MetaInputDeviceNative *device,
- uint64_t time_us)
-{
- uint32_t time;
- int64_t delta_t;
- int64_t init_time;
- double speed;
-
- time = us2ms (time_us);
-
- if (device->mousekeys_first_motion_time == 0)
- {
- /* Start acceleration _after_ the first move, so take
- * mousekeys_init_delay into account for t0
- */
- device->mousekeys_first_motion_time = time + device->mousekeys_init_delay;
- device->mousekeys_last_motion_time = device->mousekeys_first_motion_time;
- return 1.0;
- }
-
- init_time = time - device->mousekeys_first_motion_time;
- delta_t = time - device->mousekeys_last_motion_time;
-
- if (delta_t < 0)
- return 0.0;
-
- if (init_time < device->mousekeys_accel_time)
- speed = (double) (device->mousekeys_curve_factor *
- pow ((double) init_time, MOUSEKEYS_CURVE) * delta_t / 1000.0);
- else
- speed = (double) (device->mousekeys_max_speed * delta_t / 1000.0);
-
- device->mousekeys_last_motion_time = time;
-
- return speed;
-}
-
-#undef MOUSEKEYS_CURVE
-
-static void
-emulate_pointer_motion (MetaInputDeviceNative *device_evdev,
- int dx,
- int dy)
-{
- ClutterInputDevice *device = CLUTTER_INPUT_DEVICE (device_evdev);
- double dx_motion;
- double dy_motion;
- double speed;
- int64_t time_us;
-
- time_us = g_get_monotonic_time ();
- speed = mousekeys_get_speed_factor (device_evdev, time_us);
-
- if (dx < 0)
- dx_motion = floor (((double) dx) * speed);
- else
- dx_motion = ceil (((double) dx) * speed);
-
- if (dy < 0)
- dy_motion = floor (((double) dy) * speed);
- else
- dy_motion = ceil (((double) dy) * speed);
-
- clutter_virtual_input_device_notify_relative_motion (device->accessibility_virtual_device,
- time_us, dx_motion, dy_motion);
-}
-static gboolean
-is_numlock_active (MetaInputDeviceNative *device)
-{
- MetaSeatImpl *seat_impl = device->seat_impl;
- struct xkb_state *xkb_state;
-
- xkb_state = meta_seat_impl_get_xkb_state_in_impl (seat_impl);
-
- return xkb_state_mod_name_is_active (xkb_state,
- "Mod2",
- XKB_STATE_MODS_LOCKED);
-}
-
-static void
-enable_mousekeys (MetaInputDeviceNative *device_evdev)
-{
- ClutterInputDevice *device = CLUTTER_INPUT_DEVICE (device_evdev);
-
- device_evdev->mousekeys_btn = CLUTTER_BUTTON_PRIMARY;
- device_evdev->move_mousekeys_timer = 0;
- device_evdev->mousekeys_first_motion_time = 0;
- device_evdev->mousekeys_last_motion_time = 0;
- device_evdev->last_mousekeys_key = 0;
-
- if (device->accessibility_virtual_device)
- return;
-
- device->accessibility_virtual_device =
- clutter_seat_create_virtual_device (clutter_input_device_get_seat (device),
- CLUTTER_POINTER_DEVICE);
-}
-
-static void
-disable_mousekeys (MetaInputDeviceNative *device_evdev)
-{
- ClutterInputDevice *device = CLUTTER_INPUT_DEVICE (device_evdev);
-
- stop_mousekeys_move (device_evdev);
-
- /* Make sure we don't leave button pressed behind... */
- if (device_evdev->mousekeys_btn_states[get_button_index (CLUTTER_BUTTON_PRIMARY)])
- {
- device_evdev->mousekeys_btn = CLUTTER_BUTTON_PRIMARY;
- emulate_button_release (device_evdev);
- }
-
- if (device_evdev->mousekeys_btn_states[get_button_index (CLUTTER_BUTTON_MIDDLE)])
- {
- device_evdev->mousekeys_btn = CLUTTER_BUTTON_MIDDLE;
- emulate_button_release (device_evdev);
- }
-
- if (device_evdev->mousekeys_btn_states[get_button_index (CLUTTER_BUTTON_SECONDARY)])
- {
- device_evdev->mousekeys_btn = CLUTTER_BUTTON_SECONDARY;
- emulate_button_release (device_evdev);
- }
-
- if (device->accessibility_virtual_device)
- g_clear_object (&device->accessibility_virtual_device);
-}
-
-static gboolean
-trigger_mousekeys_move (gpointer data)
-{
- MetaInputDeviceNative *device = data;
- int dx = 0;
- int dy = 0;
-
- if (device->mousekeys_first_motion_time == 0)
- {
- /* This is the first move, Secdule at mk_init_delay */
- device->move_mousekeys_timer =
- timeout_source_new (device->seat_impl,
- device->mousekeys_init_delay,
- trigger_mousekeys_move,
- device);
-
- }
- else
- {
- /* More moves, reschedule at mk_interval */
- device->move_mousekeys_timer =
- timeout_source_new (device->seat_impl,
- 100, /* msec between mousekey events */
- trigger_mousekeys_move,
- device);
- }
-
- /* Pointer motion */
- switch (device->last_mousekeys_key)
- {
- case XKB_KEY_KP_Home:
- case XKB_KEY_KP_7:
- case XKB_KEY_KP_Up:
- case XKB_KEY_KP_8:
- case XKB_KEY_KP_Page_Up:
- case XKB_KEY_KP_9:
- dy = -1;
- break;
- case XKB_KEY_KP_End:
- case XKB_KEY_KP_1:
- case XKB_KEY_KP_Down:
- case XKB_KEY_KP_2:
- case XKB_KEY_KP_Page_Down:
- case XKB_KEY_KP_3:
- dy = 1;
- break;
- default:
- break;
- }
-
- switch (device->last_mousekeys_key)
- {
- case XKB_KEY_KP_Home:
- case XKB_KEY_KP_7:
- case XKB_KEY_KP_Left:
- case XKB_KEY_KP_4:
- case XKB_KEY_KP_End:
- case XKB_KEY_KP_1:
- dx = -1;
- break;
- case XKB_KEY_KP_Page_Up:
- case XKB_KEY_KP_9:
- case XKB_KEY_KP_Right:
- case XKB_KEY_KP_6:
- case XKB_KEY_KP_Page_Down:
- case XKB_KEY_KP_3:
- dx = 1;
- break;
- default:
- break;
- }
-
- if (dx != 0 || dy != 0)
- emulate_pointer_motion (device, dx, dy);
-
- /* We reschedule each time */
- return G_SOURCE_REMOVE;
-}
-
-static void
-stop_mousekeys_move (MetaInputDeviceNative *device)
-{
- device->mousekeys_first_motion_time = 0;
- device->mousekeys_last_motion_time = 0;
-
- g_clear_pointer (&device->move_mousekeys_timer, g_source_destroy);
-}
-
-static void
-start_mousekeys_move (ClutterEvent *event,
- MetaInputDeviceNative *device)
-{
- device->last_mousekeys_key = event->key.keyval;
-
- if (device->move_mousekeys_timer != 0)
- return;
-
- trigger_mousekeys_move (device);
-}
-
-static gboolean
-handle_mousekeys_press (ClutterEvent *event,
- MetaInputDeviceNative *device)
-{
- if (!(event->key.flags & CLUTTER_EVENT_FLAG_SYNTHETIC))
- stop_mousekeys_move (device);
-
- /* Do not handle mousekeys if NumLock is ON */
- if (is_numlock_active (device))
- return FALSE;
-
- /* Button selection */
- switch (event->key.keyval)
- {
- case XKB_KEY_KP_Divide:
- device->mousekeys_btn = CLUTTER_BUTTON_PRIMARY;
- return TRUE;
- case XKB_KEY_KP_Multiply:
- device->mousekeys_btn = CLUTTER_BUTTON_MIDDLE;
- return TRUE;
- case XKB_KEY_KP_Subtract:
- device->mousekeys_btn = CLUTTER_BUTTON_SECONDARY;
- return TRUE;
- default:
- break;
- }
-
- /* Button events */
- switch (event->key.keyval)
- {
- case XKB_KEY_KP_Begin:
- case XKB_KEY_KP_5:
- emulate_button_click (device);
- return TRUE;
- case XKB_KEY_KP_Insert:
- case XKB_KEY_KP_0:
- emulate_button_press (device);
- return TRUE;
- case XKB_KEY_KP_Decimal:
- case XKB_KEY_KP_Delete:
- emulate_button_release (device);
- return TRUE;
- case XKB_KEY_KP_Add:
- emulate_button_click (device);
- emulate_button_click (device);
- return TRUE;
- default:
- break;
- }
-
- /* Pointer motion */
- switch (event->key.keyval)
- {
- case XKB_KEY_KP_1:
- case XKB_KEY_KP_2:
- case XKB_KEY_KP_3:
- case XKB_KEY_KP_4:
- case XKB_KEY_KP_6:
- case XKB_KEY_KP_7:
- case XKB_KEY_KP_8:
- case XKB_KEY_KP_9:
- case XKB_KEY_KP_Down:
- case XKB_KEY_KP_End:
- case XKB_KEY_KP_Home:
- case XKB_KEY_KP_Left:
- case XKB_KEY_KP_Page_Down:
- case XKB_KEY_KP_Page_Up:
- case XKB_KEY_KP_Right:
- case XKB_KEY_KP_Up:
- start_mousekeys_move (event, device);
- return TRUE;
- default:
- break;
- }
-
- return FALSE;
-}
-
-static gboolean
-handle_mousekeys_release (ClutterEvent *event,
- MetaInputDeviceNative *device)
-{
- /* Do not handle mousekeys if NumLock is ON */
- if (is_numlock_active (device))
- return FALSE;
-
- switch (event->key.keyval)
- {
- case XKB_KEY_KP_0:
- case XKB_KEY_KP_1:
- case XKB_KEY_KP_2:
- case XKB_KEY_KP_3:
- case XKB_KEY_KP_4:
- case XKB_KEY_KP_5:
- case XKB_KEY_KP_6:
- case XKB_KEY_KP_7:
- case XKB_KEY_KP_8:
- case XKB_KEY_KP_9:
- case XKB_KEY_KP_Add:
- case XKB_KEY_KP_Begin:
- case XKB_KEY_KP_Decimal:
- case XKB_KEY_KP_Delete:
- case XKB_KEY_KP_Divide:
- case XKB_KEY_KP_Down:
- case XKB_KEY_KP_End:
- case XKB_KEY_KP_Home:
- case XKB_KEY_KP_Insert:
- case XKB_KEY_KP_Left:
- case XKB_KEY_KP_Multiply:
- case XKB_KEY_KP_Page_Down:
- case XKB_KEY_KP_Page_Up:
- case XKB_KEY_KP_Right:
- case XKB_KEY_KP_Subtract:
- case XKB_KEY_KP_Up:
- stop_mousekeys_move (device);
- return TRUE;
- default:
- break;
- }
-
- return FALSE;
-}
-
-gboolean
-meta_input_device_native_process_kbd_a11y_event_in_impl (ClutterInputDevice *device,
- ClutterEvent *event)
-{
- MetaInputDeviceNative *device_evdev = META_INPUT_DEVICE_NATIVE (device);
-
- if (device_evdev->a11y_flags & META_A11Y_KEYBOARD_ENABLED)
- {
- if (event->type == CLUTTER_KEY_PRESS)
- handle_enablekeys_press (event, device_evdev);
- else
- handle_enablekeys_release (event, device_evdev);
- }
-
- if (device_evdev->a11y_flags & META_A11Y_MOUSE_KEYS_ENABLED)
- {
- if (event->type == CLUTTER_KEY_PRESS &&
- handle_mousekeys_press (event, device_evdev))
- return TRUE; /* swallow event */
- if (event->type == CLUTTER_KEY_RELEASE &&
- handle_mousekeys_release (event, device_evdev))
- return TRUE; /* swallow event */
- }
-
- if ((device_evdev->a11y_flags & META_A11Y_BOUNCE_KEYS_ENABLED) &&
- (get_debounce_delay (device) != 0))
- {
- if ((event->type == CLUTTER_KEY_PRESS) && debounce_key (event, device_evdev))
- {
- notify_bounce_keys_reject (device_evdev);
-
- return TRUE;
- }
- else if (event->type == CLUTTER_KEY_RELEASE)
- start_bounce_keys (event, device_evdev);
- }
-
- if ((device_evdev->a11y_flags & META_A11Y_SLOW_KEYS_ENABLED) &&
- (get_slow_keys_delay (device) != 0))
- {
- if (event->type == CLUTTER_KEY_PRESS)
- return start_slow_keys (event, device_evdev);
- else if (event->type == CLUTTER_KEY_RELEASE)
- return stop_slow_keys (event, device_evdev);
- }
-
- if (device_evdev->a11y_flags & META_A11Y_STICKY_KEYS_ENABLED)
- {
- if (event->type == CLUTTER_KEY_PRESS)
- handle_stickykeys_press (event, device_evdev);
- else if (event->type == CLUTTER_KEY_RELEASE)
- handle_stickykeys_release (event, device_evdev);
- }
-
- return FALSE;
-}
-
-void
-meta_input_device_native_apply_kbd_a11y_settings_in_impl (MetaInputDeviceNative *device,
- MetaKbdA11ySettings *settings)
-{
- MetaKeyboardA11yFlags changed_flags = (device->a11y_flags ^ settings->controls);
-
- if (changed_flags & (META_A11Y_KEYBOARD_ENABLED | META_A11Y_SLOW_KEYS_ENABLED))
- clear_slow_keys (device);
-
- if (changed_flags & (META_A11Y_KEYBOARD_ENABLED | META_A11Y_BOUNCE_KEYS_ENABLED))
- device->debounce_key = 0;
-
- if (changed_flags & (META_A11Y_KEYBOARD_ENABLED | META_A11Y_STICKY_KEYS_ENABLED))
- {
- device->stickykeys_depressed_mask = 0;
- update_internal_xkb_state (device, 0, 0);
- }
-
- if (changed_flags & META_A11Y_KEYBOARD_ENABLED)
- {
- device->toggle_slowkeys_timer = 0;
- device->shift_count = 0;
- device->last_shift_time = 0;
- }
-
- if (changed_flags & (META_A11Y_KEYBOARD_ENABLED | META_A11Y_MOUSE_KEYS_ENABLED))
- {
- if (settings->controls &
- (META_A11Y_KEYBOARD_ENABLED | META_A11Y_MOUSE_KEYS_ENABLED))
- enable_mousekeys (device);
- else
- disable_mousekeys (device);
- }
- update_mousekeys_params (device, settings);
-
- /* Keep our own copy of keyboard a11y features flags to see what changes */
- device->a11y_flags = settings->controls;
-}
-
-void
-meta_input_device_native_a11y_maybe_notify_toggle_keys_in_impl (MetaInputDeviceNative *device)
-{
- if (device->a11y_flags & META_A11Y_TOGGLE_KEYS_ENABLED)
- meta_input_device_native_bell_notify (device);
-}
-
-static void
-meta_input_device_native_class_init (MetaInputDeviceNativeClass *klass)
-{
- ClutterInputDeviceClass *device_class = CLUTTER_INPUT_DEVICE_CLASS (klass);
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- object_class->finalize = meta_input_device_native_finalize;
- object_class->set_property = meta_input_device_native_set_property;
- object_class->get_property = meta_input_device_native_get_property;
-
- device_class->is_mode_switch_button = meta_input_device_native_is_mode_switch_button;
- device_class->get_group_n_modes = meta_input_device_native_get_group_n_modes;
- device_class->is_grouped = meta_input_device_native_is_grouped;
- device_class->get_pad_feature_group = meta_input_device_native_get_pad_feature_group;
-
- obj_props[PROP_DEVICE_MATRIX] =
- g_param_spec_boxed ("device-matrix",
- "Device input matrix",
- "Device input matrix",
- CAIRO_GOBJECT_TYPE_MATRIX,
- CLUTTER_PARAM_READWRITE);
- obj_props[PROP_OUTPUT_ASPECT_RATIO] =
- g_param_spec_double ("output-aspect-ratio",
- "Output aspect ratio",
- "Output aspect ratio",
- 0, G_MAXDOUBLE, 0,
- CLUTTER_PARAM_READWRITE);
-
- g_object_class_install_properties (object_class, N_PROPS, obj_props);
-}
-
-static void
-meta_input_device_native_init (MetaInputDeviceNative *self)
-{
- cairo_matrix_init_identity (&self->device_matrix);
- self->device_aspect_ratio = 0;
- self->output_ratio = 0;
-}
-
-static void
-update_pad_features (MetaInputDeviceNative *device_native)
-{
- ClutterInputDevice *device = CLUTTER_INPUT_DEVICE (device_native);
- struct libinput_device *libinput_device;
- struct libinput_tablet_pad_mode_group *mode_group;
- int n_groups, n_buttons, n_rings, n_strips, n_modes, i, j;
-
- libinput_device = meta_input_device_native_get_libinput_device (device);
- n_rings = libinput_device_tablet_pad_get_num_rings (libinput_device);
- n_strips = libinput_device_tablet_pad_get_num_strips (libinput_device);
- n_groups = libinput_device_tablet_pad_get_num_mode_groups (libinput_device);
- n_buttons = libinput_device_tablet_pad_get_num_buttons (libinput_device);
-
- device_native->pad_features = g_array_new (FALSE, FALSE, sizeof (PadFeature));
- device_native->modes = g_array_sized_new (FALSE, FALSE, sizeof (int), n_groups);
-
- for (i = 0; i < n_groups; i++)
- {
- mode_group =
- libinput_device_tablet_pad_get_mode_group (libinput_device, i);
-
- n_modes = libinput_tablet_pad_mode_group_get_num_modes (mode_group);
- g_array_append_val (device_native->modes, n_modes);
-
- for (j = 0; j < n_buttons; j++)
- {
- gboolean is_mode_switch =
- libinput_tablet_pad_mode_group_button_is_toggle (mode_group, j) != 0;
- PadFeature feature = { CLUTTER_PAD_FEATURE_BUTTON, j, i, is_mode_switch };
-
- if (libinput_tablet_pad_mode_group_has_button (mode_group, j))
- g_array_append_val (device_native->pad_features, feature);
- }
-
- for (j = 0; j < n_rings; j++)
- {
- PadFeature feature = { CLUTTER_PAD_FEATURE_RING, j, i };
-
- if (libinput_tablet_pad_mode_group_has_ring (mode_group, j))
- g_array_append_val (device_native->pad_features, feature);
- }
-
- for (j = 0; j < n_strips; j++)
- {
- PadFeature feature = { CLUTTER_PAD_FEATURE_STRIP, j, i };
-
- if (libinput_tablet_pad_mode_group_has_strip (mode_group, j))
- g_array_append_val (device_native->pad_features, feature);
- }
- }
-}
-
-/*
- * meta_input_device_native_new:
- * @manager: the device manager
- * @seat: the seat the device will belong to
- * @libinput_device: the libinput device
- *
- * Create a new ClutterInputDevice given a libinput device and associate
- * it with the provided seat.
- */
-ClutterInputDevice *
-meta_input_device_native_new_in_impl (MetaSeatImpl *seat_impl,
- struct libinput_device *libinput_device)
-{
- MetaInputDeviceNative *device;
- ClutterInputDeviceType type;
- char *vendor, *product;
- int n_rings = 0, n_strips = 0, n_groups = 1, n_buttons = 0;
- char *node_path;
- double width, height;
-
- type = meta_input_device_native_determine_type_in_impl (libinput_device);
- vendor = g_strdup_printf ("%.4x", libinput_device_get_id_vendor (libinput_device));
- product = g_strdup_printf ("%.4x", libinput_device_get_id_product (libinput_device));
- node_path = g_strdup_printf ("/dev/input/%s", libinput_device_get_sysname (libinput_device));
-
- if (libinput_device_has_capability (libinput_device,
- LIBINPUT_DEVICE_CAP_TABLET_PAD))
- {
- n_rings = libinput_device_tablet_pad_get_num_rings (libinput_device);
- n_strips = libinput_device_tablet_pad_get_num_strips (libinput_device);
- n_groups = libinput_device_tablet_pad_get_num_mode_groups (libinput_device);
- n_buttons = libinput_device_tablet_pad_get_num_buttons (libinput_device);
- }
-
- device = g_object_new (META_TYPE_INPUT_DEVICE_NATIVE,
- "name", libinput_device_get_name (libinput_device),
- "device-type", type,
- "device-mode", CLUTTER_INPUT_MODE_PHYSICAL,
- "vendor-id", vendor,
- "product-id", product,
- "n-rings", n_rings,
- "n-strips", n_strips,
- "n-mode-groups", n_groups,
- "n-buttons", n_buttons,
- "device-node", node_path,
- "seat", seat_impl->seat_native,
- NULL);
-
- device->seat_impl = seat_impl;
- device->libinput_device = libinput_device;
-
- libinput_device_set_user_data (libinput_device, device);
- libinput_device_ref (libinput_device);
- g_free (vendor);
- g_free (product);
- g_free (node_path);
-
- if (libinput_device_has_capability (libinput_device,
- LIBINPUT_DEVICE_CAP_TABLET_PAD))
- update_pad_features (device);
-
- if (libinput_device_get_size (libinput_device, &width, &height) == 0)
- device->device_aspect_ratio = width / height;
-
- device->group = (intptr_t) libinput_device_get_device_group (libinput_device);
-
- return CLUTTER_INPUT_DEVICE (device);
-}
-
-/*
- * meta_input_device_native_new_virtual:
- * @seat: the seat the device will belong to
- * @type: the input device type
- *
- * Create a new virtual ClutterInputDevice of the given type.
- */
-ClutterInputDevice *
-meta_input_device_native_new_virtual (MetaSeatImpl *seat_impl,
- ClutterInputDeviceType type,
- ClutterInputMode mode)
-{
- MetaInputDeviceNative *device;
- const char *name;
-
- switch (type)
- {
- case CLUTTER_KEYBOARD_DEVICE:
- name = "Virtual keyboard device for seat";
- break;
- case CLUTTER_POINTER_DEVICE:
- name = "Virtual pointer device for seat";
- break;
- case CLUTTER_TOUCHSCREEN_DEVICE:
- name = "Virtual touchscreen device for seat";
- break;
- default:
- name = "Virtual device for seat";
- break;
- };
-
- device = g_object_new (META_TYPE_INPUT_DEVICE_NATIVE,
- "name", name,
- "device-type", type,
- "device-mode", mode,
- "seat", seat_impl->seat_native,
- NULL);
-
- device->seat_impl = seat_impl;
-
- return CLUTTER_INPUT_DEVICE (device);
-}
-
-MetaSeatImpl *
-meta_input_device_native_get_seat_impl (MetaInputDeviceNative *device)
-{
- return device->seat_impl;
-}
-
-void
-meta_input_device_native_update_leds_in_impl (MetaInputDeviceNative *device,
- enum libinput_led leds)
-{
- if (!device->libinput_device)
- return;
-
- libinput_device_led_update (device->libinput_device, leds);
-}
-
-ClutterInputDeviceType
-meta_input_device_native_determine_type_in_impl (struct libinput_device *ldev)
-{
- /* This setting is specific to touchpads and alike, only in these
- * devices there is this additional layer of touch event interpretation.
- */
- if (libinput_device_config_tap_get_finger_count (ldev) > 0)
- return CLUTTER_TOUCHPAD_DEVICE;
- else if (libinput_device_has_capability (ldev, LIBINPUT_DEVICE_CAP_TABLET_TOOL))
- return CLUTTER_TABLET_DEVICE;
- else if (libinput_device_has_capability (ldev, LIBINPUT_DEVICE_CAP_TABLET_PAD))
- return CLUTTER_PAD_DEVICE;
- else if (libinput_device_has_capability (ldev, LIBINPUT_DEVICE_CAP_POINTER))
- return CLUTTER_POINTER_DEVICE;
- else if (libinput_device_has_capability (ldev, LIBINPUT_DEVICE_CAP_TOUCH))
- return CLUTTER_TOUCHSCREEN_DEVICE;
- else if (libinput_device_has_capability (ldev, LIBINPUT_DEVICE_CAP_KEYBOARD))
- return CLUTTER_KEYBOARD_DEVICE;
- else
- return CLUTTER_EXTENSION_DEVICE;
-}
-
-/**
- * meta_input_device_native_get_libinput_device:
- * @device: a #ClutterInputDevice
- *
- * Retrieves the libinput_device struct held in @device.
- *
- * Returns: The libinput_device struct
- *
- * Since: 1.20
- * Stability: unstable
- **/
-struct libinput_device *
-meta_input_device_native_get_libinput_device (ClutterInputDevice *device)
-{
- MetaInputDeviceNative *device_evdev;
-
- g_return_val_if_fail (META_IS_INPUT_DEVICE_NATIVE (device), NULL);
-
- device_evdev = META_INPUT_DEVICE_NATIVE (device);
-
- return device_evdev->libinput_device;
-}
-
-void
-meta_input_device_native_translate_coordinates_in_impl (ClutterInputDevice *device,
- MetaViewportInfo *viewports,
- float *x,
- float *y)
-{
- MetaInputDeviceNative *device_evdev = META_INPUT_DEVICE_NATIVE (device);
- double min_x = 0, min_y = 0, max_x = 1, max_y = 1;
- float stage_width, stage_height;
- double x_d, y_d;
-
- meta_viewport_info_get_extents (viewports, &stage_width, &stage_height);
- x_d = *x / stage_width;
- y_d = *y / stage_height;
-
- /* Apply aspect ratio */
- if (device_evdev->output_ratio > 0 &&
- device_evdev->device_aspect_ratio > 0)
- {
- double ratio = device_evdev->device_aspect_ratio / device_evdev->output_ratio;
-
- if (ratio > 1)
- x_d *= ratio;
- else if (ratio < 1)
- y_d *= 1 / ratio;
- }
-
- cairo_matrix_transform_point (&device_evdev->device_matrix, &min_x, &min_y);
- cairo_matrix_transform_point (&device_evdev->device_matrix, &max_x, &max_y);
- cairo_matrix_transform_point (&device_evdev->device_matrix, &x_d, &y_d);
-
- *x = CLAMP (x_d, MIN (min_x, max_x), MAX (min_x, max_x)) * stage_width;
- *y = CLAMP (y_d, MIN (min_y, max_y), MAX (min_y, max_y)) * stage_height;
-}
-
-MetaInputDeviceMapping
-meta_input_device_native_get_mapping_mode_in_impl (ClutterInputDevice *device)
-{
- MetaInputDeviceNative *device_native = META_INPUT_DEVICE_NATIVE (device);
- ClutterInputDeviceType device_type;
-
- g_return_val_if_fail (CLUTTER_IS_INPUT_DEVICE (device),
- META_INPUT_DEVICE_MAPPING_ABSOLUTE);
-
- device_type = clutter_input_device_get_device_type (device);
- g_return_val_if_fail (device_type == CLUTTER_TABLET_DEVICE ||
- device_type == CLUTTER_PEN_DEVICE ||
- device_type == CLUTTER_ERASER_DEVICE,
- META_INPUT_DEVICE_MAPPING_ABSOLUTE);
-
- return device_native->mapping_mode;
-}
-
-void
-meta_input_device_native_set_mapping_mode_in_impl (ClutterInputDevice *device,
- MetaInputDeviceMapping mapping)
-{
- MetaInputDeviceNative *device_native = META_INPUT_DEVICE_NATIVE (device);
- ClutterInputDeviceType device_type;
-
- g_return_if_fail (CLUTTER_IS_INPUT_DEVICE (device));
-
- device_type = clutter_input_device_get_device_type (device);
- g_return_if_fail (device_type == CLUTTER_TABLET_DEVICE ||
- device_type == CLUTTER_PEN_DEVICE ||
- device_type == CLUTTER_ERASER_DEVICE);
-
- device_native->mapping_mode = mapping;
-}
-
-void
-meta_input_device_native_set_coords_in_impl (MetaInputDeviceNative *device_native,
- float x,
- float y)
-{
- device_native->pointer_x = x;
- device_native->pointer_y = y;
-}
-
-void
-meta_input_device_native_get_coords_in_impl (MetaInputDeviceNative *device_native,
- float *x,
- float *y)
-{
- if (x)
- *x = device_native->pointer_x;
- if (y)
- *y = device_native->pointer_y;
-}
-
-void
-meta_input_device_native_detach_libinput_in_impl (MetaInputDeviceNative *device_native)
-{
- g_clear_pointer (&device_native->libinput_device, libinput_device_unref);
-}
diff --git a/src/backends/native/meta-input-device-native.h b/src/backends/native/meta-input-device-native.h
deleted file mode 100644
index 88af07c43..000000000
--- a/src/backends/native/meta-input-device-native.h
+++ /dev/null
@@ -1,162 +0,0 @@
-/*
- * Clutter.
- *
- * An OpenGL based 'interactive canvas' library.
- *
- * Copyright (C) 2010 Intel Corp.
- * Copyright (C) 2014 Jonas Ådahl
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
- *
- * Author: Damien Lespiau <damien.lespiau@intel.com>
- * Author: Jonas Ådahl <jadahl@gmail.com>
- */
-
-#ifndef META_INPUT_DEVICE_NATIVE_H
-#define META_INPUT_DEVICE_NATIVE_H
-
-#ifndef META_INPUT_THREAD_H_INSIDE
-#error "This header cannot be included directly. Use "backends/native/meta-input-thread.h""
-#endif /* META_INPUT_THREAD_H_INSIDE */
-
-#include <glib-object.h>
-
-#include "backends/meta-input-device-private.h"
-#include "backends/meta-input-settings-private.h"
-#include "backends/native/meta-seat-native.h"
-#include "clutter/clutter-mutter.h"
-
-#define META_TYPE_INPUT_DEVICE_NATIVE meta_input_device_native_get_type()
-
-#define META_INPUT_DEVICE_NATIVE(obj) \
- (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
- META_TYPE_INPUT_DEVICE_NATIVE, MetaInputDeviceNative))
-
-#define META_INPUT_DEVICE_NATIVE_CLASS(klass) \
- (G_TYPE_CHECK_CLASS_CAST ((klass), \
- META_TYPE_INPUT_DEVICE_NATIVE, MetaInputDeviceNativeClass))
-
-#define META_IS_INPUT_DEVICE_NATIVE(obj) \
- (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
- META_TYPE_INPUT_DEVICE_NATIVE))
-
-#define META_IS_INPUT_DEVICE_NATIVE_CLASS(klass) \
- (G_TYPE_CHECK_CLASS_TYPE ((klass), \
- META_TYPE_INPUT_DEVICE_NATIVE))
-
-#define META_INPUT_DEVICE_NATIVE_GET_CLASS(obj) \
- (G_TYPE_INSTANCE_GET_CLASS ((obj), \
- META_TYPE_INPUT_DEVICE_NATIVE, MetaInputDeviceNativeClass))
-
-typedef enum
-{
- META_INPUT_DEVICE_MAPPING_ABSOLUTE,
- META_INPUT_DEVICE_MAPPING_RELATIVE,
-} MetaInputDeviceMapping;
-
-typedef struct _MetaInputDeviceNative MetaInputDeviceNative;
-typedef struct _MetaInputDeviceNativeClass MetaInputDeviceNativeClass;
-
-struct _MetaInputDeviceNative
-{
- ClutterInputDevice parent;
-
- struct libinput_device *libinput_device;
- MetaSeatImpl *seat_impl;
- ClutterInputDeviceTool *last_tool;
- GArray *pad_features;
- GArray *modes;
- intptr_t group;
-
- cairo_matrix_t device_matrix;
- double device_aspect_ratio; /* w:h */
- double output_ratio; /* w:h */
- MetaInputDeviceMapping mapping_mode;
-
- /* Pointer position */
- float pointer_x;
- float pointer_y;
-
- /* Keyboard a11y */
- MetaKeyboardA11yFlags a11y_flags;
- GList *slow_keys_list;
- GSource *debounce_timer;
- uint16_t debounce_key;
- xkb_mod_mask_t stickykeys_depressed_mask;
- xkb_mod_mask_t stickykeys_latched_mask;
- xkb_mod_mask_t stickykeys_locked_mask;
- GSource *toggle_slowkeys_timer;
- uint16_t shift_count;
- uint32_t last_shift_time;
- int mousekeys_btn;
- gboolean mousekeys_btn_states[3];
- uint32_t mousekeys_first_motion_time; /* ms */
- uint32_t mousekeys_last_motion_time; /* ms */
- guint mousekeys_init_delay;
- guint mousekeys_accel_time;
- guint mousekeys_max_speed;
- double mousekeys_curve_factor;
- GSource *move_mousekeys_timer;
- uint16_t last_mousekeys_key;
-};
-
-struct _MetaInputDeviceNativeClass
-{
- ClutterInputDeviceClass parent_class;
-};
-
-GType meta_input_device_native_get_type (void) G_GNUC_CONST;
-
-ClutterInputDevice * meta_input_device_native_new_in_impl (MetaSeatImpl *seat_impl,
- struct libinput_device *libinput_device);
-
-ClutterInputDevice * meta_input_device_native_new_virtual (MetaSeatImpl *seat_impl,
- ClutterInputDeviceType type,
- ClutterInputMode mode);
-
-MetaSeatImpl * meta_input_device_native_get_seat_impl (MetaInputDeviceNative *device);
-
-void meta_input_device_native_update_leds_in_impl (MetaInputDeviceNative *device,
- enum libinput_led leds);
-
-ClutterInputDeviceType meta_input_device_native_determine_type_in_impl (struct libinput_device *libinput_device);
-
-
-void meta_input_device_native_translate_coordinates_in_impl (ClutterInputDevice *device,
- MetaViewportInfo *viewports,
- float *x,
- float *y);
-
-MetaInputDeviceMapping meta_input_device_native_get_mapping_mode_in_impl (ClutterInputDevice *device);
-void meta_input_device_native_set_mapping_mode_in_impl (ClutterInputDevice *device,
- MetaInputDeviceMapping mapping);
-
-void meta_input_device_native_apply_kbd_a11y_settings_in_impl (MetaInputDeviceNative *device,
- MetaKbdA11ySettings *settings);
-
-void meta_input_device_native_a11y_maybe_notify_toggle_keys_in_impl (MetaInputDeviceNative *device_evdev);
-
-struct libinput_device * meta_input_device_native_get_libinput_device (ClutterInputDevice *device);
-
-void meta_input_device_native_set_coords_in_impl (MetaInputDeviceNative *device_native,
- float x,
- float y);
-void meta_input_device_native_get_coords_in_impl (MetaInputDeviceNative *device_native,
- float *x,
- float *y);
-gboolean meta_input_device_native_process_kbd_a11y_event_in_impl (ClutterInputDevice *device,
- ClutterEvent *event);
-void meta_input_device_native_detach_libinput_in_impl (MetaInputDeviceNative *device_native);
-
-#endif /* META_INPUT_DEVICE_NATIVE_H */
diff --git a/src/backends/native/meta-input-device-tool-native.c b/src/backends/native/meta-input-device-tool-native.c
deleted file mode 100644
index e6ec0c758..000000000
--- a/src/backends/native/meta-input-device-tool-native.c
+++ /dev/null
@@ -1,183 +0,0 @@
-/*
- * Copyright © 2009, 2010, 2011 Intel Corp.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
- *
- * Author: Carlos Garnacho <carlosg@gnome.org>
- */
-
-#include "config.h"
-
-#include "backends/native/meta-input-thread.h"
-
-G_DEFINE_TYPE (MetaInputDeviceToolNative, meta_input_device_tool_native,
- CLUTTER_TYPE_INPUT_DEVICE_TOOL)
-
-static void
-meta_input_device_tool_native_finalize (GObject *object)
-{
- MetaInputDeviceToolNative *tool = META_INPUT_DEVICE_TOOL_NATIVE (object);
-
- g_hash_table_unref (tool->button_map);
- libinput_tablet_tool_unref (tool->tool);
-
- G_OBJECT_CLASS (meta_input_device_tool_native_parent_class)->finalize (object);
-}
-
-static void
-meta_input_device_tool_native_class_init (MetaInputDeviceToolNativeClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- object_class->finalize = meta_input_device_tool_native_finalize;
-}
-
-static void
-meta_input_device_tool_native_init (MetaInputDeviceToolNative *tool)
-{
- tool->button_map = g_hash_table_new (NULL, NULL);
-}
-
-static ClutterInputAxisFlags
-translate_axes (struct libinput_tablet_tool *tool)
-{
- ClutterInputAxisFlags axes = 0;
-
- if (libinput_tablet_tool_has_pressure (tool))
- axes |= CLUTTER_INPUT_AXIS_FLAG_PRESSURE;
- if (libinput_tablet_tool_has_distance (tool))
- axes |= CLUTTER_INPUT_AXIS_FLAG_DISTANCE;
- if (libinput_tablet_tool_has_rotation (tool))
- axes |= CLUTTER_INPUT_AXIS_FLAG_ROTATION;
- if (libinput_tablet_tool_has_slider (tool))
- axes |= CLUTTER_INPUT_AXIS_FLAG_SLIDER;
- if (libinput_tablet_tool_has_wheel (tool))
- axes |= CLUTTER_INPUT_AXIS_FLAG_WHEEL;
- if (libinput_tablet_tool_has_tilt (tool))
- axes |= CLUTTER_INPUT_AXIS_FLAG_XTILT | CLUTTER_INPUT_AXIS_FLAG_YTILT;
-
- return axes;
-}
-
-ClutterInputDeviceTool *
-meta_input_device_tool_native_new (struct libinput_tablet_tool *tool,
- uint64_t serial,
- ClutterInputDeviceToolType type)
-{
- MetaInputDeviceToolNative *evdev_tool;
-
- evdev_tool = g_object_new (META_TYPE_INPUT_DEVICE_TOOL_NATIVE,
- "type", type,
- "serial", serial,
- "id", libinput_tablet_tool_get_tool_id (tool),
- "axes", translate_axes (tool),
- NULL);
-
- evdev_tool->tool = libinput_tablet_tool_ref (tool);
-
- return CLUTTER_INPUT_DEVICE_TOOL (evdev_tool);
-}
-
-void
-meta_input_device_tool_native_set_pressure_curve_in_impl (ClutterInputDeviceTool *tool,
- double curve[4])
-{
- MetaInputDeviceToolNative *evdev_tool;
-
- g_return_if_fail (META_IS_INPUT_DEVICE_TOOL_NATIVE (tool));
- g_return_if_fail (curve[0] >= 0 && curve[0] <= 1 &&
- curve[1] >= 0 && curve[1] <= 1 &&
- curve[2] >= 0 && curve[2] <= 1 &&
- curve[3] >= 0 && curve[3] <= 1);
-
- evdev_tool = META_INPUT_DEVICE_TOOL_NATIVE (tool);
- evdev_tool->pressure_curve[0] = curve[0];
- evdev_tool->pressure_curve[1] = curve[1];
- evdev_tool->pressure_curve[2] = curve[2];
- evdev_tool->pressure_curve[3] = curve[3];
-}
-
-void
-meta_input_device_tool_native_set_button_code_in_impl (ClutterInputDeviceTool *tool,
- uint32_t button,
- uint32_t evcode)
-{
- MetaInputDeviceToolNative *evdev_tool;
-
- g_return_if_fail (META_IS_INPUT_DEVICE_TOOL_NATIVE (tool));
-
- evdev_tool = META_INPUT_DEVICE_TOOL_NATIVE (tool);
-
- if (evcode == 0)
- {
- g_hash_table_remove (evdev_tool->button_map, GUINT_TO_POINTER (button));
- }
- else
- {
- g_hash_table_insert (evdev_tool->button_map, GUINT_TO_POINTER (button),
- GUINT_TO_POINTER (evcode));
- }
-}
-
-static double
-calculate_bezier_position (double pos,
- double x1,
- double y1,
- double x2,
- double y2)
-{
- double int1_y, int2_y;
-
- pos = CLAMP (pos, 0, 1);
-
- /* Intersection between 0,0 and x1,y1 */
- int1_y = pos * y1;
-
- /* Intersection between x2,y2 and 1,1 */
- int2_y = (pos * (1 - y2)) + y2;
-
- /* Find the new position in the line traced by the previous points */
- return (pos * (int2_y - int1_y)) + int1_y;
-}
-
-double
-meta_input_device_tool_native_translate_pressure_in_impl (ClutterInputDeviceTool *tool,
- double pressure)
-{
- MetaInputDeviceToolNative *evdev_tool;
-
- g_return_val_if_fail (META_IS_INPUT_DEVICE_TOOL_NATIVE (tool), pressure);
-
- evdev_tool = META_INPUT_DEVICE_TOOL_NATIVE (tool);
-
- return calculate_bezier_position (CLAMP (pressure, 0, 1),
- evdev_tool->pressure_curve[0],
- evdev_tool->pressure_curve[1],
- evdev_tool->pressure_curve[2],
- evdev_tool->pressure_curve[3]);
-}
-
-uint32_t
-meta_input_device_tool_native_get_button_code_in_impl (ClutterInputDeviceTool *tool,
- uint32_t button)
-{
- MetaInputDeviceToolNative *evdev_tool;
-
- g_return_val_if_fail (META_IS_INPUT_DEVICE_TOOL_NATIVE (tool), 0);
-
- evdev_tool = META_INPUT_DEVICE_TOOL_NATIVE (tool);
-
- return GPOINTER_TO_UINT (g_hash_table_lookup (evdev_tool->button_map,
- GUINT_TO_POINTER (button)));
-}
diff --git a/src/backends/native/meta-input-device-tool-native.h b/src/backends/native/meta-input-device-tool-native.h
deleted file mode 100644
index fa12358ad..000000000
--- a/src/backends/native/meta-input-device-tool-native.h
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * Copyright © 2009, 2010, 2011 Intel Corp.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
- *
- * Author: Carlos Garnacho <carlosg@gnome.org>
- */
-
-#ifndef META_INPUT_DEVICE_NATIVE_TOOL_H
-#define META_INPUT_DEVICE_NATIVE_TOOL_H
-
-#ifndef META_INPUT_THREAD_H_INSIDE
-#error "This header cannot be included directly. Use "backends/native/meta-input-thread.h""
-#endif /* META_INPUT_THREAD_H_INSIDE */
-
-#include <libinput.h>
-
-#include "clutter/clutter.h"
-
-G_BEGIN_DECLS
-
-#define META_TYPE_INPUT_DEVICE_TOOL_NATIVE (meta_input_device_tool_native_get_type ())
-
-#define META_INPUT_DEVICE_TOOL_NATIVE(o) \
- (G_TYPE_CHECK_INSTANCE_CAST ((o), \
- META_TYPE_INPUT_DEVICE_TOOL_NATIVE, MetaInputDeviceToolNative))
-
-#define META_IS_INPUT_DEVICE_TOOL_NATIVE(o) \
- (G_TYPE_CHECK_INSTANCE_TYPE ((o), \
- META_TYPE_INPUT_DEVICE_TOOL_NATIVE))
-
-#define META_INPUT_DEVICE_TOOL_NATIVE_CLASS(c) \
- (G_TYPE_CHECK_CLASS_CAST ((c), \
- META_TYPE_INPUT_DEVICE_TOOL_EVDEV, MetaInputDeviceToolNativeClass))
-
-#define META_IS_INPUT_DEVICE_TOOL_NATIVE_CLASS(c) \
- (G_TYPE_CHECK_CLASS_TYPE ((c), \
- META_TYPE_INPUT_DEVICE_TOOL_NATIVE))
-
-#define META_INPUT_DEVICE_TOOL_NATIVE_GET_CLASS(o) \
- (G_TYPE_INSTANCE_GET_CLASS ((o), \
- META_TYPE_INPUT_DEVICE_TOOL_NATIVE, MetaInputDeviceToolNativeClass))
-
-typedef struct _MetaInputDeviceToolNative MetaInputDeviceToolNative;
-typedef struct _MetaInputDeviceToolNativeClass MetaInputDeviceToolNativeClass;
-
-struct _MetaInputDeviceToolNative
-{
- ClutterInputDeviceTool parent_instance;
- struct libinput_tablet_tool *tool;
- GHashTable *button_map;
- double pressure_curve[4];
-};
-
-struct _MetaInputDeviceToolNativeClass
-{
- ClutterInputDeviceToolClass parent_class;
-};
-
-GType meta_input_device_tool_native_get_type (void) G_GNUC_CONST;
-
-ClutterInputDeviceTool * meta_input_device_tool_native_new (struct libinput_tablet_tool *tool,
- uint64_t serial,
- ClutterInputDeviceToolType type);
-
-gdouble meta_input_device_tool_native_translate_pressure_in_impl (ClutterInputDeviceTool *tool,
- double pressure);
-uint32_t meta_input_device_tool_native_get_button_code_in_impl (ClutterInputDeviceTool *tool,
- uint32_t button);
-
-void meta_input_device_tool_native_set_pressure_curve_in_impl (ClutterInputDeviceTool *tool,
- double curve[4]);
-void meta_input_device_tool_native_set_button_code_in_impl (ClutterInputDeviceTool *tool,
- uint32_t button,
- uint32_t evcode);
-
-G_END_DECLS
-
-#endif /* META_INPUT_DEVICE_NATIVE_TOOL_H */
diff --git a/src/backends/native/meta-input-settings-native.c b/src/backends/native/meta-input-settings-native.c
deleted file mode 100644
index 8f61b8bcc..000000000
--- a/src/backends/native/meta-input-settings-native.c
+++ /dev/null
@@ -1,876 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2014 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Author: Carlos Garnacho <carlosg@gnome.org>
- */
-
-#include "config.h"
-
-#include <linux/input-event-codes.h>
-#include <libinput.h>
-
-#include "backends/native/meta-backend-native.h"
-#include "backends/native/meta-input-thread.h"
-#include "backends/native/meta-input-settings-native.h"
-
-G_DEFINE_TYPE (MetaInputSettingsNative, meta_input_settings_native, META_TYPE_INPUT_SETTINGS)
-
-enum
-{
- PROP_0,
- PROP_SEAT_IMPL,
- N_PROPS,
-};
-
-static GParamSpec *props[N_PROPS] = { 0 };
-
-static void
-meta_input_settings_native_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- MetaInputSettingsNative *input_settings_native =
- META_INPUT_SETTINGS_NATIVE (object);
-
- switch (prop_id)
- {
- case PROP_SEAT_IMPL:
- input_settings_native->seat_impl = g_value_get_object (value);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-
-static void
-meta_input_settings_native_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- MetaInputSettingsNative *input_settings_native =
- META_INPUT_SETTINGS_NATIVE (object);
-
- switch (prop_id)
- {
- case PROP_SEAT_IMPL:
- g_value_set_object (value, input_settings_native->seat_impl);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-
-static gboolean
-set_send_events (GTask *task)
-{
- GDesktopDeviceSendEvents mode;
- ClutterInputDevice *device;
- enum libinput_config_send_events_mode libinput_mode;
- struct libinput_device *libinput_device;
-
- device = g_task_get_source_object (task);
- mode = GPOINTER_TO_UINT (g_task_get_task_data (task));
-
- switch (mode)
- {
- case G_DESKTOP_DEVICE_SEND_EVENTS_DISABLED:
- libinput_mode = LIBINPUT_CONFIG_SEND_EVENTS_DISABLED;
- break;
- case G_DESKTOP_DEVICE_SEND_EVENTS_DISABLED_ON_EXTERNAL_MOUSE:
- libinput_mode = LIBINPUT_CONFIG_SEND_EVENTS_DISABLED_ON_EXTERNAL_MOUSE;
- break;
- case G_DESKTOP_DEVICE_SEND_EVENTS_ENABLED:
- libinput_mode = LIBINPUT_CONFIG_SEND_EVENTS_ENABLED;
- break;
- default:
- g_assert_not_reached ();
- }
-
- libinput_device = meta_input_device_native_get_libinput_device (device);
- if (libinput_device)
- libinput_device_config_send_events_set_mode (libinput_device, libinput_mode);
-
- return G_SOURCE_REMOVE;
-}
-
-static void
-meta_input_settings_native_set_send_events (MetaInputSettings *settings,
- ClutterInputDevice *device,
- GDesktopDeviceSendEvents mode)
-{
- MetaInputSettingsNative *input_settings_native;
- GTask *task;
-
- task = g_task_new (device, NULL, NULL, NULL);
- g_task_set_task_data (task, GUINT_TO_POINTER (mode), NULL);
-
- input_settings_native = META_INPUT_SETTINGS_NATIVE (settings);
- meta_seat_impl_run_input_task (input_settings_native->seat_impl,
- task, (GSourceFunc) set_send_events);
- g_object_unref (task);
-}
-
-static gboolean
-set_matrix (GTask *task)
-{
- ClutterInputDevice *device = g_task_get_source_object (task);
- float *matrix = g_task_get_task_data (task);
- cairo_matrix_t dev_matrix;
-
- if (clutter_input_device_get_device_type (device) ==
- CLUTTER_TOUCHSCREEN_DEVICE ||
- meta_input_device_native_get_mapping_mode_in_impl (device) ==
- META_INPUT_DEVICE_MAPPING_ABSOLUTE)
- {
- cairo_matrix_init (&dev_matrix,
- matrix[0], matrix[3], matrix[1],
- matrix[4], matrix[2], matrix[5]);
- }
- else
- {
- cairo_matrix_init_identity (&dev_matrix);
- }
-
- g_object_set (device, "device-matrix", &dev_matrix, NULL);
-
- return G_SOURCE_REMOVE;
-}
-
-static void
-meta_input_settings_native_set_matrix (MetaInputSettings *settings,
- ClutterInputDevice *device,
- const float matrix[6])
-{
- MetaInputSettingsNative *input_settings_native;
- GTask *task;
-
- task = g_task_new (device, NULL, NULL, NULL);
-
- g_task_set_task_data (task, g_memdup2 (matrix, sizeof (float) * 6), g_free);
-
- input_settings_native = META_INPUT_SETTINGS_NATIVE (settings);
- meta_seat_impl_run_input_task (input_settings_native->seat_impl,
- task, (GSourceFunc) set_matrix);
- g_object_unref (task);
-}
-
-static void
-meta_input_settings_native_set_speed (MetaInputSettings *settings,
- ClutterInputDevice *device,
- gdouble speed)
-{
- struct libinput_device *libinput_device;
-
- libinput_device = meta_input_device_native_get_libinput_device (device);
- if (!libinput_device)
- return;
- libinput_device_config_accel_set_speed (libinput_device,
- CLAMP (speed, -1, 1));
-}
-
-static void
-meta_input_settings_native_set_left_handed (MetaInputSettings *settings,
- ClutterInputDevice *device,
- gboolean enabled)
-{
- struct libinput_device *libinput_device;
-
- libinput_device = meta_input_device_native_get_libinput_device (device);
- if (!libinput_device)
- return;
-
- if (libinput_device_config_left_handed_is_available (libinput_device))
- libinput_device_config_left_handed_set (libinput_device, enabled);
-}
-
-static void
-meta_input_settings_native_set_tap_enabled (MetaInputSettings *settings,
- ClutterInputDevice *device,
- gboolean enabled)
-{
- struct libinput_device *libinput_device;
-
- libinput_device = meta_input_device_native_get_libinput_device (device);
- if (!libinput_device)
- return;
-
- if (libinput_device_config_tap_get_finger_count (libinput_device) > 0)
- libinput_device_config_tap_set_enabled (libinput_device,
- enabled ?
- LIBINPUT_CONFIG_TAP_ENABLED :
- LIBINPUT_CONFIG_TAP_DISABLED);
-}
-
-static void
-meta_input_settings_native_set_tap_and_drag_enabled (MetaInputSettings *settings,
- ClutterInputDevice *device,
- gboolean enabled)
-{
- struct libinput_device *libinput_device;
-
- libinput_device = meta_input_device_native_get_libinput_device (device);
- if (!libinput_device)
- return;
-
- if (libinput_device_config_tap_get_finger_count (libinput_device) > 0)
- libinput_device_config_tap_set_drag_enabled (libinput_device,
- enabled ?
- LIBINPUT_CONFIG_DRAG_ENABLED :
- LIBINPUT_CONFIG_DRAG_DISABLED);
-}
-
-static void
-meta_input_settings_native_set_tap_and_drag_lock_enabled (MetaInputSettings *settings,
- ClutterInputDevice *device,
- gboolean enabled)
-{
- struct libinput_device *libinput_device;
-
- libinput_device = meta_input_device_native_get_libinput_device (device);
- if (!libinput_device)
- return;
-
- if (libinput_device_config_tap_get_finger_count (libinput_device) > 0)
- libinput_device_config_tap_set_drag_lock_enabled (libinput_device,
- enabled ?
- LIBINPUT_CONFIG_DRAG_LOCK_ENABLED :
- LIBINPUT_CONFIG_DRAG_LOCK_DISABLED);
-}
-
-static void
-meta_input_settings_native_set_disable_while_typing (MetaInputSettings *settings,
- ClutterInputDevice *device,
- gboolean enabled)
-{
- struct libinput_device *libinput_device;
-
- libinput_device = meta_input_device_native_get_libinput_device (device);
-
- if (!libinput_device)
- return;
-
- if (libinput_device_config_dwt_is_available (libinput_device))
- libinput_device_config_dwt_set_enabled (libinput_device,
- enabled ?
- LIBINPUT_CONFIG_DWT_ENABLED :
- LIBINPUT_CONFIG_DWT_DISABLED);
-}
-
-static void
-meta_input_settings_native_set_invert_scroll (MetaInputSettings *settings,
- ClutterInputDevice *device,
- gboolean inverted)
-{
- struct libinput_device *libinput_device;
-
- libinput_device = meta_input_device_native_get_libinput_device (device);
- if (!libinput_device)
- return;
-
- if (libinput_device_config_scroll_has_natural_scroll (libinput_device))
- libinput_device_config_scroll_set_natural_scroll_enabled (libinput_device,
- inverted);
-}
-
-static gboolean
-device_set_scroll_method (struct libinput_device *libinput_device,
- enum libinput_config_scroll_method method)
-{
- enum libinput_config_status status =
- libinput_device_config_scroll_set_method (libinput_device, method);
- return status == LIBINPUT_CONFIG_STATUS_SUCCESS;
-}
-
-static gboolean
-device_set_click_method (struct libinput_device *libinput_device,
- enum libinput_config_click_method method)
-{
- enum libinput_config_status status =
- libinput_device_config_click_set_method (libinput_device, method);
- return status == LIBINPUT_CONFIG_STATUS_SUCCESS;
-}
-
-static gboolean
-device_set_tap_button_map (struct libinput_device *libinput_device,
- enum libinput_config_tap_button_map map)
-{
- enum libinput_config_status status =
- libinput_device_config_tap_set_button_map (libinput_device, map);
- return status == LIBINPUT_CONFIG_STATUS_SUCCESS;
-}
-
-static void
-meta_input_settings_native_set_edge_scroll (MetaInputSettings *settings,
- ClutterInputDevice *device,
- gboolean edge_scrolling_enabled)
-{
- struct libinput_device *libinput_device;
- enum libinput_config_scroll_method current, method;
-
- libinput_device = meta_input_device_native_get_libinput_device (device);
-
- method = edge_scrolling_enabled ? LIBINPUT_CONFIG_SCROLL_EDGE : LIBINPUT_CONFIG_SCROLL_NO_SCROLL;
- current = libinput_device_config_scroll_get_method (libinput_device);
- current &= ~LIBINPUT_CONFIG_SCROLL_EDGE;
-
- device_set_scroll_method (libinput_device, current | method);
-}
-
-static void
-meta_input_settings_native_set_two_finger_scroll (MetaInputSettings *settings,
- ClutterInputDevice *device,
- gboolean two_finger_scroll_enabled)
-{
- struct libinput_device *libinput_device;
- enum libinput_config_scroll_method current, method;
-
- libinput_device = meta_input_device_native_get_libinput_device (device);
-
- method = two_finger_scroll_enabled ? LIBINPUT_CONFIG_SCROLL_2FG : LIBINPUT_CONFIG_SCROLL_NO_SCROLL;
- current = libinput_device_config_scroll_get_method (libinput_device);
- current &= ~LIBINPUT_CONFIG_SCROLL_2FG;
-
- device_set_scroll_method (libinput_device, current | method);
-}
-
-static gboolean
-meta_input_settings_native_has_two_finger_scroll (MetaInputSettings *settings,
- ClutterInputDevice *device)
-{
- struct libinput_device *libinput_device;
-
- libinput_device = meta_input_device_native_get_libinput_device (device);
- if (!libinput_device)
- return FALSE;
-
- return libinput_device_config_scroll_get_methods (libinput_device) & LIBINPUT_CONFIG_SCROLL_2FG;
-}
-
-static void
-meta_input_settings_native_set_scroll_button (MetaInputSettings *settings,
- ClutterInputDevice *device,
- guint button,
- gboolean button_lock)
-{
- struct libinput_device *libinput_device;
- enum libinput_config_scroll_method method;
- enum libinput_config_scroll_button_lock_state lock_state;
- guint evcode;
-
- libinput_device = meta_input_device_native_get_libinput_device (device);
- if (!libinput_device)
- return;
-
- if (button == 0)
- {
- method = LIBINPUT_CONFIG_SCROLL_NO_SCROLL;
- evcode = 0;
- }
- else
- {
- switch (button)
- {
- case 1:
- evcode = BTN_LEFT;
- break;
- case 2:
- evcode = BTN_MIDDLE;
- break;
- case 3:
- evcode = BTN_RIGHT;
- break;
- default:
- /* Compensate for X11 scroll buttons */
- if (button > 7)
- button -= 4;
-
- /* Button is 1-indexed */
- evcode = (BTN_LEFT - 1) + button;
- }
-
- method = LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN;
- }
-
- if (!device_set_scroll_method (libinput_device, method))
- return;
-
- libinput_device_config_scroll_set_button (libinput_device, evcode);
-
- if (button_lock)
- lock_state = LIBINPUT_CONFIG_SCROLL_BUTTON_LOCK_ENABLED;
- else
- lock_state = LIBINPUT_CONFIG_SCROLL_BUTTON_LOCK_DISABLED;
-
- libinput_device_config_scroll_set_button_lock (libinput_device, lock_state);
-}
-
-static void
-meta_input_settings_native_set_click_method (MetaInputSettings *settings,
- ClutterInputDevice *device,
- GDesktopTouchpadClickMethod mode)
-{
- enum libinput_config_click_method click_method = 0;
- struct libinput_device *libinput_device;
-
- libinput_device = meta_input_device_native_get_libinput_device (device);
- if (!libinput_device)
- return;
-
- switch (mode)
- {
- case G_DESKTOP_TOUCHPAD_CLICK_METHOD_DEFAULT:
- click_method = libinput_device_config_click_get_default_method (libinput_device);
- break;
- case G_DESKTOP_TOUCHPAD_CLICK_METHOD_NONE:
- click_method = LIBINPUT_CONFIG_CLICK_METHOD_NONE;
- break;
- case G_DESKTOP_TOUCHPAD_CLICK_METHOD_AREAS:
- click_method = LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS;
- break;
- case G_DESKTOP_TOUCHPAD_CLICK_METHOD_FINGERS:
- click_method = LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER;
- break;
- default:
- g_assert_not_reached ();
- return;
- }
-
- device_set_click_method (libinput_device, click_method);
-}
-
-static void
-meta_input_settings_native_set_tap_button_map (MetaInputSettings *settings,
- ClutterInputDevice *device,
- GDesktopTouchpadTapButtonMap mode)
-{
- enum libinput_config_tap_button_map button_map = 0;
- struct libinput_device *libinput_device;
-
- libinput_device = meta_input_device_native_get_libinput_device (device);
- if (!libinput_device)
- return;
-
- if (libinput_device_config_tap_get_finger_count (libinput_device) == 0)
- return;
-
- switch (mode)
- {
- case G_DESKTOP_TOUCHPAD_BUTTON_TAP_MAP_DEFAULT:
- button_map = libinput_device_config_tap_get_default_button_map (libinput_device);
- break;
- case G_DESKTOP_TOUCHPAD_BUTTON_TAP_MAP_LRM:
- button_map = LIBINPUT_CONFIG_TAP_MAP_LRM;
- break;
- case G_DESKTOP_TOUCHPAD_BUTTON_TAP_MAP_LMR:
- button_map = LIBINPUT_CONFIG_TAP_MAP_LMR;
- break;
- default:
- g_assert_not_reached ();
- return;
- }
-
- device_set_tap_button_map (libinput_device, button_map);
-}
-
-static void
-meta_input_settings_native_set_keyboard_repeat (MetaInputSettings *settings,
- gboolean enabled,
- guint delay,
- guint interval)
-{
- MetaInputSettingsNative *input_settings_native;
-
- input_settings_native = META_INPUT_SETTINGS_NATIVE (settings);
- meta_seat_impl_set_keyboard_repeat_in_impl (input_settings_native->seat_impl,
- enabled, delay, interval);
-}
-
-static void
-set_device_accel_profile (ClutterInputDevice *device,
- GDesktopPointerAccelProfile profile)
-{
- struct libinput_device *libinput_device;
- enum libinput_config_accel_profile libinput_profile;
- uint32_t profiles;
-
- libinput_device = meta_input_device_native_get_libinput_device (device);
-
- switch (profile)
- {
- case G_DESKTOP_POINTER_ACCEL_PROFILE_FLAT:
- libinput_profile = LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT;
- break;
- case G_DESKTOP_POINTER_ACCEL_PROFILE_ADAPTIVE:
- libinput_profile = LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE;
- break;
- default:
- g_warn_if_reached ();
- case G_DESKTOP_POINTER_ACCEL_PROFILE_DEFAULT:
- libinput_profile =
- libinput_device_config_accel_get_default_profile (libinput_device);
- }
-
- profiles = libinput_device_config_accel_get_profiles (libinput_device);
- if ((profiles & libinput_profile) == 0)
- {
- libinput_profile =
- libinput_device_config_accel_get_default_profile (libinput_device);
- }
-
- libinput_device_config_accel_set_profile (libinput_device,
- libinput_profile);
-}
-
-static gboolean
-has_udev_property (ClutterInputDevice *device,
- const char *property)
-{
- struct libinput_device *libinput_device;
- struct udev_device *udev_device;
- struct udev_device *parent_udev_device;
-
- libinput_device = meta_input_device_native_get_libinput_device (device);
- if (!libinput_device)
- return FALSE;
-
- udev_device = libinput_device_get_udev_device (libinput_device);
-
- if (!udev_device)
- return FALSE;
-
- if (NULL != udev_device_get_property_value (udev_device, property))
- {
- udev_device_unref (udev_device);
- return TRUE;
- }
-
- parent_udev_device = udev_device_get_parent (udev_device);
- udev_device_unref (udev_device);
-
- if (!parent_udev_device)
- return FALSE;
-
- if (NULL != udev_device_get_property_value (parent_udev_device, property))
- return TRUE;
-
- return FALSE;
-}
-
-static gboolean
-is_mouse_device (ClutterInputDevice *device)
-{
- return (has_udev_property (device, "ID_INPUT_MOUSE") &&
- !has_udev_property (device, "ID_INPUT_POINTINGSTICK"));
-}
-
-static gboolean
-meta_input_settings_native_is_touchpad_device (MetaInputSettings *settings,
- ClutterInputDevice *device)
-{
- return has_udev_property (device, "ID_INPUT_TOUCHPAD");
-}
-
-static gboolean
-meta_input_settings_native_is_trackball_device (MetaInputSettings *settings,
- ClutterInputDevice *device)
-{
- return has_udev_property (device, "ID_INPUT_TRACKBALL");
-}
-
-static void
-meta_input_settings_native_set_mouse_accel_profile (MetaInputSettings *settings,
- ClutterInputDevice *device,
- GDesktopPointerAccelProfile profile)
-{
- if (!is_mouse_device (device))
- return;
-
- set_device_accel_profile (device, profile);
-}
-
-static void
-meta_input_settings_native_set_trackball_accel_profile (MetaInputSettings *settings,
- ClutterInputDevice *device,
- GDesktopPointerAccelProfile profile)
-{
- if (!meta_input_settings_native_is_trackball_device (settings, device))
- return;
-
- set_device_accel_profile (device, profile);
-}
-
-static void
-meta_input_settings_native_set_tablet_mapping (MetaInputSettings *settings,
- ClutterInputDevice *device,
- GDesktopTabletMapping mapping)
-{
- MetaInputDeviceMapping dev_mapping;
-
- if (mapping == G_DESKTOP_TABLET_MAPPING_ABSOLUTE)
- dev_mapping = META_INPUT_DEVICE_MAPPING_ABSOLUTE;
- else if (mapping == G_DESKTOP_TABLET_MAPPING_RELATIVE)
- dev_mapping = META_INPUT_DEVICE_MAPPING_RELATIVE;
- else
- return;
-
- meta_input_device_native_set_mapping_mode_in_impl (device, dev_mapping);
-}
-
-static gboolean
-set_tablet_aspect_ratio (GTask *task)
-{
- ClutterInputDevice *device;
- double *aspect_ratio;
-
- device = g_task_get_source_object (task);
- aspect_ratio = g_task_get_task_data (task);
- g_object_set (device, "output-aspect-ratio", *aspect_ratio, NULL);
-
- return G_SOURCE_REMOVE;
-}
-
-static void
-meta_input_settings_native_set_tablet_aspect_ratio (MetaInputSettings *settings,
- ClutterInputDevice *device,
- gdouble aspect_ratio)
-{
- MetaInputSettingsNative *input_settings_native;
- GTask *task;
-
- if (meta_input_device_native_get_mapping_mode_in_impl (device) ==
- META_INPUT_DEVICE_MAPPING_RELATIVE)
- aspect_ratio = 0;
-
- task = g_task_new (device, NULL, NULL, NULL);
- g_task_set_task_data (task,
- g_memdup2 (&aspect_ratio, sizeof (double)),
- g_free);
-
- input_settings_native = META_INPUT_SETTINGS_NATIVE (settings);
- meta_seat_impl_run_input_task (input_settings_native->seat_impl,
- task, (GSourceFunc) set_tablet_aspect_ratio);
- g_object_unref (task);
-}
-
-static void
-meta_input_settings_native_set_tablet_area (MetaInputSettings *settings,
- ClutterInputDevice *device,
- gdouble padding_left,
- gdouble padding_right,
- gdouble padding_top,
- gdouble padding_bottom)
-{
- struct libinput_device *libinput_device;
- gfloat scale_x;
- gfloat scale_y;
- gfloat offset_x;
- gfloat offset_y;
-
- scale_x = 1. / (1. - (padding_left + padding_right));
- scale_y = 1. / (1. - (padding_top + padding_bottom));
- offset_x = -padding_left * scale_x;
- offset_y = -padding_top * scale_y;
-
- gfloat matrix[6] = { scale_x, 0., offset_x,
- 0., scale_y, offset_y };
-
- libinput_device = meta_input_device_native_get_libinput_device (device);
- if (!libinput_device ||
- !libinput_device_config_calibration_has_matrix (libinput_device))
- return;
-
- libinput_device_config_calibration_set_matrix (libinput_device, matrix);
-}
-
-static void
-meta_input_settings_native_set_stylus_pressure (MetaInputSettings *settings,
- ClutterInputDevice *device,
- ClutterInputDeviceTool *tool,
- const gint curve[4])
-{
- gdouble pressure_curve[4];
-
- pressure_curve[0] = (gdouble) curve[0] / 100;
- pressure_curve[1] = (gdouble) curve[1] / 100;
- pressure_curve[2] = (gdouble) curve[2] / 100;
- pressure_curve[3] = (gdouble) curve[3] / 100;
-
- meta_input_device_tool_native_set_pressure_curve_in_impl (tool, pressure_curve);
-}
-
-static guint
-action_to_evcode (GDesktopStylusButtonAction action)
-{
- switch (action)
- {
- case G_DESKTOP_STYLUS_BUTTON_ACTION_MIDDLE:
- return BTN_STYLUS;
- case G_DESKTOP_STYLUS_BUTTON_ACTION_RIGHT:
- return BTN_STYLUS2;
- case G_DESKTOP_STYLUS_BUTTON_ACTION_BACK:
- return BTN_BACK;
- case G_DESKTOP_STYLUS_BUTTON_ACTION_FORWARD:
- return BTN_FORWARD;
- case G_DESKTOP_STYLUS_BUTTON_ACTION_DEFAULT:
- default:
- return 0;
- }
-}
-
-static void
-meta_input_settings_native_set_stylus_button_map (MetaInputSettings *settings,
- ClutterInputDevice *device,
- ClutterInputDeviceTool *tool,
- GDesktopStylusButtonAction primary,
- GDesktopStylusButtonAction secondary,
- GDesktopStylusButtonAction tertiary)
-{
- meta_input_device_tool_native_set_button_code_in_impl (tool, CLUTTER_BUTTON_MIDDLE,
- action_to_evcode (primary));
- meta_input_device_tool_native_set_button_code_in_impl (tool, CLUTTER_BUTTON_SECONDARY,
- action_to_evcode (secondary));
- meta_input_device_tool_native_set_button_code_in_impl (tool, 8, /* Back */
- action_to_evcode (tertiary));
-}
-
-static void
-meta_input_settings_native_set_mouse_middle_click_emulation (MetaInputSettings *settings,
- ClutterInputDevice *device,
- gboolean enabled)
-{
- struct libinput_device *libinput_device;
-
- if (!is_mouse_device (device))
- return;
-
- libinput_device = meta_input_device_native_get_libinput_device (device);
- if (!libinput_device)
- return;
-
- if (libinput_device_config_middle_emulation_is_available (libinput_device))
- libinput_device_config_middle_emulation_set_enabled (libinput_device, enabled);
-}
-
-static void
-meta_input_settings_native_set_touchpad_middle_click_emulation (MetaInputSettings *settings,
- ClutterInputDevice *device,
- gboolean enabled)
-{
- struct libinput_device *libinput_device;
-
- if (!meta_input_settings_native_is_touchpad_device (settings, device))
- return;
-
- libinput_device = meta_input_device_native_get_libinput_device (device);
- if (!libinput_device)
- return;
-
- if (libinput_device_config_middle_emulation_is_available (libinput_device))
- libinput_device_config_middle_emulation_set_enabled (libinput_device, enabled);
-}
-
-static void
-meta_input_settings_native_set_trackball_middle_click_emulation (MetaInputSettings *settings,
- ClutterInputDevice *device,
- gboolean enabled)
-{
- struct libinput_device *libinput_device;
-
- if (!meta_input_settings_native_is_trackball_device (settings, device))
- return;
-
- libinput_device = meta_input_device_native_get_libinput_device (device);
- if (!libinput_device)
- return;
-
- if (libinput_device_config_middle_emulation_is_available (libinput_device))
- libinput_device_config_middle_emulation_set_enabled (libinput_device, enabled);
-}
-
-static void
-meta_input_settings_native_class_init (MetaInputSettingsNativeClass *klass)
-{
- MetaInputSettingsClass *input_settings_class = META_INPUT_SETTINGS_CLASS (klass);
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- object_class->set_property = meta_input_settings_native_set_property;
- object_class->get_property = meta_input_settings_native_get_property;
-
- input_settings_class->set_send_events = meta_input_settings_native_set_send_events;
- input_settings_class->set_matrix = meta_input_settings_native_set_matrix;
- input_settings_class->set_speed = meta_input_settings_native_set_speed;
- input_settings_class->set_left_handed = meta_input_settings_native_set_left_handed;
- input_settings_class->set_tap_enabled = meta_input_settings_native_set_tap_enabled;
- input_settings_class->set_tap_button_map = meta_input_settings_native_set_tap_button_map;
- input_settings_class->set_tap_and_drag_enabled = meta_input_settings_native_set_tap_and_drag_enabled;
- input_settings_class->set_tap_and_drag_lock_enabled =
- meta_input_settings_native_set_tap_and_drag_lock_enabled;
- input_settings_class->set_invert_scroll = meta_input_settings_native_set_invert_scroll;
- input_settings_class->set_edge_scroll = meta_input_settings_native_set_edge_scroll;
- input_settings_class->set_two_finger_scroll = meta_input_settings_native_set_two_finger_scroll;
- input_settings_class->set_scroll_button = meta_input_settings_native_set_scroll_button;
- input_settings_class->set_click_method = meta_input_settings_native_set_click_method;
- input_settings_class->set_keyboard_repeat = meta_input_settings_native_set_keyboard_repeat;
- input_settings_class->set_disable_while_typing = meta_input_settings_native_set_disable_while_typing;
-
- input_settings_class->set_tablet_mapping = meta_input_settings_native_set_tablet_mapping;
- input_settings_class->set_tablet_aspect_ratio = meta_input_settings_native_set_tablet_aspect_ratio;
- input_settings_class->set_tablet_area = meta_input_settings_native_set_tablet_area;
-
- input_settings_class->set_mouse_accel_profile = meta_input_settings_native_set_mouse_accel_profile;
- input_settings_class->set_trackball_accel_profile = meta_input_settings_native_set_trackball_accel_profile;
-
- input_settings_class->set_stylus_pressure = meta_input_settings_native_set_stylus_pressure;
- input_settings_class->set_stylus_button_map = meta_input_settings_native_set_stylus_button_map;
-
- input_settings_class->set_mouse_middle_click_emulation = meta_input_settings_native_set_mouse_middle_click_emulation;
- input_settings_class->set_touchpad_middle_click_emulation = meta_input_settings_native_set_touchpad_middle_click_emulation;
- input_settings_class->set_trackball_middle_click_emulation = meta_input_settings_native_set_trackball_middle_click_emulation;
-
- input_settings_class->has_two_finger_scroll = meta_input_settings_native_has_two_finger_scroll;
- input_settings_class->is_trackball_device = meta_input_settings_native_is_trackball_device;
-
- props[PROP_SEAT_IMPL] =
- g_param_spec_object ("seat-impl",
- "Seat Impl",
- "Seat Impl",
- META_TYPE_SEAT_IMPL,
- CLUTTER_PARAM_READWRITE |
- G_PARAM_CONSTRUCT_ONLY);
-
- g_object_class_install_properties (object_class, N_PROPS, props);
-}
-
-static void
-meta_input_settings_native_init (MetaInputSettingsNative *settings)
-{
-}
-
-MetaInputSettings *
-meta_input_settings_native_new_in_impl (MetaSeatImpl *seat_impl)
-{
- return g_object_new (META_TYPE_INPUT_SETTINGS_NATIVE,
- "seat-impl", seat_impl,
- NULL);
-}
diff --git a/src/backends/native/meta-input-settings-native.h b/src/backends/native/meta-input-settings-native.h
deleted file mode 100644
index cddd5b15f..000000000
--- a/src/backends/native/meta-input-settings-native.h
+++ /dev/null
@@ -1,56 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright 2014 Red Hat, Inc.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, see <http://www.gnu.org/licenses/>.
- *
- * Author: Carlos Garnacho <carlosg@gnome.org>
- */
-
-#ifndef META_INPUT_SETTINGS_NATIVE_H
-#define META_INPUT_SETTINGS_NATIVE_H
-
-#ifndef META_INPUT_THREAD_H_INSIDE
-#error "This header cannot be included directly. Use "backends/native/meta-input-thread.h""
-#endif /* META_INPUT_THREAD_H_INSIDE */
-
-#include "backends/meta-input-settings-private.h"
-
-#define META_TYPE_INPUT_SETTINGS_NATIVE (meta_input_settings_native_get_type ())
-#define META_INPUT_SETTINGS_NATIVE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), META_TYPE_INPUT_SETTINGS_NATIVE, MetaInputSettingsNative))
-#define META_INPUT_SETTINGS_NATIVE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), META_TYPE_INPUT_SETTINGS_NATIVE, MetaInputSettingsNativeClass))
-#define META_IS_INPUT_SETTINGS_NATIVE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), META_TYPE_INPUT_SETTINGS_NATIVE))
-#define META_IS_INPUT_SETTINGS_NATIVE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), META_TYPE_INPUT_SETTINGS_NATIVE))
-#define META_INPUT_SETTINGS_NATIVE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), META_TYPE_INPUT_SETTINGS_NATIVE, MetaInputSettingsNativeClass))
-
-typedef struct _MetaInputSettingsNative MetaInputSettingsNative;
-typedef struct _MetaInputSettingsNativeClass MetaInputSettingsNativeClass;
-
-struct _MetaInputSettingsNative
-{
- MetaInputSettings parent_instance;
- MetaSeatImpl *seat_impl;
-};
-
-struct _MetaInputSettingsNativeClass
-{
- MetaInputSettingsClass parent_class;
-};
-
-GType meta_input_settings_native_get_type (void) G_GNUC_CONST;
-
-MetaInputSettings * meta_input_settings_native_new_in_impl (MetaSeatImpl *seat_impl);
-
-#endif /* META_INPUT_SETTINGS_NATIVE_H */
diff --git a/src/backends/native/meta-input-thread.h b/src/backends/native/meta-input-thread.h
deleted file mode 100644
index 196adc27b..000000000
--- a/src/backends/native/meta-input-thread.h
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Copyright (C) 2020 Red Hat Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
- *
- * Author: Carlos Garnacho <carlosg@gnome.org>
- */
-
-#ifndef META_INPUT_THREAD_H
-#define META_INPUT_THREAD_H
-
-#define META_INPUT_THREAD_H_INSIDE
-
-#include "src/backends/native/meta-input-device-native.h"
-#include "src/backends/native/meta-input-device-tool-native.h"
-#include "src/backends/native/meta-input-settings-native.h"
-#include "src/backends/native/meta-keymap-native.h"
-#include "src/backends/native/meta-seat-impl.h"
-
-#undef META_INPUT_THREAD_H_INSIDE
-
-#endif /* META_INPUT_THREAD_H */
diff --git a/src/backends/native/meta-keymap-native.c b/src/backends/native/meta-keymap-native.c
deleted file mode 100644
index 500bb1012..000000000
--- a/src/backends/native/meta-keymap-native.c
+++ /dev/null
@@ -1,152 +0,0 @@
-/*
- * Copyright (C) 2018 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Author: Carlos Garnacho <carlosg@gnome.org>
- */
-
-#include "config.h"
-
-#include "backends/meta-keymap-utils.h"
-#include "backends/native/meta-input-thread.h"
-#include "backends/native/meta-seat-impl.h"
-#include "backends/native/meta-seat-native.h"
-#include "clutter/clutter-keymap-private.h"
-
-static const char *option_xkb_layout = "us";
-static const char *option_xkb_variant = "";
-static const char *option_xkb_options = "";
-
-typedef struct _MetaKeymapNative MetaKeymapNative;
-
-struct _MetaKeymapNative
-{
- ClutterKeymap parent_instance;
-
- struct xkb_keymap *keymap;
- gboolean num_lock;
- gboolean caps_lock;
-};
-
-G_DEFINE_TYPE (MetaKeymapNative, meta_keymap_native,
- CLUTTER_TYPE_KEYMAP)
-
-static void
-meta_keymap_native_finalize (GObject *object)
-{
- MetaKeymapNative *keymap = META_KEYMAP_NATIVE (object);
-
- xkb_keymap_unref (keymap->keymap);
-
- G_OBJECT_CLASS (meta_keymap_native_parent_class)->finalize (object);
-}
-
-static PangoDirection
-meta_keymap_native_get_direction (ClutterKeymap *keymap)
-{
- return PANGO_DIRECTION_NEUTRAL;
-}
-
-static void
-meta_keymap_native_class_init (MetaKeymapNativeClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
- ClutterKeymapClass *keymap_class = CLUTTER_KEYMAP_CLASS (klass);
-
- object_class->finalize = meta_keymap_native_finalize;
-
- keymap_class->get_direction = meta_keymap_native_get_direction;
-}
-
-static void
-meta_keymap_native_init (MetaKeymapNative *keymap)
-{
- struct xkb_context *ctx;
- struct xkb_rule_names names;
-
- names.rules = "evdev";
- names.model = "pc105";
- names.layout = option_xkb_layout;
- names.variant = option_xkb_variant;
- names.options = option_xkb_options;
-
- ctx = meta_create_xkb_context ();
- g_assert (ctx);
- keymap->keymap = xkb_keymap_new_from_names (ctx, &names, 0);
- xkb_context_unref (ctx);
-}
-
-void
-meta_keymap_native_set_keyboard_map_in_impl (MetaKeymapNative *keymap,
- struct xkb_keymap *xkb_keymap)
-{
- g_return_if_fail (xkb_keymap != NULL);
-
- if (keymap->keymap)
- xkb_keymap_unref (keymap->keymap);
- keymap->keymap = xkb_keymap_ref (xkb_keymap);
-}
-
-struct xkb_keymap *
-meta_keymap_native_get_keyboard_map_in_impl (MetaKeymapNative *keymap)
-{
- return keymap->keymap;
-}
-
-typedef struct
-{
- MetaKeymapNative *keymap_native;
- gboolean num_lock_state;
- gboolean caps_lock_state;
-} UpdateLockedModifierStateData;
-
-static gboolean
-update_locked_modifier_state_in_main (gpointer user_data)
-{
- UpdateLockedModifierStateData *data = user_data;
-
- clutter_keymap_set_lock_modifier_state (CLUTTER_KEYMAP (data->keymap_native),
- data->caps_lock_state,
- data->num_lock_state);
-
- return G_SOURCE_REMOVE;
-}
-
-void
-meta_keymap_native_update_in_impl (MetaKeymapNative *keymap_native,
- MetaSeatImpl *seat_impl,
- struct xkb_state *xkb_state)
-{
- UpdateLockedModifierStateData *data;
-
- data = g_new0 (UpdateLockedModifierStateData, 1);
- data->keymap_native = keymap_native;
- data->num_lock_state =
- xkb_state_mod_name_is_active (xkb_state,
- XKB_MOD_NAME_NUM,
- XKB_STATE_MODS_LATCHED |
- XKB_STATE_MODS_LOCKED);
- data->caps_lock_state =
- xkb_state_mod_name_is_active (xkb_state,
- XKB_MOD_NAME_CAPS,
- XKB_STATE_MODS_LATCHED |
- XKB_STATE_MODS_LOCKED);
-
- meta_seat_impl_queue_main_thread_idle (seat_impl,
- update_locked_modifier_state_in_main,
- data, g_free);
-}
diff --git a/src/backends/native/meta-keymap-native.h b/src/backends/native/meta-keymap-native.h
deleted file mode 100644
index 0aa62d085..000000000
--- a/src/backends/native/meta-keymap-native.h
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright (C) 2018 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Author: Carlos Garnacho <carlosg@gnome.org>
- */
-#ifndef META_KEYMAP_NATIVE_H
-#define META_KEYMAP_NATIVE_H
-
-#ifndef META_INPUT_THREAD_H_INSIDE
-#error "This header cannot be included directly. Use "backends/native/meta-input-thread.h""
-#endif /* META_INPUT_THREAD_H_INSIDE */
-
-#include "backends/native/meta-xkb-utils.h"
-#include "clutter/clutter.h"
-
-#define META_TYPE_KEYMAP_NATIVE (meta_keymap_native_get_type ())
-G_DECLARE_FINAL_TYPE (MetaKeymapNative, meta_keymap_native,
- META, KEYMAP_NATIVE,
- ClutterKeymap)
-
-void meta_keymap_native_set_keyboard_map_in_impl (MetaKeymapNative *keymap,
- struct xkb_keymap *xkb_keymap);
-struct xkb_keymap * meta_keymap_native_get_keyboard_map_in_impl (MetaKeymapNative *keymap);
-void meta_keymap_native_update_in_impl (MetaKeymapNative *keymap,
- MetaSeatImpl *seat_impl,
- struct xkb_state *xkb_state);
-
-#endif /* META_KEYMAP_NATIVE_H */
diff --git a/src/backends/native/meta-kms-connector-private.h b/src/backends/native/meta-kms-connector-private.h
deleted file mode 100644
index 9accf8ccd..000000000
--- a/src/backends/native/meta-kms-connector-private.h
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Copyright (C) 2019 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-
-#ifndef META_KMS_CONNECTOR_PRIVATE_H
-#define META_KMS_CONNECTOR_PRIVATE_H
-
-#include "backends/native/meta-kms-connector.h"
-
-typedef enum _MetaKmsConnectorProp
-{
- META_KMS_CONNECTOR_PROP_CRTC_ID = 0,
- META_KMS_CONNECTOR_PROP_DPMS,
- META_KMS_CONNECTOR_PROP_UNDERSCAN,
- META_KMS_CONNECTOR_PROP_UNDERSCAN_HBORDER,
- META_KMS_CONNECTOR_PROP_UNDERSCAN_VBORDER,
- META_KMS_CONNECTOR_N_PROPS
-} MetaKmsConnectorProp;
-
-uint32_t meta_kms_connector_get_prop_id (MetaKmsConnector *connector,
- MetaKmsConnectorProp prop);
-
-const char * meta_kms_connector_get_prop_name (MetaKmsConnector *connector,
- MetaKmsConnectorProp prop);
-
-void meta_kms_connector_update_state (MetaKmsConnector *connector,
- drmModeRes *drm_resources);
-
-void meta_kms_connector_predict_state (MetaKmsConnector *connector,
- MetaKmsUpdate *update);
-
-MetaKmsConnector * meta_kms_connector_new (MetaKmsImplDevice *impl_device,
- drmModeConnector *drm_connector,
- drmModeRes *drm_resources);
-
-gboolean meta_kms_connector_is_same_as (MetaKmsConnector *connector,
- drmModeConnector *drm_connector);
-
-#endif /* META_KMS_CONNECTOR_PRIVATE_H */
diff --git a/src/backends/native/meta-kms-connector.c b/src/backends/native/meta-kms-connector.c
deleted file mode 100644
index a666bb45c..000000000
--- a/src/backends/native/meta-kms-connector.c
+++ /dev/null
@@ -1,700 +0,0 @@
-/*
- * Copyright (C) 2019 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-
-#include "config.h"
-
-#include "backends/native/meta-kms-connector.h"
-#include "backends/native/meta-kms-connector-private.h"
-
-#include <errno.h>
-
-#include "backends/native/meta-kms-crtc.h"
-#include "backends/native/meta-kms-device-private.h"
-#include "backends/native/meta-kms-impl-device.h"
-#include "backends/native/meta-kms-mode-private.h"
-#include "backends/native/meta-kms-update-private.h"
-
-typedef struct _MetaKmsConnectorPropTable
-{
- MetaKmsProp props[META_KMS_CONNECTOR_N_PROPS];
-} MetaKmsConnectorPropTable;
-
-struct _MetaKmsConnector
-{
- GObject parent;
-
- MetaKmsDevice *device;
-
- uint32_t id;
- uint32_t type;
- uint32_t type_id;
- char *name;
-
- MetaKmsConnectorState *current_state;
-
- MetaKmsConnectorPropTable prop_table;
-
- uint32_t edid_blob_id;
- uint32_t tile_blob_id;
-
- gboolean fd_held;
-};
-
-G_DEFINE_TYPE (MetaKmsConnector, meta_kms_connector, G_TYPE_OBJECT)
-
-MetaKmsDevice *
-meta_kms_connector_get_device (MetaKmsConnector *connector)
-{
- return connector->device;
-}
-
-uint32_t
-meta_kms_connector_get_prop_id (MetaKmsConnector *connector,
- MetaKmsConnectorProp prop)
-{
- return connector->prop_table.props[prop].prop_id;
-}
-
-const char *
-meta_kms_connector_get_prop_name (MetaKmsConnector *connector,
- MetaKmsConnectorProp prop)
-{
- return connector->prop_table.props[prop].name;
-}
-
-uint32_t
-meta_kms_connector_get_connector_type (MetaKmsConnector *connector)
-{
- return connector->type;
-}
-
-uint32_t
-meta_kms_connector_get_id (MetaKmsConnector *connector)
-{
- return connector->id;
-}
-
-const char *
-meta_kms_connector_get_name (MetaKmsConnector *connector)
-{
- return connector->name;
-}
-
-gboolean
-meta_kms_connector_can_clone (MetaKmsConnector *connector,
- MetaKmsConnector *other_connector)
-{
- MetaKmsConnectorState *state = connector->current_state;
- MetaKmsConnectorState *other_state = other_connector->current_state;
-
- if (state->common_possible_clones == 0 ||
- other_state->common_possible_clones == 0)
- return FALSE;
-
- if (state->encoder_device_idxs != other_state->encoder_device_idxs)
- return FALSE;
-
- return TRUE;
-}
-
-const MetaKmsConnectorState *
-meta_kms_connector_get_current_state (MetaKmsConnector *connector)
-{
- return connector->current_state;
-}
-
-gboolean
-meta_kms_connector_is_underscanning_supported (MetaKmsConnector *connector)
-{
- uint32_t underscan_prop_id;
-
- underscan_prop_id =
- connector->prop_table.props[META_KMS_CONNECTOR_PROP_UNDERSCAN].prop_id;
-
- return underscan_prop_id != 0;
-}
-
-static void
-sync_fd_held (MetaKmsConnector *connector,
- MetaKmsImplDevice *impl_device)
-{
- gboolean should_hold_fd;
-
- should_hold_fd = connector->current_state->current_crtc_id != 0;
-
- if (connector->fd_held == should_hold_fd)
- return;
-
- if (should_hold_fd)
- meta_kms_impl_device_hold_fd (impl_device);
- else
- meta_kms_impl_device_unhold_fd (impl_device);
-
- connector->fd_held = should_hold_fd;
-}
-
-static void
-set_panel_orientation (MetaKmsConnectorState *state,
- drmModePropertyPtr prop,
- uint64_t orientation)
-{
- const char *name;
-
- name = prop->enums[orientation].name;
- if (strcmp (name, "Upside Down") == 0)
- {
- state->panel_orientation_transform = META_MONITOR_TRANSFORM_180;
- }
- else if (strcmp (name, "Left Side Up") == 0)
- {
- /* Left side up, rotate 90 degrees counter clockwise to correct */
- state->panel_orientation_transform = META_MONITOR_TRANSFORM_90;
- }
- else if (strcmp (name, "Right Side Up") == 0)
- {
- /* Right side up, rotate 270 degrees counter clockwise to correct */
- state->panel_orientation_transform = META_MONITOR_TRANSFORM_270;
- }
- else
- {
- state->panel_orientation_transform = META_MONITOR_TRANSFORM_NORMAL;
- }
-}
-
-static void
-state_set_properties (MetaKmsConnectorState *state,
- MetaKmsImplDevice *impl_device,
- drmModeConnector *drm_connector)
-{
- int fd;
- int i;
-
- fd = meta_kms_impl_device_get_fd (impl_device);
-
- for (i = 0; i < drm_connector->count_props; i++)
- {
- drmModePropertyPtr prop;
-
- prop = drmModeGetProperty (fd, drm_connector->props[i]);
- if (!prop)
- continue;
-
- if ((prop->flags & DRM_MODE_PROP_RANGE) &&
- strcmp (prop->name, "suggested X") == 0)
- state->suggested_x = drm_connector->prop_values[i];
- else if ((prop->flags & DRM_MODE_PROP_RANGE) &&
- strcmp (prop->name, "suggested Y") == 0)
- state->suggested_y = drm_connector->prop_values[i];
- else if ((prop->flags & DRM_MODE_PROP_RANGE) &&
- strcmp (prop->name, "hotplug_mode_update") == 0)
- state->hotplug_mode_update = drm_connector->prop_values[i];
- else if (strcmp (prop->name, "scaling mode") == 0)
- state->has_scaling = TRUE;
- else if ((prop->flags & DRM_MODE_PROP_ENUM) &&
- strcmp (prop->name, "panel orientation") == 0)
- set_panel_orientation (state, prop, drm_connector->prop_values[i]);
- else if ((prop->flags & DRM_MODE_PROP_RANGE) &&
- strcmp (prop->name, "non-desktop") == 0)
- state->non_desktop = drm_connector->prop_values[i];
-
- drmModeFreeProperty (prop);
- }
-}
-
-static CoglSubpixelOrder
-drm_subpixel_order_to_cogl_subpixel_order (drmModeSubPixel subpixel)
-{
- switch (subpixel)
- {
- case DRM_MODE_SUBPIXEL_NONE:
- return COGL_SUBPIXEL_ORDER_NONE;
- break;
- case DRM_MODE_SUBPIXEL_HORIZONTAL_RGB:
- return COGL_SUBPIXEL_ORDER_HORIZONTAL_RGB;
- break;
- case DRM_MODE_SUBPIXEL_HORIZONTAL_BGR:
- return COGL_SUBPIXEL_ORDER_HORIZONTAL_BGR;
- break;
- case DRM_MODE_SUBPIXEL_VERTICAL_RGB:
- return COGL_SUBPIXEL_ORDER_VERTICAL_RGB;
- break;
- case DRM_MODE_SUBPIXEL_VERTICAL_BGR:
- return COGL_SUBPIXEL_ORDER_VERTICAL_BGR;
- break;
- case DRM_MODE_SUBPIXEL_UNKNOWN:
- return COGL_SUBPIXEL_ORDER_UNKNOWN;
- }
- return COGL_SUBPIXEL_ORDER_UNKNOWN;
-}
-
-static void
-state_set_edid (MetaKmsConnectorState *state,
- MetaKmsConnector *connector,
- MetaKmsImplDevice *impl_device,
- uint32_t blob_id)
-{
- int fd;
- drmModePropertyBlobPtr edid_blob;
- GBytes *edid_data;
-
- fd = meta_kms_impl_device_get_fd (impl_device);
- edid_blob = drmModeGetPropertyBlob (fd, blob_id);
- if (!edid_blob)
- {
- g_warning ("Failed to read EDID of connector %s: %s",
- connector->name, g_strerror (errno));
- return;
- }
-
- edid_data = g_bytes_new (edid_blob->data, edid_blob->length);
- drmModeFreePropertyBlob (edid_blob);
-
- state->edid_data = edid_data;
-}
-
-static void
-state_set_tile_info (MetaKmsConnectorState *state,
- MetaKmsConnector *connector,
- MetaKmsImplDevice *impl_device,
- uint32_t blob_id)
-{
- int fd;
- drmModePropertyBlobPtr tile_blob;
-
- state->tile_info = (MetaTileInfo) { 0 };
-
- fd = meta_kms_impl_device_get_fd (impl_device);
- tile_blob = drmModeGetPropertyBlob (fd, blob_id);
- if (!tile_blob)
- {
- g_warning ("Failed to read TILE of connector %s: %s",
- connector->name, strerror (errno));
- return;
- }
-
- if (tile_blob->length > 0)
- {
- if (sscanf ((char *) tile_blob->data, "%d:%d:%d:%d:%d:%d:%d:%d",
- &state->tile_info.group_id,
- &state->tile_info.flags,
- &state->tile_info.max_h_tiles,
- &state->tile_info.max_v_tiles,
- &state->tile_info.loc_h_tile,
- &state->tile_info.loc_v_tile,
- &state->tile_info.tile_w,
- &state->tile_info.tile_h) != 8)
- {
- g_warning ("Couldn't understand TILE property blob of connector %s",
- connector->name);
- state->tile_info = (MetaTileInfo) { 0 };
- }
- }
-
- drmModeFreePropertyBlob (tile_blob);
-}
-
-static void
-state_set_blobs (MetaKmsConnectorState *state,
- MetaKmsConnector *connector,
- MetaKmsImplDevice *impl_device,
- drmModeConnector *drm_connector)
-{
- int fd;
- int i;
-
- fd = meta_kms_impl_device_get_fd (impl_device);
-
- for (i = 0; i < drm_connector->count_props; i++)
- {
- drmModePropertyPtr prop;
-
- prop = drmModeGetProperty (fd, drm_connector->props[i]);
- if (!prop)
- continue;
-
- if (prop->flags & DRM_MODE_PROP_BLOB)
- {
- uint32_t blob_id;
-
- blob_id = drm_connector->prop_values[i];
-
- if (blob_id)
- {
- if (strcmp (prop->name, "EDID") == 0)
- state_set_edid (state, connector, impl_device, blob_id);
- else if (strcmp (prop->name, "TILE") == 0)
- state_set_tile_info (state, connector, impl_device, blob_id);
- }
- }
-
- drmModeFreeProperty (prop);
- }
-}
-
-static void
-state_set_physical_dimensions (MetaKmsConnectorState *state,
- drmModeConnector *drm_connector)
-{
- state->width_mm = drm_connector->mmWidth;
- state->height_mm = drm_connector->mmHeight;
-}
-
-static void
-state_set_modes (MetaKmsConnectorState *state,
- MetaKmsImplDevice *impl_device,
- drmModeConnector *drm_connector)
-{
- int i;
-
- for (i = 0; i < drm_connector->count_modes; i++)
- {
- MetaKmsMode *mode;
-
- mode = meta_kms_mode_new (impl_device, &drm_connector->modes[i],
- META_KMS_MODE_FLAG_NONE);
- state->modes = g_list_prepend (state->modes, mode);
- }
- state->modes = g_list_reverse (state->modes);
-}
-
-static void
-set_encoder_device_idx_bit (uint32_t *encoder_device_idxs,
- uint32_t encoder_id,
- MetaKmsImplDevice *impl_device,
- drmModeRes *drm_resources)
-{
- int fd;
- int i;
-
- fd = meta_kms_impl_device_get_fd (impl_device);
-
- for (i = 0; i < drm_resources->count_encoders; i++)
- {
- drmModeEncoder *drm_encoder;
-
- drm_encoder = drmModeGetEncoder (fd, drm_resources->encoders[i]);
- if (!drm_encoder)
- continue;
-
- if (drm_encoder->encoder_id == encoder_id)
- {
- *encoder_device_idxs |= (1 << i);
- drmModeFreeEncoder (drm_encoder);
- break;
- }
-
- drmModeFreeEncoder (drm_encoder);
- }
-}
-
-static void
-state_set_crtc_state (MetaKmsConnectorState *state,
- drmModeConnector *drm_connector,
- MetaKmsImplDevice *impl_device,
- drmModeRes *drm_resources)
-{
- int fd;
- int i;
- uint32_t common_possible_crtcs;
- uint32_t common_possible_clones;
- uint32_t encoder_device_idxs;
-
- fd = meta_kms_impl_device_get_fd (impl_device);
-
- common_possible_crtcs = UINT32_MAX;
- common_possible_clones = UINT32_MAX;
- encoder_device_idxs = 0;
- for (i = 0; i < drm_connector->count_encoders; i++)
- {
- drmModeEncoder *drm_encoder;
-
- drm_encoder = drmModeGetEncoder (fd, drm_connector->encoders[i]);
- if (!drm_encoder)
- continue;
-
- common_possible_crtcs &= drm_encoder->possible_crtcs;
- common_possible_clones &= drm_encoder->possible_clones;
-
- set_encoder_device_idx_bit (&encoder_device_idxs,
- drm_encoder->encoder_id,
- impl_device,
- drm_resources);
-
- if (drm_connector->encoder_id == drm_encoder->encoder_id)
- state->current_crtc_id = drm_encoder->crtc_id;
-
- drmModeFreeEncoder (drm_encoder);
- }
-
- state->common_possible_crtcs = common_possible_crtcs;
- state->common_possible_clones = common_possible_clones;
- state->encoder_device_idxs = encoder_device_idxs;
-}
-
-static MetaKmsConnectorState *
-meta_kms_connector_state_new (void)
-{
- MetaKmsConnectorState *state;
-
- state = g_new0 (MetaKmsConnectorState, 1);
- state->suggested_x = -1;
- state->suggested_y = -1;
-
- return state;
-}
-
-static void
-meta_kms_connector_state_free (MetaKmsConnectorState *state)
-{
- g_clear_pointer (&state->edid_data, g_bytes_unref);
- g_list_free_full (state->modes, (GDestroyNotify) meta_kms_mode_free);
- g_free (state);
-}
-
-static void
-meta_kms_connector_read_state (MetaKmsConnector *connector,
- MetaKmsImplDevice *impl_device,
- drmModeConnector *drm_connector,
- drmModeRes *drm_resources)
-{
- MetaKmsConnectorState *state;
-
- g_clear_pointer (&connector->current_state, meta_kms_connector_state_free);
-
- if (!drm_connector || drm_connector->connection != DRM_MODE_CONNECTED)
- return;
-
- state = meta_kms_connector_state_new ();
-
- state_set_blobs (state, connector, impl_device, drm_connector);
-
- state_set_properties (state, impl_device, drm_connector);
-
- state->subpixel_order =
- drm_subpixel_order_to_cogl_subpixel_order (drm_connector->subpixel);
-
- state_set_physical_dimensions (state, drm_connector);
-
- state_set_modes (state, impl_device, drm_connector);
-
- state_set_crtc_state (state, drm_connector, impl_device, drm_resources);
-
- connector->current_state = state;
-
- sync_fd_held (connector, impl_device);
-}
-
-void
-meta_kms_connector_update_state (MetaKmsConnector *connector,
- drmModeRes *drm_resources)
-{
- MetaKmsImplDevice *impl_device;
- drmModeConnector *drm_connector;
-
- impl_device = meta_kms_device_get_impl_device (connector->device);
- drm_connector = drmModeGetConnector (meta_kms_impl_device_get_fd (impl_device),
- connector->id);
- meta_kms_connector_read_state (connector, impl_device,
- drm_connector,
- drm_resources);
- if (drm_connector)
- drmModeFreeConnector (drm_connector);
-}
-
-void
-meta_kms_connector_predict_state (MetaKmsConnector *connector,
- MetaKmsUpdate *update)
-{
- MetaKmsImplDevice *impl_device;
- MetaKmsConnectorState *current_state;
- GList *mode_sets;
- GList *l;
- current_state = connector->current_state;
- if (!current_state)
- return;
-
- mode_sets = meta_kms_update_get_mode_sets (update);
- for (l = mode_sets; l; l = l->next)
- {
- MetaKmsModeSet *mode_set = l->data;
- MetaKmsCrtc *crtc = mode_set->crtc;
-
- if (current_state->current_crtc_id == meta_kms_crtc_get_id (crtc))
- {
- if (g_list_find (mode_set->connectors, connector))
- break;
- else
- current_state->current_crtc_id = 0;
- }
- else
- {
- if (g_list_find (mode_set->connectors, connector))
- {
- current_state->current_crtc_id = meta_kms_crtc_get_id (crtc);
- break;
- }
- }
- }
-
- impl_device = meta_kms_device_get_impl_device (connector->device);
- sync_fd_held (connector, impl_device);
-}
-
-static void
-init_properties (MetaKmsConnector *connector,
- MetaKmsImplDevice *impl_device,
- drmModeConnector *drm_connector)
-{
- MetaKmsConnectorPropTable *prop_table = &connector->prop_table;
-
- *prop_table = (MetaKmsConnectorPropTable) {
- .props = {
- [META_KMS_CONNECTOR_PROP_CRTC_ID] =
- {
- .name = "CRTC_ID",
- .type = DRM_MODE_PROP_OBJECT,
- },
- [META_KMS_CONNECTOR_PROP_DPMS] =
- {
- .name = "DPMS",
- .type = DRM_MODE_PROP_ENUM,
- },
- [META_KMS_CONNECTOR_PROP_UNDERSCAN] =
- {
- .name = "underscan",
- .type = DRM_MODE_PROP_ENUM,
- },
- [META_KMS_CONNECTOR_PROP_UNDERSCAN_HBORDER] =
- {
- .name = "underscan hborder",
- .type = DRM_MODE_PROP_RANGE,
- },
- [META_KMS_CONNECTOR_PROP_UNDERSCAN_VBORDER] =
- {
- .name = "underscan vborder",
- .type = DRM_MODE_PROP_RANGE,
- },
- }
- };
-
- meta_kms_impl_device_init_prop_table (impl_device,
- drm_connector->props,
- drm_connector->prop_values,
- drm_connector->count_props,
- connector->prop_table.props,
- META_KMS_CONNECTOR_N_PROPS,
- NULL);
-}
-
-static char *
-make_connector_name (drmModeConnector *drm_connector)
-{
- static const char * const connector_type_names[] = {
- "None",
- "VGA",
- "DVI-I",
- "DVI-D",
- "DVI-A",
- "Composite",
- "SVIDEO",
- "LVDS",
- "Component",
- "DIN",
- "DP",
- "HDMI",
- "HDMI-B",
- "TV",
- "eDP",
- "Virtual",
- "DSI",
- };
-
- if (drm_connector->connector_type < G_N_ELEMENTS (connector_type_names))
- return g_strdup_printf ("%s-%d",
- connector_type_names[drm_connector->connector_type],
- drm_connector->connector_type_id);
- else
- return g_strdup_printf ("Unknown%d-%d",
- drm_connector->connector_type,
- drm_connector->connector_type_id);
-}
-
-gboolean
-meta_kms_connector_is_same_as (MetaKmsConnector *connector,
- drmModeConnector *drm_connector)
-{
- return (connector->id == drm_connector->connector_id &&
- connector->type == drm_connector->connector_type &&
- connector->type_id == drm_connector->connector_type_id);
-}
-
-MetaKmsConnector *
-meta_kms_connector_new (MetaKmsImplDevice *impl_device,
- drmModeConnector *drm_connector,
- drmModeRes *drm_resources)
-{
- MetaKmsConnector *connector;
-
- connector = g_object_new (META_TYPE_KMS_CONNECTOR, NULL);
- connector->device = meta_kms_impl_device_get_device (impl_device);
- connector->id = drm_connector->connector_id;
- connector->type = drm_connector->connector_type;
- connector->type_id = drm_connector->connector_type_id;
- connector->name = make_connector_name (drm_connector);
-
- init_properties (connector, impl_device, drm_connector);
-
- meta_kms_connector_read_state (connector, impl_device,
- drm_connector,
- drm_resources);
-
- return connector;
-}
-
-static void
-meta_kms_connector_finalize (GObject *object)
-{
- MetaKmsConnector *connector = META_KMS_CONNECTOR (object);
-
- if (connector->fd_held)
- {
- MetaKmsImplDevice *impl_device;
-
- impl_device = meta_kms_device_get_impl_device (connector->device);
- meta_kms_impl_device_unhold_fd (impl_device);
- }
-
- g_clear_pointer (&connector->current_state, meta_kms_connector_state_free);
- g_free (connector->name);
-
- G_OBJECT_CLASS (meta_kms_connector_parent_class)->finalize (object);
-}
-
-static void
-meta_kms_connector_init (MetaKmsConnector *connector)
-{
-}
-
-static void
-meta_kms_connector_class_init (MetaKmsConnectorClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- object_class->finalize = meta_kms_connector_finalize;
-}
diff --git a/src/backends/native/meta-kms-connector.h b/src/backends/native/meta-kms-connector.h
deleted file mode 100644
index a3a7136c5..000000000
--- a/src/backends/native/meta-kms-connector.h
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * Copyright (C) 2019 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-
-#ifndef META_KMS_CONNECTOR_H
-#define META_KMS_CONNECTOR_H
-
-#include <glib-object.h>
-#include <stdint.h>
-#include <xf86drmMode.h>
-
-#include "backends/meta-output.h"
-#include "backends/native/meta-kms-types.h"
-
-#define META_TYPE_KMS_CONNECTOR (meta_kms_connector_get_type ())
-G_DECLARE_FINAL_TYPE (MetaKmsConnector, meta_kms_connector,
- META, KMS_CONNECTOR, GObject)
-
-typedef struct _MetaKmsConnectorState
-{
- uint32_t current_crtc_id;
-
- uint32_t common_possible_crtcs;
- uint32_t common_possible_clones;
- uint32_t encoder_device_idxs;
-
- GList *modes;
-
- uint32_t width_mm;
- uint32_t height_mm;
-
- MetaTileInfo tile_info;
- GBytes *edid_data;
-
- gboolean has_scaling;
- gboolean non_desktop;
-
- CoglSubpixelOrder subpixel_order;
-
- int suggested_x;
- int suggested_y;
- gboolean hotplug_mode_update;
-
- MetaMonitorTransform panel_orientation_transform;
-} MetaKmsConnectorState;
-
-MetaKmsDevice * meta_kms_connector_get_device (MetaKmsConnector *connector);
-
-uint32_t meta_kms_connector_get_connector_type (MetaKmsConnector *connector);
-
-uint32_t meta_kms_connector_get_id (MetaKmsConnector *connector);
-
-const char * meta_kms_connector_get_name (MetaKmsConnector *connector);
-
-gboolean meta_kms_connector_can_clone (MetaKmsConnector *connector,
- MetaKmsConnector *other_connector);
-
-const MetaKmsConnectorState * meta_kms_connector_get_current_state (MetaKmsConnector *connector);
-
-gboolean meta_kms_connector_is_underscanning_supported (MetaKmsConnector *connector);
-
-#endif /* META_KMS_CONNECTOR_H */
diff --git a/src/backends/native/meta-kms-crtc-private.h b/src/backends/native/meta-kms-crtc-private.h
deleted file mode 100644
index 60c5fd309..000000000
--- a/src/backends/native/meta-kms-crtc-private.h
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Copyright (C) 2019 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-
-#ifndef META_KMS_CRTC_PRIVATE_H
-#define META_KMS_CRTC_PRIVATE_H
-
-#include <xf86drmMode.h>
-
-#include "backends/native/meta-kms-crtc.h"
-
-typedef enum _MetaKmsCrtcProp
-{
- META_KMS_CRTC_PROP_MODE_ID = 0,
- META_KMS_CRTC_PROP_ACTIVE,
- META_KMS_CRTC_PROP_GAMMA_LUT,
- META_KMS_CRTC_N_PROPS
-} MetaKmsCrtcProp;
-
-MetaKmsCrtc * meta_kms_crtc_new (MetaKmsImplDevice *impl_device,
- drmModeCrtc *drm_crtc,
- int idx,
- GError **error);
-
-void meta_kms_crtc_update_state (MetaKmsCrtc *crtc);
-
-void meta_kms_crtc_predict_state (MetaKmsCrtc *crtc,
- MetaKmsUpdate *update);
-
-uint32_t meta_kms_crtc_get_prop_id (MetaKmsCrtc *crtc,
- MetaKmsCrtcProp prop);
-
-const char * meta_kms_crtc_get_prop_name (MetaKmsCrtc *crtc,
- MetaKmsCrtcProp prop);
-
-#endif /* META_KMS_CRTC_PRIVATE_H */
diff --git a/src/backends/native/meta-kms-crtc.c b/src/backends/native/meta-kms-crtc.c
deleted file mode 100644
index 51d040b44..000000000
--- a/src/backends/native/meta-kms-crtc.c
+++ /dev/null
@@ -1,399 +0,0 @@
-/*
- * Copyright (C) 2019 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-
-#include "config.h"
-
-#include "backends/native/meta-kms-crtc.h"
-#include "backends/native/meta-kms-crtc-private.h"
-
-#include "backends/native/meta-kms-device-private.h"
-#include "backends/native/meta-kms-impl-device.h"
-#include "backends/native/meta-kms-mode.h"
-#include "backends/native/meta-kms-update-private.h"
-
-typedef struct _MetaKmsCrtcPropTable
-{
- MetaKmsProp props[META_KMS_CRTC_N_PROPS];
-} MetaKmsCrtcPropTable;
-
-struct _MetaKmsCrtc
-{
- GObject parent;
-
- MetaKmsDevice *device;
-
- uint32_t id;
- int idx;
-
- MetaKmsCrtcState current_state;
-
- MetaKmsCrtcPropTable prop_table;
-};
-
-G_DEFINE_TYPE (MetaKmsCrtc, meta_kms_crtc, G_TYPE_OBJECT)
-
-MetaKmsDevice *
-meta_kms_crtc_get_device (MetaKmsCrtc *crtc)
-{
- return crtc->device;
-}
-
-const MetaKmsCrtcState *
-meta_kms_crtc_get_current_state (MetaKmsCrtc *crtc)
-{
- return &crtc->current_state;
-}
-
-uint32_t
-meta_kms_crtc_get_id (MetaKmsCrtc *crtc)
-{
- return crtc->id;
-}
-
-int
-meta_kms_crtc_get_idx (MetaKmsCrtc *crtc)
-{
- return crtc->idx;
-}
-
-uint32_t
-meta_kms_crtc_get_prop_id (MetaKmsCrtc *crtc,
- MetaKmsCrtcProp prop)
-{
- return crtc->prop_table.props[prop].prop_id;
-}
-
-const char *
-meta_kms_crtc_get_prop_name (MetaKmsCrtc *crtc,
- MetaKmsCrtcProp prop)
-{
- return crtc->prop_table.props[prop].name;
-}
-
-gboolean
-meta_kms_crtc_is_active (MetaKmsCrtc *crtc)
-{
- return crtc->current_state.is_active;
-}
-
-static void
-read_gamma_state (MetaKmsCrtc *crtc,
- MetaKmsImplDevice *impl_device,
- drmModeCrtc *drm_crtc)
-{
- MetaKmsCrtcState *current_state = &crtc->current_state;
-
- if (current_state->gamma.size != drm_crtc->gamma_size)
- {
- current_state->gamma.size = drm_crtc->gamma_size;
-
- current_state->gamma.red = g_realloc_n (current_state->gamma.red,
- drm_crtc->gamma_size,
- sizeof (uint16_t));
- current_state->gamma.green = g_realloc_n (current_state->gamma.green,
- drm_crtc->gamma_size,
- sizeof (uint16_t));
- current_state->gamma.blue = g_realloc_n (current_state->gamma.blue,
- drm_crtc->gamma_size,
- sizeof (uint16_t));
- }
-
- drmModeCrtcGetGamma (meta_kms_impl_device_get_fd (impl_device),
- crtc->id,
- current_state->gamma.size,
- current_state->gamma.red,
- current_state->gamma.green,
- current_state->gamma.blue);
-}
-
-static int
-find_prop_idx (MetaKmsProp *prop,
- uint32_t *drm_props,
- int n_drm_props)
-{
- int i;
-
- g_return_val_if_fail (prop->prop_id > 0, -1);
-
- for (i = 0; i < n_drm_props; i++)
- {
- if (drm_props[i] == prop->prop_id)
- return i;
- }
-
- return -1;
-}
-
-static void
-meta_kms_crtc_read_state (MetaKmsCrtc *crtc,
- MetaKmsImplDevice *impl_device,
- drmModeCrtc *drm_crtc,
- drmModeObjectProperties *drm_props)
-{
- MetaKmsProp *active_prop;
- int active_idx;
-
- crtc->current_state.rect = (MetaRectangle) {
- .x = drm_crtc->x,
- .y = drm_crtc->y,
- .width = drm_crtc->width,
- .height = drm_crtc->height,
- };
-
- crtc->current_state.is_drm_mode_valid = drm_crtc->mode_valid;
- crtc->current_state.drm_mode = drm_crtc->mode;
-
- active_prop = &crtc->prop_table.props[META_KMS_CRTC_PROP_ACTIVE];
- if (active_prop->prop_id)
- {
- active_idx = find_prop_idx (active_prop,
- drm_props->props,
- drm_props->count_props);
- crtc->current_state.is_active = !!drm_props->prop_values[active_idx];
- }
- else
- {
- crtc->current_state.is_active = drm_crtc->mode_valid;
- }
-
- meta_topic (META_DEBUG_KMS,
- "Read CRTC %u state: active: %d, mode: %s",
- crtc->id, crtc->current_state.is_active,
- crtc->current_state.is_drm_mode_valid
- ? crtc->current_state.drm_mode.name
- : "(nil)");
-
- read_gamma_state (crtc, impl_device, drm_crtc);
-}
-
-void
-meta_kms_crtc_update_state (MetaKmsCrtc *crtc)
-{
- MetaKmsImplDevice *impl_device;
- int fd;
- drmModeCrtc *drm_crtc;
- drmModeObjectProperties *drm_props;
-
- impl_device = meta_kms_device_get_impl_device (crtc->device);
- fd = meta_kms_impl_device_get_fd (impl_device);
-
- drm_crtc = drmModeGetCrtc (fd, crtc->id);
- drm_props = drmModeObjectGetProperties (fd, crtc->id, DRM_MODE_OBJECT_CRTC);
-
- if (!drm_crtc || !drm_props)
- {
- crtc->current_state.is_active = FALSE;
- crtc->current_state.rect = (MetaRectangle) { };
- crtc->current_state.is_drm_mode_valid = FALSE;
- goto out;
- }
-
- meta_kms_crtc_read_state (crtc, impl_device, drm_crtc, drm_props);
-
-out:
- g_clear_pointer (&drm_props, drmModeFreeObjectProperties);
- g_clear_pointer (&drm_crtc, drmModeFreeCrtc);
-}
-
-static void
-clear_gamma_state (MetaKmsCrtc *crtc)
-{
- crtc->current_state.gamma.size = 0;
- g_clear_pointer (&crtc->current_state.gamma.red, g_free);
- g_clear_pointer (&crtc->current_state.gamma.green, g_free);
- g_clear_pointer (&crtc->current_state.gamma.blue, g_free);
-}
-
-void
-meta_kms_crtc_predict_state (MetaKmsCrtc *crtc,
- MetaKmsUpdate *update)
-{
- GList *mode_sets;
- GList *crtc_gammas;
- GList *l;
-
- mode_sets = meta_kms_update_get_mode_sets (update);
- for (l = mode_sets; l; l = l->next)
- {
- MetaKmsModeSet *mode_set = l->data;
-
- if (mode_set->crtc != crtc)
- continue;
-
- if (mode_set->mode)
- {
- MetaKmsPlaneAssignment *plane_assignment;
- const drmModeModeInfo *drm_mode;
-
- plane_assignment =
- meta_kms_update_get_primary_plane_assignment (update, crtc);
- drm_mode = meta_kms_mode_get_drm_mode (mode_set->mode);
-
- crtc->current_state.is_active = TRUE;
- crtc->current_state.rect =
- meta_fixed_16_rectangle_to_rectangle (plane_assignment->src_rect);
- crtc->current_state.is_drm_mode_valid = TRUE;
- crtc->current_state.drm_mode = *drm_mode;
- }
- else
- {
- crtc->current_state.is_active = FALSE;
- crtc->current_state.rect = (MetaRectangle) { 0 };
- crtc->current_state.is_drm_mode_valid = FALSE;
- crtc->current_state.drm_mode = (drmModeModeInfo) { 0 };
- }
-
- break;
- }
-
- crtc_gammas = meta_kms_update_get_crtc_gammas (update);
- for (l = crtc_gammas; l; l = l->next)
- {
- MetaKmsCrtcGamma *gamma = l->data;
-
- if (gamma->crtc != crtc)
- continue;
-
- clear_gamma_state (crtc);
- crtc->current_state.gamma.size = gamma->size;
- crtc->current_state.gamma.red =
- g_memdup2 (gamma->red, gamma->size * sizeof (uint16_t));
- crtc->current_state.gamma.green =
- g_memdup2 (gamma->green, gamma->size * sizeof (uint16_t));
- crtc->current_state.gamma.blue =
- g_memdup2 (gamma->blue, gamma->size * sizeof (uint16_t));
-
- break;
- }
-}
-
-static void
-parse_active (MetaKmsImplDevice *impl_device,
- MetaKmsProp *prop,
- drmModePropertyPtr drm_prop,
- uint64_t drm_prop_value,
- gpointer user_data)
-{
- MetaKmsCrtc *crtc = user_data;
-
- crtc->current_state.is_active = !!drm_prop_value;
-}
-
-static void
-init_proporties (MetaKmsCrtc *crtc,
- MetaKmsImplDevice *impl_device,
- drmModeCrtc *drm_crtc)
-{
- MetaKmsCrtcPropTable *prop_table = &crtc->prop_table;
- int fd;
- drmModeObjectProperties *drm_props;
-
- *prop_table = (MetaKmsCrtcPropTable) {
- .props = {
- [META_KMS_CRTC_PROP_MODE_ID] =
- {
- .name = "MODE_ID",
- .type = DRM_MODE_PROP_BLOB,
- },
- [META_KMS_CRTC_PROP_ACTIVE] =
- {
- .name = "ACTIVE",
- .type = DRM_MODE_PROP_RANGE,
- .parse = parse_active,
- },
- [META_KMS_CRTC_PROP_GAMMA_LUT] =
- {
- .name = "GAMMA_LUT",
- .type = DRM_MODE_PROP_BLOB,
- },
- }
- };
-
- fd = meta_kms_impl_device_get_fd (impl_device);
- drm_props = drmModeObjectGetProperties (fd,
- drm_crtc->crtc_id,
- DRM_MODE_OBJECT_CRTC);
-
- meta_kms_impl_device_init_prop_table (impl_device,
- drm_props->props,
- drm_props->prop_values,
- drm_props->count_props,
- crtc->prop_table.props,
- META_KMS_CRTC_N_PROPS,
- crtc);
-
- drmModeFreeObjectProperties (drm_props);
-}
-
-MetaKmsCrtc *
-meta_kms_crtc_new (MetaKmsImplDevice *impl_device,
- drmModeCrtc *drm_crtc,
- int idx,
- GError **error)
-{
- int fd;
- drmModeObjectProperties *drm_props;
- MetaKmsCrtc *crtc;
-
- fd = meta_kms_impl_device_get_fd (impl_device);
- drm_props = drmModeObjectGetProperties (fd, drm_crtc->crtc_id,
- DRM_MODE_OBJECT_CRTC);
- if (!drm_props)
- {
- g_set_error (error, G_IO_ERROR, g_io_error_from_errno (errno),
- "drmModeObjectGetProperties: %s", g_strerror (errno));
- return NULL;
- }
-
- crtc = g_object_new (META_TYPE_KMS_CRTC, NULL);
- crtc->device = meta_kms_impl_device_get_device (impl_device);
- crtc->id = drm_crtc->crtc_id;
- crtc->idx = idx;
-
- init_proporties (crtc, impl_device, drm_crtc);
-
- meta_kms_crtc_read_state (crtc, impl_device, drm_crtc, drm_props);
-
- drmModeFreeObjectProperties (drm_props);
-
- return crtc;
-}
-
-static void
-meta_kms_crtc_finalize (GObject *object)
-{
- MetaKmsCrtc *crtc = META_KMS_CRTC (object);
-
- clear_gamma_state (crtc);
-
- G_OBJECT_CLASS (meta_kms_crtc_parent_class)->finalize (object);
-}
-
-static void
-meta_kms_crtc_init (MetaKmsCrtc *crtc)
-{
-}
-
-static void
-meta_kms_crtc_class_init (MetaKmsCrtcClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- object_class->finalize = meta_kms_crtc_finalize;
-}
diff --git a/src/backends/native/meta-kms-crtc.h b/src/backends/native/meta-kms-crtc.h
deleted file mode 100644
index 406ca3ac1..000000000
--- a/src/backends/native/meta-kms-crtc.h
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * Copyright (C) 2019 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-
-#ifndef META_KMS_CRTC_H
-#define META_KMS_CRTC_H
-
-#include <glib-object.h>
-#include <stdint.h>
-#include <xf86drmMode.h>
-
-#include "backends/native/meta-kms-types.h"
-#include "meta/boxes.h"
-
-typedef struct _MetaKmsCrtcState
-{
- gboolean is_active;
-
- MetaRectangle rect;
- gboolean is_drm_mode_valid;
- drmModeModeInfo drm_mode;
-
- struct {
- uint16_t *red;
- uint16_t *green;
- uint16_t *blue;
-
- int size;
- } gamma;
-} MetaKmsCrtcState;
-
-typedef struct _MetaKmsCrtcGamma
-{
- MetaKmsCrtc *crtc;
- int size;
- uint16_t *red;
- uint16_t *green;
- uint16_t *blue;
-} MetaKmsCrtcGamma;
-
-#define META_TYPE_KMS_CRTC (meta_kms_crtc_get_type ())
-G_DECLARE_FINAL_TYPE (MetaKmsCrtc, meta_kms_crtc,
- META, KMS_CRTC,
- GObject)
-
-MetaKmsDevice * meta_kms_crtc_get_device (MetaKmsCrtc *crtc);
-
-const MetaKmsCrtcState * meta_kms_crtc_get_current_state (MetaKmsCrtc *crtc);
-
-uint32_t meta_kms_crtc_get_id (MetaKmsCrtc *crtc);
-
-int meta_kms_crtc_get_idx (MetaKmsCrtc *crtc);
-
-gboolean meta_kms_crtc_is_active (MetaKmsCrtc *crtc);
-
-void meta_kms_crtc_gamma_free (MetaKmsCrtcGamma *gamma);
-
-MetaKmsCrtcGamma * meta_kms_crtc_gamma_new (MetaKmsCrtc *crtc,
- int size,
- const uint16_t *red,
- const uint16_t *green,
- const uint16_t *blue);
-
-#endif /* META_KMS_CRTC_H */
diff --git a/src/backends/native/meta-kms-device-private.h b/src/backends/native/meta-kms-device-private.h
deleted file mode 100644
index 41e05a2f7..000000000
--- a/src/backends/native/meta-kms-device-private.h
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright (C) 2019 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-
-#ifndef META_KMS_DEVICE_PRIVATE_H
-#define META_KMS_DEVICE_PRIVATE_H
-
-#include "backends/native/meta-kms-types.h"
-
-MetaKmsImplDevice * meta_kms_device_get_impl_device (MetaKmsDevice *device);
-
-void meta_kms_device_update_states_in_impl (MetaKmsDevice *device);
-
-void meta_kms_device_predict_states_in_impl (MetaKmsDevice *device,
- MetaKmsUpdate *update);
-
-void meta_kms_device_add_fake_plane_in_impl (MetaKmsDevice *device,
- MetaKmsPlaneType plane_type,
- MetaKmsCrtc *crtc);
-
-#endif /* META_KMS_DEVICE_PRIVATE_H */
diff --git a/src/backends/native/meta-kms-device.c b/src/backends/native/meta-kms-device.c
deleted file mode 100644
index b4d3e5802..000000000
--- a/src/backends/native/meta-kms-device.c
+++ /dev/null
@@ -1,439 +0,0 @@
-/*
- * Copyright (C) 2019 Red Hat
- * Copyright (C) 2019 DisplayLink (UK) Ltd.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-
-#include "config.h"
-
-#include "backends/native/meta-kms-device-private.h"
-#include "backends/native/meta-kms-device.h"
-
-#include <fcntl.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <xf86drm.h>
-
-#include "backends/native/meta-backend-native-private.h"
-#include "backends/native/meta-device-pool.h"
-#include "backends/native/meta-kms-impl-device-atomic.h"
-#include "backends/native/meta-kms-impl-device-dummy.h"
-#include "backends/native/meta-kms-impl-device-simple.h"
-#include "backends/native/meta-kms-impl-device.h"
-#include "backends/native/meta-kms-impl.h"
-#include "backends/native/meta-kms-plane.h"
-#include "backends/native/meta-kms-private.h"
-
-struct _MetaKmsDevice
-{
- GObject parent;
-
- MetaKms *kms;
-
- MetaKmsImplDevice *impl_device;
-
- MetaKmsDeviceFlag flags;
- char *path;
- char *driver_name;
- char *driver_description;
-
- GList *crtcs;
- GList *connectors;
- GList *planes;
-
- MetaKmsDeviceCaps caps;
-
- GList *fallback_modes;
-};
-
-G_DEFINE_TYPE (MetaKmsDevice, meta_kms_device, G_TYPE_OBJECT);
-
-MetaKms *
-meta_kms_device_get_kms (MetaKmsDevice *device)
-{
- return device->kms;
-}
-
-MetaKmsImplDevice *
-meta_kms_device_get_impl_device (MetaKmsDevice *device)
-{
- return device->impl_device;
-}
-
-const char *
-meta_kms_device_get_path (MetaKmsDevice *device)
-{
- return device->path;
-}
-
-const char *
-meta_kms_device_get_driver_name (MetaKmsDevice *device)
-{
- return device->driver_name;
-}
-
-const char *
-meta_kms_device_get_driver_description (MetaKmsDevice *device)
-{
- return device->driver_description;
-}
-
-MetaKmsDeviceFlag
-meta_kms_device_get_flags (MetaKmsDevice *device)
-{
- return device->flags;
-}
-
-gboolean
-meta_kms_device_get_cursor_size (MetaKmsDevice *device,
- uint64_t *out_cursor_width,
- uint64_t *out_cursor_height)
-{
- if (device->caps.has_cursor_size)
- {
- *out_cursor_width = device->caps.cursor_width;
- *out_cursor_height = device->caps.cursor_height;
- return TRUE;
- }
- else
- {
- return FALSE;
- }
-}
-
-gboolean
-meta_kms_device_prefers_shadow_buffer (MetaKmsDevice *device)
-{
- return device->caps.prefers_shadow_buffer;
-}
-
-gboolean
-meta_kms_device_uses_monotonic_clock (MetaKmsDevice *device)
-{
- return device->caps.uses_monotonic_clock;
-}
-
-GList *
-meta_kms_device_get_connectors (MetaKmsDevice *device)
-{
- return device->connectors;
-}
-
-GList *
-meta_kms_device_get_crtcs (MetaKmsDevice *device)
-{
- return device->crtcs;
-}
-
-GList *
-meta_kms_device_get_planes (MetaKmsDevice *device)
-{
- return device->planes;
-}
-
-static MetaKmsPlane *
-get_plane_with_type_for (MetaKmsDevice *device,
- MetaKmsCrtc *crtc,
- MetaKmsPlaneType type)
-{
- GList *l;
-
- for (l = meta_kms_device_get_planes (device); l; l = l->next)
- {
- MetaKmsPlane *plane = l->data;
-
- if (meta_kms_plane_get_plane_type (plane) != type)
- continue;
-
- if (meta_kms_plane_is_usable_with (plane, crtc))
- return plane;
- }
-
- return NULL;
-}
-
-MetaKmsPlane *
-meta_kms_device_get_primary_plane_for (MetaKmsDevice *device,
- MetaKmsCrtc *crtc)
-{
- return get_plane_with_type_for (device, crtc, META_KMS_PLANE_TYPE_PRIMARY);
-}
-
-MetaKmsPlane *
-meta_kms_device_get_cursor_plane_for (MetaKmsDevice *device,
- MetaKmsCrtc *crtc)
-{
- return get_plane_with_type_for (device, crtc, META_KMS_PLANE_TYPE_CURSOR);
-}
-
-GList *
-meta_kms_device_get_fallback_modes (MetaKmsDevice *device)
-{
- return device->fallback_modes;
-}
-
-void
-meta_kms_device_update_states_in_impl (MetaKmsDevice *device)
-{
- MetaKmsImplDevice *impl_device = meta_kms_device_get_impl_device (device);
-
- meta_assert_in_kms_impl (device->kms);
- meta_assert_is_waiting_for_kms_impl_task (device->kms);
-
- meta_kms_impl_device_update_states (impl_device);
-
- g_list_free (device->crtcs);
- device->crtcs = meta_kms_impl_device_copy_crtcs (impl_device);
-
- g_list_free (device->connectors);
- device->connectors = meta_kms_impl_device_copy_connectors (impl_device);
-
- g_list_free (device->planes);
- device->planes = meta_kms_impl_device_copy_planes (impl_device);
-}
-
-void
-meta_kms_device_predict_states_in_impl (MetaKmsDevice *device,
- MetaKmsUpdate *update)
-{
- MetaKmsImplDevice *impl_device = meta_kms_device_get_impl_device (device);
-
- meta_assert_in_kms_impl (device->kms);
-
- meta_kms_impl_device_predict_states (impl_device, update);
-}
-
-void
-meta_kms_device_add_fake_plane_in_impl (MetaKmsDevice *device,
- MetaKmsPlaneType plane_type,
- MetaKmsCrtc *crtc)
-{
- MetaKmsImplDevice *impl_device = device->impl_device;
- MetaKmsPlane *plane;
-
- meta_assert_in_kms_impl (device->kms);
-
- plane = meta_kms_impl_device_add_fake_plane (impl_device,
- plane_type,
- crtc);
- device->planes = g_list_append (device->planes, plane);
-}
-
-typedef struct _CreateImplDeviceData
-{
- MetaKmsDevice *device;
- const char *path;
- MetaKmsDeviceFlag flags;
-
- MetaKmsImplDevice *out_impl_device;
- GList *out_crtcs;
- GList *out_connectors;
- GList *out_planes;
- MetaKmsDeviceCaps out_caps;
- GList *out_fallback_modes;
- char *out_driver_name;
- char *out_driver_description;
- char *out_path;
-} CreateImplDeviceData;
-
-static const char *
-impl_device_type_to_string (GType type)
-{
- if (type == META_TYPE_KMS_IMPL_DEVICE_ATOMIC)
- return "atomic modesetting";
- else if (type == META_TYPE_KMS_IMPL_DEVICE_SIMPLE)
- return "legacy modesetting";
- else if (type == META_TYPE_KMS_IMPL_DEVICE_DUMMY)
- return "no modesetting";
- g_assert_not_reached();
-}
-
-static MetaKmsImplDevice *
-meta_create_kms_impl_device (MetaKmsDevice *device,
- MetaKmsImpl *impl,
- const char *path,
- MetaKmsDeviceFlag flags,
- GError **error)
-{
- meta_assert_in_kms_impl (meta_kms_impl_get_kms (impl));
-
- if (flags & META_KMS_DEVICE_FLAG_NO_MODE_SETTING)
- {
- return g_initable_new (META_TYPE_KMS_IMPL_DEVICE_DUMMY,
- NULL, error,
- "device", device,
- "impl", impl,
- "path", path,
- "flags", flags,
- NULL);
- }
- else
- {
- GType impl_device_types[] = {
- META_TYPE_KMS_IMPL_DEVICE_ATOMIC,
- META_TYPE_KMS_IMPL_DEVICE_SIMPLE,
- };
- int i;
-
- for (i = 0; i < G_N_ELEMENTS (impl_device_types); i++)
- {
- MetaKmsImplDevice *impl_device;
- g_autoptr (GError) local_error = NULL;
-
- impl_device = g_initable_new (impl_device_types[i],
- NULL, &local_error,
- "device", device,
- "impl", impl,
- "path", path,
- "flags", flags,
- NULL);
- if (impl_device)
- return impl_device;
-
- if (local_error->domain != META_KMS_ERROR)
- {
- g_warning ("Failed to open %s backend: %s",
- impl_device_type_to_string (impl_device_types[i]),
- local_error->message);
- }
- }
-
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- "No suitable mode setting backend found");
-
- return NULL;
- }
-}
-
-static gpointer
-create_impl_device_in_impl (MetaKmsImpl *impl,
- gpointer user_data,
- GError **error)
-{
- CreateImplDeviceData *data = user_data;
- MetaKmsImplDevice *impl_device;
-
- impl_device = meta_create_kms_impl_device (data->device,
- impl,
- data->path,
- data->flags,
- error);
- if (!impl_device)
- return FALSE;
-
- meta_kms_impl_add_impl_device (impl, impl_device);
-
- data->out_impl_device = impl_device;
- data->out_crtcs = meta_kms_impl_device_copy_crtcs (impl_device);
- data->out_connectors = meta_kms_impl_device_copy_connectors (impl_device);
- data->out_planes = meta_kms_impl_device_copy_planes (impl_device);
- data->out_caps = *meta_kms_impl_device_get_caps (impl_device);
- data->out_fallback_modes =
- meta_kms_impl_device_copy_fallback_modes (impl_device);
- data->out_driver_name =
- g_strdup (meta_kms_impl_device_get_driver_name (impl_device));
- data->out_driver_description =
- g_strdup (meta_kms_impl_device_get_driver_description (impl_device));
- data->out_path = g_strdup (meta_kms_impl_device_get_path (impl_device));
-
- return GINT_TO_POINTER (TRUE);
-}
-
-MetaKmsDevice *
-meta_kms_device_new (MetaKms *kms,
- const char *path,
- MetaKmsDeviceFlag flags,
- GError **error)
-{
- MetaKmsDevice *device;
- CreateImplDeviceData data;
-
- device = g_object_new (META_TYPE_KMS_DEVICE, NULL);
- device->kms = kms;
-
- data = (CreateImplDeviceData) {
- .device = device,
- .path = path,
- .flags = flags,
- };
- if (!meta_kms_run_impl_task_sync (kms, create_impl_device_in_impl, &data,
- error))
- {
- g_object_unref (device);
- return NULL;
- }
-
- device->impl_device = data.out_impl_device;
- device->flags = flags;
- device->path = g_strdup (path);
- device->crtcs = data.out_crtcs;
- device->connectors = data.out_connectors;
- device->planes = data.out_planes;
- device->caps = data.out_caps;
- device->fallback_modes = data.out_fallback_modes;
- device->driver_name = data.out_driver_name;
- device->driver_description = data.out_driver_description;
- free (device->path);
- device->path = data.out_path;
-
- return device;
-}
-
-static gpointer
-free_impl_device_in_impl (MetaKmsImpl *impl,
- gpointer user_data,
- GError **error)
-{
- MetaKmsImplDevice *impl_device = user_data;
-
- g_object_unref (impl_device);
-
- return GINT_TO_POINTER (TRUE);
-}
-
-static void
-meta_kms_device_finalize (GObject *object)
-{
- MetaKmsDevice *device = META_KMS_DEVICE (object);
-
- g_free (device->path);
- g_list_free (device->crtcs);
- g_list_free (device->connectors);
- g_list_free (device->planes);
-
- if (device->impl_device)
- {
- meta_kms_run_impl_task_sync (device->kms, free_impl_device_in_impl,
- device->impl_device,
- NULL);
- }
-
- G_OBJECT_CLASS (meta_kms_device_parent_class)->finalize (object);
-}
-
-static void
-meta_kms_device_init (MetaKmsDevice *device)
-{
-}
-
-static void
-meta_kms_device_class_init (MetaKmsDeviceClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- object_class->finalize = meta_kms_device_finalize;
-}
diff --git a/src/backends/native/meta-kms-device.h b/src/backends/native/meta-kms-device.h
deleted file mode 100644
index 58dda6136..000000000
--- a/src/backends/native/meta-kms-device.h
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * Copyright (C) 2019 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-
-#ifndef META_KMS_DEVICE_H
-#define META_KMS_DEVICE_H
-
-#include <glib-object.h>
-
-#include "backends/native/meta-kms-types.h"
-
-#define META_TYPE_KMS_DEVICE (meta_kms_device_get_type ())
-G_DECLARE_FINAL_TYPE (MetaKmsDevice, meta_kms_device,
- META, KMS_DEVICE,
- GObject)
-
-MetaKms * meta_kms_device_get_kms (MetaKmsDevice *device);
-
-const char * meta_kms_device_get_path (MetaKmsDevice *device);
-
-const char * meta_kms_device_get_driver_name (MetaKmsDevice *device);
-
-const char * meta_kms_device_get_driver_description (MetaKmsDevice *device);
-
-MetaKmsDeviceFlag meta_kms_device_get_flags (MetaKmsDevice *device);
-
-gboolean meta_kms_device_get_cursor_size (MetaKmsDevice *device,
- uint64_t *out_cursor_width,
- uint64_t *out_cursor_height);
-
-gboolean meta_kms_device_prefers_shadow_buffer (MetaKmsDevice *device);
-
-gboolean meta_kms_device_uses_monotonic_clock (MetaKmsDevice *device);
-
-GList * meta_kms_device_get_connectors (MetaKmsDevice *device);
-
-GList * meta_kms_device_get_crtcs (MetaKmsDevice *device);
-
-GList * meta_kms_device_get_planes (MetaKmsDevice *device);
-
-MetaKmsPlane * meta_kms_device_get_primary_plane_for (MetaKmsDevice *device,
- MetaKmsCrtc *crtc);
-
-MetaKmsPlane * meta_kms_device_get_cursor_plane_for (MetaKmsDevice *device,
- MetaKmsCrtc *crtc);
-
-GList * meta_kms_device_get_fallback_modes (MetaKmsDevice *device);
-
-MetaKmsDevice * meta_kms_device_new (MetaKms *kms,
- const char *path,
- MetaKmsDeviceFlag flags,
- GError **error);
-
-#endif /* META_KMS_DEVICE_H */
diff --git a/src/backends/native/meta-kms-impl-device-atomic.c b/src/backends/native/meta-kms-impl-device-atomic.c
deleted file mode 100644
index 8e41207ee..000000000
--- a/src/backends/native/meta-kms-impl-device-atomic.c
+++ /dev/null
@@ -1,1202 +0,0 @@
-/*
- * Copyright (C) 2019-2020 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-
-#include "config.h"
-
-#include "backends/native/meta-kms-impl-device-atomic.h"
-
-#include "backends/native/meta-backend-native-private.h"
-#include "backends/native/meta-kms-connector-private.h"
-#include "backends/native/meta-kms-crtc-private.h"
-#include "backends/native/meta-kms-device-private.h"
-#include "backends/native/meta-kms-mode-private.h"
-#include "backends/native/meta-kms-plane-private.h"
-#include "backends/native/meta-kms-private.h"
-#include "backends/native/meta-kms-update-private.h"
-
-typedef gboolean (* MetaKmsAtomicProcessFunc) (MetaKmsImplDevice *impl_device,
- MetaKmsUpdate *update,
- drmModeAtomicReq *req,
- GArray *blob_ids,
- gpointer entry_data,
- gpointer user_data,
- GError **error);
-
-struct _MetaKmsImplDeviceAtomic
-{
- MetaKmsImplDevice parent;
-
- GHashTable *page_flip_datas;
-};
-
-static GInitableIface *initable_parent_iface;
-
-static void
-initable_iface_init (GInitableIface *iface);
-
-G_DEFINE_TYPE_WITH_CODE (MetaKmsImplDeviceAtomic, meta_kms_impl_device_atomic,
- META_TYPE_KMS_IMPL_DEVICE,
- G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE,
- initable_iface_init))
-
-static uint32_t
-store_new_blob (MetaKmsImplDevice *impl_device,
- GArray *blob_ids,
- const void *data,
- size_t size,
- GError **error)
-{
- int fd = meta_kms_impl_device_get_fd (impl_device);
- uint32_t blob_id;
- int ret;
-
- ret = drmModeCreatePropertyBlob (fd, data, size, &blob_id);
- if (ret < 0)
- {
- g_set_error (error, G_IO_ERROR, g_io_error_from_errno (-ret),
- "drmModeCreatePropertyBlob: %s", g_strerror (-ret));
- return 0;
- }
-
- g_array_append_val (blob_ids, blob_id);
-
- return blob_id;
-}
-
-static void
-release_blob_ids (MetaKmsImplDevice *impl_device,
- GArray *blob_ids)
-{
- int fd = meta_kms_impl_device_get_fd (impl_device);
- unsigned int i;
-
- for (i = 0; i < blob_ids->len; i++)
- {
- uint32_t blob_id = g_array_index (blob_ids, uint32_t, i);
-
- drmModeDestroyPropertyBlob (fd, blob_id);
- }
-}
-
-static gboolean
-add_connector_property (MetaKmsImplDevice *impl_device,
- MetaKmsConnector *connector,
- drmModeAtomicReq *req,
- MetaKmsConnectorProp prop,
- uint64_t value,
- GError **error)
-{
- int ret;
- uint32_t prop_id;
-
- prop_id = meta_kms_connector_get_prop_id (connector, prop);
- if (!prop_id)
- {
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
- "Connector property '%s' not found",
- meta_kms_connector_get_prop_name (connector, prop));
- return FALSE;
- }
-
- meta_topic (META_DEBUG_KMS,
- "[atomic] Setting connector %u (%s) property '%s' (%u) to %"
- G_GUINT64_FORMAT,
- meta_kms_connector_get_id (connector),
- meta_kms_impl_device_get_path (impl_device),
- meta_kms_connector_get_prop_name (connector, prop),
- meta_kms_connector_get_prop_id (connector, prop),
- value);
- ret = drmModeAtomicAddProperty (req,
- meta_kms_connector_get_id (connector),
- prop_id,
- value);
- if (ret < 0)
- {
- g_set_error (error, G_IO_ERROR, g_io_error_from_errno (-ret),
- "drmModeAtomicAddProperty, connector: %u, prop id: %u: %s",
- meta_kms_connector_get_id (connector),
- prop_id,
- g_strerror (-ret));
- return FALSE;
- }
-
- return TRUE;
-}
-
-static gboolean
-process_connector_update (MetaKmsImplDevice *impl_device,
- MetaKmsUpdate *update,
- drmModeAtomicReq *req,
- GArray *blob_ids,
- gpointer update_entry,
- gpointer user_data,
- GError **error)
-{
- MetaKmsConnectorUpdate *connector_update = update_entry;
- MetaKmsConnector *connector = connector_update->connector;
-
- if (connector_update->underscanning.has_update &&
- connector_update->underscanning.is_active)
- {
- meta_topic (META_DEBUG_KMS,
- "[atomic] Setting underscanning on connector %u (%s) to "
- "%" G_GUINT64_FORMAT "x%" G_GUINT64_FORMAT,
- meta_kms_connector_get_id (connector),
- meta_kms_impl_device_get_path (impl_device),
- connector_update->underscanning.hborder,
- connector_update->underscanning.vborder);
-
- if (!add_connector_property (impl_device,
- connector, req,
- META_KMS_CONNECTOR_PROP_UNDERSCAN,
- 1,
- error))
- return FALSE;
- if (!add_connector_property (impl_device,
- connector, req,
- META_KMS_CONNECTOR_PROP_UNDERSCAN_HBORDER,
- connector_update->underscanning.hborder,
- error))
- return FALSE;
- if (!add_connector_property (impl_device,
- connector, req,
- META_KMS_CONNECTOR_PROP_UNDERSCAN_VBORDER,
- connector_update->underscanning.vborder,
- error))
- return FALSE;
- }
- else if (connector_update->underscanning.has_update)
- {
- meta_topic (META_DEBUG_KMS,
- "[atomic] Unsetting underscanning on connector %u (%s)",
- meta_kms_connector_get_id (connector),
- meta_kms_impl_device_get_path (impl_device));
-
- if (!add_connector_property (impl_device,
- connector, req,
- META_KMS_CONNECTOR_PROP_UNDERSCAN,
- 0,
- error))
- return FALSE;
- }
-
- return TRUE;
-}
-
-static gboolean
-add_crtc_property (MetaKmsImplDevice *impl_device,
- MetaKmsCrtc *crtc,
- drmModeAtomicReq *req,
- MetaKmsCrtcProp prop,
- uint64_t value,
- GError **error)
-{
- int ret;
- uint32_t prop_id;
-
- prop_id = meta_kms_crtc_get_prop_id (crtc, prop);
- if (!prop_id)
- {
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
- "CRTC property (%s) not found",
- meta_kms_crtc_get_prop_name (crtc, prop));
- return FALSE;
- }
-
- meta_topic (META_DEBUG_KMS,
- "[atomic] Setting CRTC %u (%s) property '%s' (%u) to %"
- G_GUINT64_FORMAT,
- meta_kms_crtc_get_id (crtc),
- meta_kms_impl_device_get_path (impl_device),
- meta_kms_crtc_get_prop_name (crtc, prop),
- meta_kms_crtc_get_prop_id (crtc, prop),
- value);
- ret = drmModeAtomicAddProperty (req,
- meta_kms_crtc_get_id (crtc),
- prop_id,
- value);
- if (ret < 0)
- {
- g_set_error (error, G_IO_ERROR, g_io_error_from_errno (-ret),
- "drmModeAtomicAddProperty, crtc: %u, prop: %s (%u): %s",
- meta_kms_crtc_get_id (crtc),
- meta_kms_crtc_get_prop_name (crtc, prop),
- prop_id,
- g_strerror (-ret));
- return FALSE;
- }
-
- return TRUE;
-}
-
-static gboolean
-process_mode_set (MetaKmsImplDevice *impl_device,
- MetaKmsUpdate *update,
- drmModeAtomicReq *req,
- GArray *blob_ids,
- gpointer update_entry,
- gpointer user_data,
- GError **error)
-{
- MetaKmsModeSet *mode_set = update_entry;
- MetaKmsCrtc *crtc = mode_set->crtc;
- MetaKmsMode *mode;
-
- mode = (MetaKmsMode *) mode_set->mode;
- if (mode)
- {
- uint32_t mode_id;
- GList *l;
-
- mode_id = meta_kms_mode_create_blob_id (mode, error);
- if (mode_id == 0)
- return FALSE;
-
- g_array_append_val (blob_ids, mode_id);
-
- meta_topic (META_DEBUG_KMS,
- "[atomic] Setting mode of CRTC %u (%s) to %s",
- meta_kms_crtc_get_id (crtc),
- meta_kms_impl_device_get_path (impl_device),
- meta_kms_mode_get_name (mode));
-
- if (!add_crtc_property (impl_device,
- crtc, req,
- META_KMS_CRTC_PROP_MODE_ID,
- mode_id,
- error))
- return FALSE;
-
- if (!add_crtc_property (impl_device,
- crtc, req,
- META_KMS_CRTC_PROP_ACTIVE,
- 1,
- error))
- return FALSE;
-
- for (l = mode_set->connectors; l; l = l->next)
- {
- MetaKmsConnector *connector = l->data;
-
- if (!add_connector_property (impl_device,
- connector, req,
- META_KMS_CONNECTOR_PROP_CRTC_ID,
- meta_kms_crtc_get_id (crtc),
- error))
- return FALSE;
- }
- }
- else
- {
- if (!add_crtc_property (impl_device,
- crtc, req,
- META_KMS_CRTC_PROP_MODE_ID,
- 0,
- error))
- return FALSE;
-
- if (!add_crtc_property (impl_device,
- crtc, req,
- META_KMS_CRTC_PROP_ACTIVE,
- 0,
- error))
- return FALSE;
-
- meta_topic (META_DEBUG_KMS,
- "[atomic] Unsetting mode of (%u, %s)",
- meta_kms_crtc_get_id (crtc),
- meta_kms_impl_device_get_path (impl_device));
- }
-
- return TRUE;
-}
-
-static gboolean
-add_plane_property (MetaKmsImplDevice *impl_device,
- MetaKmsPlane *plane,
- drmModeAtomicReq *req,
- MetaKmsCrtcProp prop,
- uint64_t value,
- GError **error)
-{
- int ret;
- uint32_t prop_id;
-
- prop_id = meta_kms_plane_get_prop_id (plane, prop);
- if (!prop_id)
- {
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
- "Plane property (%s) not found on %u",
- meta_kms_plane_get_prop_name (plane, prop),
- meta_kms_plane_get_id (plane));
- return FALSE;
- }
-
- switch (meta_kms_plane_get_prop_internal_type (plane, prop))
- {
- case META_KMS_PROP_TYPE_RAW:
- meta_topic (META_DEBUG_KMS,
- "[atomic] Setting plane %u (%s) property '%s' (%u) to %"
- G_GUINT64_FORMAT,
- meta_kms_plane_get_id (plane),
- meta_kms_impl_device_get_path (impl_device),
- meta_kms_plane_get_prop_name (plane, prop),
- meta_kms_plane_get_prop_id (plane, prop),
- value);
- break;
- case META_KMS_PROP_TYPE_FIXED_16:
- meta_topic (META_DEBUG_KMS,
- "[atomic] Setting plane %u (%s) property '%s' (%u) to %.2f",
- meta_kms_plane_get_id (plane),
- meta_kms_impl_device_get_path (impl_device),
- meta_kms_plane_get_prop_name (plane, prop),
- meta_kms_plane_get_prop_id (plane, prop),
- meta_fixed_16_to_double (value));
- break;
- }
- ret = drmModeAtomicAddProperty (req,
- meta_kms_plane_get_id (plane),
- prop_id,
- value);
- if (ret < 0)
- {
- g_set_error (error, G_IO_ERROR, g_io_error_from_errno (-ret),
- "drmModeAtomicAddProperty, plane: %u, prop: %s (%u): %s",
- meta_kms_plane_get_id (plane),
- meta_kms_plane_get_prop_name (plane, prop),
- prop_id,
- g_strerror (-ret));
- return FALSE;
- }
-
- return TRUE;
-}
-
-static const char *
-get_plane_type_string (MetaKmsPlane *plane)
-{
- switch (meta_kms_plane_get_plane_type (plane))
- {
- case META_KMS_PLANE_TYPE_PRIMARY:
- return "primary";
- case META_KMS_PLANE_TYPE_CURSOR:
- return "cursor";
- case META_KMS_PLANE_TYPE_OVERLAY:
- return "overlay";
- }
-
- g_assert_not_reached ();
-}
-
-static gboolean
-process_plane_assignment (MetaKmsImplDevice *impl_device,
- MetaKmsUpdate *update,
- drmModeAtomicReq *req,
- GArray *blob_ids,
- gpointer update_entry,
- gpointer user_data,
- GError **error)
-{
- MetaKmsPlaneAssignment *plane_assignment = update_entry;
- MetaKmsPlane *plane = plane_assignment->plane;
- MetaDrmBuffer *buffer;
-
- buffer = plane_assignment->buffer;
-
- meta_topic (META_DEBUG_KMS,
- "[atomic] Assigning %s plane (%u, %s) to %u, "
- "%hdx%hd+%hd+%hd -> %dx%d+%d+%d",
- get_plane_type_string (plane),
- meta_kms_plane_get_id (plane),
- meta_kms_impl_device_get_path (impl_device),
- buffer ? meta_drm_buffer_get_fb_id (buffer) : 0,
- meta_fixed_16_to_int (plane_assignment->src_rect.width),
- meta_fixed_16_to_int (plane_assignment->src_rect.height),
- meta_fixed_16_to_int (plane_assignment->src_rect.x),
- meta_fixed_16_to_int (plane_assignment->src_rect.y),
- plane_assignment->dst_rect.width,
- plane_assignment->dst_rect.height,
- plane_assignment->dst_rect.x,
- plane_assignment->dst_rect.y);
-
- if (buffer)
- {
- int i;
- struct {
- MetaKmsPlaneProp prop;
- uint64_t value;
- } props[] = {
- {
- .prop = META_KMS_PLANE_PROP_FB_ID,
- .value = meta_drm_buffer_get_fb_id (buffer),
- },
- {
- .prop = META_KMS_PLANE_PROP_CRTC_ID,
- .value = meta_kms_crtc_get_id (plane_assignment->crtc),
- },
- {
- .prop = META_KMS_PLANE_PROP_SRC_X,
- .value = plane_assignment->src_rect.x,
- },
- {
- .prop = META_KMS_PLANE_PROP_SRC_Y,
- .value = plane_assignment->src_rect.y,
- },
- {
- .prop = META_KMS_PLANE_PROP_SRC_W,
- .value = plane_assignment->src_rect.width,
- },
- {
- .prop = META_KMS_PLANE_PROP_SRC_H,
- .value = plane_assignment->src_rect.height,
- },
- {
- .prop = META_KMS_PLANE_PROP_CRTC_X,
- .value = plane_assignment->dst_rect.x,
- },
- {
- .prop = META_KMS_PLANE_PROP_CRTC_Y,
- .value = plane_assignment->dst_rect.y,
- },
- {
- .prop = META_KMS_PLANE_PROP_CRTC_W,
- .value = plane_assignment->dst_rect.width,
- },
- {
- .prop = META_KMS_PLANE_PROP_CRTC_H,
- .value = plane_assignment->dst_rect.height,
- },
- };
-
- for (i = 0; i < G_N_ELEMENTS (props); i++)
- {
- if (!add_plane_property (impl_device,
- plane, req,
- props[i].prop,
- props[i].value,
- error))
- return FALSE;
- }
- }
- else
- {
- int i;
- struct {
- MetaKmsPlaneProp prop;
- uint64_t value;
- } props[] = {
- {
- .prop = META_KMS_PLANE_PROP_FB_ID,
- .value = 0,
- },
- {
- .prop = META_KMS_PLANE_PROP_CRTC_ID,
- .value = 0,
- },
- };
-
- for (i = 0; i < G_N_ELEMENTS (props); i++)
- {
- if (!add_plane_property (impl_device,
- plane, req,
- props[i].prop,
- props[i].value,
- error))
- return FALSE;
- }
- }
-
- if (plane_assignment->rotation)
- {
- meta_topic (META_DEBUG_KMS,
- "[atomic] Setting plane (%u, %s) rotation to %"
- G_GUINT64_FORMAT,
- meta_kms_plane_get_id (plane),
- meta_kms_impl_device_get_path (impl_device),
- plane_assignment->rotation);
-
- if (!add_plane_property (impl_device,
- plane, req,
- META_KMS_PLANE_PROP_ROTATION,
- plane_assignment->rotation,
- error))
- return FALSE;
- }
-
- return TRUE;
-}
-
-static gboolean
-process_crtc_gamma (MetaKmsImplDevice *impl_device,
- MetaKmsUpdate *update,
- drmModeAtomicReq *req,
- GArray *blob_ids,
- gpointer update_entry,
- gpointer user_data,
- GError **error)
-{
- MetaKmsCrtcGamma *gamma = update_entry;
- MetaKmsCrtc *crtc = gamma->crtc;
- struct drm_color_lut drm_color_lut[gamma->size];
- int i;
- uint32_t color_lut_blob_id;
-
- for (i = 0; i < gamma->size; i++)
- {
- drm_color_lut[i].red = gamma->red[i];
- drm_color_lut[i].green = gamma->green[i];
- drm_color_lut[i].blue = gamma->blue[i];
- }
-
- color_lut_blob_id = store_new_blob (impl_device,
- blob_ids,
- drm_color_lut,
- sizeof drm_color_lut,
- error);
- if (!color_lut_blob_id)
- return FALSE;
-
- meta_topic (META_DEBUG_KMS,
- "[atomic] Setting CRTC (%u, %s) gamma, size: %d",
- meta_kms_crtc_get_id (crtc),
- meta_kms_impl_device_get_path (impl_device),
- gamma->size);
-
- if (!add_crtc_property (impl_device,
- crtc, req,
- META_KMS_CRTC_PROP_GAMMA_LUT,
- color_lut_blob_id,
- error))
- return FALSE;
-
- return TRUE;
-}
-
-static gboolean
-process_page_flip_listener (MetaKmsImplDevice *impl_device,
- MetaKmsUpdate *update,
- drmModeAtomicReq *req,
- GArray *blob_ids,
- gpointer update_entry,
- gpointer user_data,
- GError **error)
-{
- MetaKmsImplDeviceAtomic *impl_device_atomic =
- META_KMS_IMPL_DEVICE_ATOMIC (impl_device);
- MetaKmsPageFlipListener *listener = update_entry;
- MetaKmsPageFlipData *page_flip_data;
- uint32_t crtc_id;
- gpointer listener_user_data;
- GDestroyNotify listener_destroy_notify;
-
- crtc_id = meta_kms_crtc_get_id (listener->crtc);
- page_flip_data = g_hash_table_lookup (impl_device_atomic->page_flip_datas,
- GUINT_TO_POINTER (crtc_id));
- if (!page_flip_data)
- {
- page_flip_data = meta_kms_page_flip_data_new (impl_device,
- listener->crtc);
- g_hash_table_insert (impl_device_atomic->page_flip_datas,
- GUINT_TO_POINTER (crtc_id),
- page_flip_data);
-
- meta_kms_impl_device_hold_fd (impl_device);
-
- meta_topic (META_DEBUG_KMS,
- "[atomic] Adding page flip data for (%u, %s): %p",
- crtc_id,
- meta_kms_impl_device_get_path (impl_device),
- page_flip_data);
- }
-
- listener_user_data = g_steal_pointer (&listener->user_data);
- listener_destroy_notify = g_steal_pointer (&listener->destroy_notify);
- meta_kms_page_flip_data_add_listener (page_flip_data,
- listener->vtable,
- listener->flags,
- listener_user_data,
- listener_destroy_notify);
-
- return TRUE;
-}
-
-static gboolean
-discard_page_flip_listener (MetaKmsImplDevice *impl_device,
- MetaKmsUpdate *update,
- drmModeAtomicReq *req,
- GArray *blob_ids,
- gpointer update_entry,
- gpointer user_data,
- GError **error)
-{
- MetaKmsPageFlipListener *listener = update_entry;
- GError *commit_error = user_data;
- MetaKmsPageFlipData *page_flip_data;
- gpointer listener_user_data;
- GDestroyNotify listener_destroy_notify;
-
- page_flip_data = meta_kms_page_flip_data_new (impl_device,
- listener->crtc);
-
- meta_topic (META_DEBUG_KMS,
- "[atomic] Creating transient page flip data for (%u, %s): %p",
- meta_kms_crtc_get_id (listener->crtc),
- meta_kms_impl_device_get_path (impl_device),
- page_flip_data);
-
- listener_user_data = g_steal_pointer (&listener->user_data);
- listener_destroy_notify = g_steal_pointer (&listener->destroy_notify);
- meta_kms_page_flip_data_add_listener (page_flip_data,
- listener->vtable,
- listener->flags,
- listener_user_data,
- listener_destroy_notify);
-
- meta_kms_page_flip_data_discard_in_impl (page_flip_data, commit_error);
-
- return TRUE;
-}
-
-static gboolean
-process_entries (MetaKmsImplDevice *impl_device,
- MetaKmsUpdate *update,
- drmModeAtomicReq *req,
- GArray *blob_ids,
- GList *entries,
- gpointer user_data,
- MetaKmsAtomicProcessFunc func,
- GError **error)
-{
- GList *l;
-
- for (l = entries; l; l = l->next)
- {
- if (!func (impl_device,
- update,
- req,
- blob_ids,
- l->data,
- user_data,
- error))
- return FALSE;
- }
-
- return TRUE;
-}
-
-static void
-atomic_page_flip_handler (int fd,
- unsigned int sequence,
- unsigned int tv_sec,
- unsigned int tv_usec,
- unsigned int crtc_id,
- void *user_data)
-{
- MetaKmsImplDeviceAtomic *impl_device_atomic = user_data;
- MetaKmsImplDevice *impl_device = META_KMS_IMPL_DEVICE (impl_device_atomic);
- MetaKmsPageFlipData *page_flip_data = NULL;
-
- g_hash_table_steal_extended (impl_device_atomic->page_flip_datas,
- GUINT_TO_POINTER (crtc_id),
- NULL,
- (gpointer *) &page_flip_data);
-
- meta_topic (META_DEBUG_KMS,
- "[atomic] Page flip callback for CRTC (%u, %s), data: %p",
- crtc_id, meta_kms_impl_device_get_path (impl_device),
- page_flip_data);
-
- if (!page_flip_data)
- return;
-
- meta_kms_impl_device_unhold_fd (impl_device);
-
- meta_kms_page_flip_data_set_timings_in_impl (page_flip_data,
- sequence, tv_sec, tv_usec);
- meta_kms_impl_device_handle_page_flip_callback (impl_device, page_flip_data);
-}
-
-static void
-meta_kms_impl_device_atomic_setup_drm_event_context (MetaKmsImplDevice *impl_device,
- drmEventContext *drm_event_context)
-{
- drm_event_context->version = 3;
- drm_event_context->page_flip_handler2 = atomic_page_flip_handler;
-}
-
-static const char *
-commit_flags_string (uint32_t commit_flags)
-{
- static char static_commit_flags_string[255];
- const char *commit_flag_strings[4] = { NULL };
- int i = 0;
- g_autofree char *commit_flags_string = NULL;
-
- if (commit_flags & DRM_MODE_ATOMIC_NONBLOCK)
- commit_flag_strings[i++] = "ATOMIC_NONBLOCK";
- if (commit_flags & DRM_MODE_ATOMIC_ALLOW_MODESET)
- commit_flag_strings[i++] = "ATOMIC_ALLOW_MODESET";
- if (commit_flags & DRM_MODE_PAGE_FLIP_EVENT)
- commit_flag_strings[i++] = "PAGE_FLIP_EVENT";
-
- commit_flags_string = g_strjoinv ("|", (char **) commit_flag_strings);
- strncpy (static_commit_flags_string, commit_flags_string,
- (sizeof static_commit_flags_string) - 1);
-
- return static_commit_flags_string;
-}
-
-static gboolean
-disable_connectors (MetaKmsImplDevice *impl_device,
- drmModeAtomicReq *req,
- GError **error)
-{
- GList *l;
-
- for (l = meta_kms_impl_device_peek_connectors (impl_device); l; l = l->next)
- {
- MetaKmsConnector *connector = l->data;
-
- if (!add_connector_property (impl_device,
- connector, req,
- META_KMS_CONNECTOR_PROP_CRTC_ID,
- 0,
- error))
- return FALSE;
- }
-
- return TRUE;
-}
-
-static gboolean
-disable_planes (MetaKmsImplDevice *impl_device,
- drmModeAtomicReq *req,
- GError **error)
-{
- GList *l;
-
- for (l = meta_kms_impl_device_peek_planes (impl_device); l; l = l->next)
- {
- MetaKmsPlane *plane = l->data;
-
- if (!add_plane_property (impl_device,
- plane, req,
- META_KMS_PLANE_PROP_CRTC_ID,
- 0,
- error))
- return FALSE;
-
- if (!add_plane_property (impl_device,
- plane, req,
- META_KMS_PLANE_PROP_FB_ID,
- 0,
- error))
- return FALSE;
- }
-
- return TRUE;
-}
-
-static gboolean
-disable_crtcs (MetaKmsImplDevice *impl_device,
- drmModeAtomicReq *req,
- GError **error)
-{
- GList *l;
-
- for (l = meta_kms_impl_device_peek_crtcs (impl_device); l; l = l->next)
- {
- MetaKmsCrtc *crtc = l->data;
-
- if (!add_crtc_property (impl_device,
- crtc, req,
- META_KMS_CRTC_PROP_ACTIVE,
- 0,
- error))
- return FALSE;
-
- if (!add_crtc_property (impl_device,
- crtc, req,
- META_KMS_CRTC_PROP_MODE_ID,
- 0,
- error))
- return FALSE;
- }
-
- return TRUE;
-}
-
-static gboolean
-disable_planes_and_connectors (MetaKmsImplDevice *impl_device,
- drmModeAtomicReq *req,
- GError **error)
-{
- if (!disable_connectors (impl_device, req, error))
- return FALSE;
- if (!disable_planes (impl_device, req, error))
- return FALSE;
-
- return TRUE;
-}
-
-static gboolean
-process_power_save (MetaKmsImplDevice *impl_device,
- drmModeAtomicReq *req,
- GError **error)
-{
- if (!disable_connectors (impl_device, req, error))
- return FALSE;
- if (!disable_planes (impl_device, req, error))
- return FALSE;
- if (!disable_crtcs (impl_device, req, error))
- return FALSE;
-
- return TRUE;
-}
-
-static MetaKmsFeedback *
-meta_kms_impl_device_atomic_process_update (MetaKmsImplDevice *impl_device,
- MetaKmsUpdate *update,
- MetaKmsUpdateFlag flags)
-{
- GError *error = NULL;
- GList *failed_planes = NULL;
- drmModeAtomicReq *req;
- g_autoptr (GArray) blob_ids = NULL;
- int fd;
- uint32_t commit_flags = 0;
- int ret;
-
- blob_ids = g_array_new (FALSE, TRUE, sizeof (uint32_t));
-
- meta_topic (META_DEBUG_KMS,
- "[atomic] Processing update %" G_GUINT64_FORMAT,
- meta_kms_update_get_sequence_number (update));
-
- req = drmModeAtomicAlloc ();
- if (!req)
- {
- g_set_error (&error, G_IO_ERROR, G_IO_ERROR_FAILED,
- "Failed to create atomic transaction request: %s",
- g_strerror (errno));
- goto err;
- }
-
- if (meta_kms_update_get_mode_sets (update))
- {
- if (!disable_planes_and_connectors (impl_device, req, &error))
- goto err;
- }
-
- if (meta_kms_update_is_power_save (update))
- {
- meta_topic (META_DEBUG_KMS,
- "[atomic] Entering power save mode for %s",
- meta_kms_impl_device_get_path (impl_device));
-
- if (!process_power_save (impl_device, req, &error))
- goto err;
-
- commit_flags = DRM_MODE_ATOMIC_ALLOW_MODESET;
- goto commit;
- }
-
- if (!process_entries (impl_device,
- update,
- req,
- blob_ids,
- meta_kms_update_get_connector_updates (update),
- NULL,
- process_connector_update,
- &error))
- goto err;
-
- if (!process_entries (impl_device,
- update,
- req,
- blob_ids,
- meta_kms_update_get_mode_sets (update),
- NULL,
- process_mode_set,
- &error))
- goto err;
-
- if (!process_entries (impl_device,
- update,
- req,
- blob_ids,
- meta_kms_update_get_plane_assignments (update),
- NULL,
- process_plane_assignment,
- &error))
- goto err;
-
- if (!process_entries (impl_device,
- update,
- req,
- blob_ids,
- meta_kms_update_get_crtc_gammas (update),
- NULL,
- process_crtc_gamma,
- &error))
- goto err;
-
- if (meta_kms_update_get_mode_sets (update))
- commit_flags |= DRM_MODE_ATOMIC_ALLOW_MODESET;
- else
- commit_flags |= DRM_MODE_ATOMIC_NONBLOCK;
-
- if (meta_kms_update_get_page_flip_listeners (update))
- commit_flags |= DRM_MODE_PAGE_FLIP_EVENT;
-
-commit:
- meta_topic (META_DEBUG_KMS,
- "[atomic] Committing update %" G_GUINT64_FORMAT ", flags: %s",
- meta_kms_update_get_sequence_number (update),
- commit_flags_string (commit_flags));
-
- fd = meta_kms_impl_device_get_fd (impl_device);
- ret = drmModeAtomicCommit (fd, req, commit_flags, impl_device);
- drmModeAtomicFree (req);
- if (ret < 0)
- {
- g_set_error (&error, G_IO_ERROR, g_io_error_from_errno (-ret),
- "drmModeAtomicCommit: %s", g_strerror (-ret));
- goto err;
- }
-
- process_entries (impl_device,
- update,
- req,
- blob_ids,
- meta_kms_update_get_page_flip_listeners (update),
- NULL,
- process_page_flip_listener,
- NULL);
-
- release_blob_ids (impl_device, blob_ids);
-
- return meta_kms_feedback_new_passed (NULL);
-
-err:
- meta_topic (META_DEBUG_KMS, "[atomic] KMS update failed: %s", error->message);
-
- if (!(flags & META_KMS_UPDATE_FLAG_PRESERVE_ON_ERROR))
- {
- process_entries (impl_device,
- update,
- req,
- blob_ids,
- meta_kms_update_get_page_flip_listeners (update),
- error,
- discard_page_flip_listener,
- NULL);
- }
-
- release_blob_ids (impl_device, blob_ids);
-
- return meta_kms_feedback_new_failed (failed_planes, error);
-}
-
-static void
-meta_kms_impl_device_atomic_handle_page_flip_callback (MetaKmsImplDevice *impl_device,
- MetaKmsPageFlipData *page_flip_data)
-{
- meta_kms_page_flip_data_flipped_in_impl (page_flip_data);
-}
-
-static void
-meta_kms_impl_device_atomic_discard_pending_page_flips (MetaKmsImplDevice *impl_device)
-{
-}
-
-static gboolean
-dispose_page_flip_data (gpointer key,
- gpointer value,
- gpointer user_data)
-{
- MetaKmsPageFlipData *page_flip_data = value;
- MetaKmsImplDevice *impl_device = user_data;
-
- meta_kms_page_flip_data_discard_in_impl (page_flip_data, NULL);
- meta_kms_impl_device_unhold_fd (impl_device);
-
- return TRUE;
-}
-
-static void
-meta_kms_impl_device_atomic_prepare_shutdown (MetaKmsImplDevice *impl_device)
-{
- MetaKmsImplDeviceAtomic *impl_device_atomic =
- META_KMS_IMPL_DEVICE_ATOMIC (impl_device);
-
- g_hash_table_foreach_remove (impl_device_atomic->page_flip_datas,
- dispose_page_flip_data,
- impl_device);
-}
-
-static void
-meta_kms_impl_device_atomic_finalize (GObject *object)
-{
- MetaKmsImplDeviceAtomic *impl_device_atomic =
- META_KMS_IMPL_DEVICE_ATOMIC (object);
-
- g_assert (g_hash_table_size (impl_device_atomic->page_flip_datas) == 0);
-
- g_hash_table_unref (impl_device_atomic->page_flip_datas);
-
- G_OBJECT_CLASS (meta_kms_impl_device_atomic_parent_class)->finalize (object);
-}
-
-static MetaDeviceFile *
-meta_kms_impl_device_atomic_open_device_file (MetaKmsImplDevice *impl_device,
- const char *path,
- GError **error)
-{
- MetaKmsDevice *device = meta_kms_impl_device_get_device (impl_device);
- MetaKms *kms = meta_kms_device_get_kms (device);
- MetaBackend *backend = meta_kms_get_backend (kms);
- MetaDevicePool *device_pool =
- meta_backend_native_get_device_pool (META_BACKEND_NATIVE (backend));
- g_autoptr (MetaDeviceFile) device_file = NULL;
-
- device_file = meta_device_pool_open (device_pool, path,
- META_DEVICE_FILE_FLAG_TAKE_CONTROL,
- error);
- if (!device_file)
- return NULL;
-
- if (!meta_device_file_has_tag (device_file,
- META_DEVICE_FILE_TAG_KMS,
- META_KMS_DEVICE_FILE_TAG_ATOMIC))
- {
- int fd = meta_device_file_get_fd (device_file);
-
- g_warn_if_fail (!meta_device_file_has_tag (device_file,
- META_DEVICE_FILE_TAG_KMS,
- META_KMS_DEVICE_FILE_TAG_SIMPLE));
-
- if (drmSetClientCap (fd, DRM_CLIENT_CAP_UNIVERSAL_PLANES, 1) != 0)
- {
- g_set_error (error, META_KMS_ERROR, META_KMS_ERROR_NOT_SUPPORTED,
- "DRM_CLIENT_CAP_UNIVERSAL_PLANES not supported");
- return NULL;
- }
-
- if (drmSetClientCap (fd, DRM_CLIENT_CAP_ATOMIC, 1) != 0)
- {
- g_set_error (error, META_KMS_ERROR, META_KMS_ERROR_NOT_SUPPORTED,
- "DRM_CLIENT_CAP_ATOMIC not supported");
- return NULL;
- }
-
- meta_device_file_tag (device_file,
- META_DEVICE_FILE_TAG_KMS,
- META_KMS_DEVICE_FILE_TAG_ATOMIC);
- }
-
- return g_steal_pointer (&device_file);
-}
-
-static gboolean
-is_atomic_allowed (const char *driver_name)
-{
- const char *atomic_driver_deny_list[] = {
- "qxl",
- "vmwgfx",
- "vboxvideo",
- "nvidia-drm",
- NULL,
- };
-
- return !g_strv_contains (atomic_driver_deny_list, driver_name);
-}
-
-static gboolean
-meta_kms_impl_device_atomic_initable_init (GInitable *initable,
- GCancellable *cancellable,
- GError **error)
-{
- MetaKmsImplDevice *impl_device = META_KMS_IMPL_DEVICE (initable);
- const char *atomic_kms_enable_env;
-
- atomic_kms_enable_env = getenv ("MUTTER_DEBUG_ENABLE_ATOMIC_KMS");
- if (atomic_kms_enable_env && g_strcmp0 (atomic_kms_enable_env, "1") != 0)
- {
- g_set_error (error, META_KMS_ERROR, META_KMS_ERROR_USER_INHIBITED,
- "Atomic mode setting disable via env var");
- return FALSE;
- }
-
- if (!initable_parent_iface->init (initable, cancellable, error))
- return FALSE;
-
- if (!is_atomic_allowed (meta_kms_impl_device_get_driver_name (impl_device)))
- {
- g_set_error (error, META_KMS_ERROR, META_KMS_ERROR_DENY_LISTED,
- "Atomic mode setting disable via driver deny list");
- return FALSE;
- }
-
- if (!meta_kms_impl_device_init_mode_setting (impl_device, error))
- return FALSE;
-
- g_message ("Added device '%s' (%s) using atomic mode setting.",
- meta_kms_impl_device_get_path (impl_device),
- meta_kms_impl_device_get_driver_name (impl_device));
-
- return TRUE;
-}
-
-static void
-meta_kms_impl_device_atomic_init (MetaKmsImplDeviceAtomic *impl_device_atomic)
-{
- impl_device_atomic->page_flip_datas = g_hash_table_new (NULL, NULL);
-}
-
-static void
-initable_iface_init (GInitableIface *iface)
-{
- initable_parent_iface = g_type_interface_peek_parent (iface);
-
- iface->init = meta_kms_impl_device_atomic_initable_init;
-}
-
-static void
-meta_kms_impl_device_atomic_class_init (MetaKmsImplDeviceAtomicClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
- MetaKmsImplDeviceClass *impl_device_class =
- META_KMS_IMPL_DEVICE_CLASS (klass);
-
- object_class->finalize = meta_kms_impl_device_atomic_finalize;
-
- impl_device_class->open_device_file =
- meta_kms_impl_device_atomic_open_device_file;
- impl_device_class->setup_drm_event_context =
- meta_kms_impl_device_atomic_setup_drm_event_context;
- impl_device_class->process_update =
- meta_kms_impl_device_atomic_process_update;
- impl_device_class->handle_page_flip_callback =
- meta_kms_impl_device_atomic_handle_page_flip_callback;
- impl_device_class->discard_pending_page_flips =
- meta_kms_impl_device_atomic_discard_pending_page_flips;
- impl_device_class->prepare_shutdown =
- meta_kms_impl_device_atomic_prepare_shutdown;
-}
diff --git a/src/backends/native/meta-kms-impl-device-atomic.h b/src/backends/native/meta-kms-impl-device-atomic.h
deleted file mode 100644
index 74658797c..000000000
--- a/src/backends/native/meta-kms-impl-device-atomic.h
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Copyright (C) 2019 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-
-#ifndef META_KMS_IMPL_DEVICE_ATOMIC_H
-#define META_KMS_IMPL_DEVICE_ATOMIC_H
-
-#include "backends/native/meta-kms-impl-device.h"
-
-#define META_TYPE_KMS_IMPL_DEVICE_ATOMIC (meta_kms_impl_device_atomic_get_type ())
-G_DECLARE_FINAL_TYPE (MetaKmsImplDeviceAtomic, meta_kms_impl_device_atomic,
- META, KMS_IMPL_DEVICE_ATOMIC, MetaKmsImplDevice)
-
-#endif /* META_KMS_IMPL_DEVICE_ATOMIC_H */
diff --git a/src/backends/native/meta-kms-impl-device-dummy.c b/src/backends/native/meta-kms-impl-device-dummy.c
deleted file mode 100644
index 02583bbeb..000000000
--- a/src/backends/native/meta-kms-impl-device-dummy.c
+++ /dev/null
@@ -1,127 +0,0 @@
-/*
- * Copyright (C) 2021 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-
-#include "config.h"
-
-#include "backends/native/meta-kms-impl-device-dummy.h"
-
-#include "backends/native/meta-backend-native-private.h"
-#include "backends/native/meta-kms.h"
-
-struct _MetaKmsImplDeviceDummy
-{
- MetaKmsImplDevice parent;
-};
-
-static GInitableIface *initable_parent_iface;
-
-static void
-initable_iface_init (GInitableIface *iface);
-
-G_DEFINE_TYPE_WITH_CODE (MetaKmsImplDeviceDummy,
- meta_kms_impl_device_dummy,
- META_TYPE_KMS_IMPL_DEVICE,
- G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE,
- initable_iface_init))
-
-static void
-meta_kms_impl_device_dummy_discard_pending_page_flips (MetaKmsImplDevice *impl_device)
-{
-}
-
-static MetaDeviceFile *
-meta_kms_impl_device_dummy_open_device_file (MetaKmsImplDevice *impl_device,
- const char *path,
- GError **error)
-{
- MetaKmsDevice *device = meta_kms_impl_device_get_device (impl_device);
- MetaKms *kms = meta_kms_device_get_kms (device);
- MetaBackend *backend = meta_kms_get_backend (kms);
- MetaDevicePool *device_pool =
- meta_backend_native_get_device_pool (META_BACKEND_NATIVE (backend));
- g_autoptr (MetaDeviceFile) device_file = NULL;
- int fd;
- g_autofree char *render_node_path = NULL;
-
- device_file = meta_device_pool_open (device_pool, path,
- META_DEVICE_FILE_FLAG_NONE,
- error);
- if (!device_file)
- return NULL;
-
- fd = meta_device_file_get_fd (device_file);
- render_node_path = drmGetRenderDeviceNameFromFd (fd);
- if (!render_node_path)
- {
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- "Couldn't find render node device for '%s' (%s)",
- meta_kms_impl_device_get_path (impl_device),
- meta_kms_impl_device_get_driver_name (impl_device));
- return NULL;
- }
-
- meta_topic (META_DEBUG_KMS, "Found render node '%s' from '%s'",
- render_node_path, path);
-
- return meta_device_pool_open (device_pool, render_node_path,
- META_DEVICE_FILE_FLAG_NONE,
- error);
-}
-
-static gboolean
-meta_kms_impl_device_dummy_initable_init (GInitable *initable,
- GCancellable *cancellable,
- GError **error)
-{
- MetaKmsImplDevice *impl_device = META_KMS_IMPL_DEVICE (initable);
-
- if (!initable_parent_iface->init (initable, cancellable, error))
- return FALSE;
-
- g_message ("Added device '%s' (%s) using no mode setting.",
- meta_kms_impl_device_get_path (impl_device),
- meta_kms_impl_device_get_driver_name (impl_device));
-
- return TRUE;
-}
-
-static void
-initable_iface_init (GInitableIface *iface)
-{
- initable_parent_iface = g_type_interface_peek_parent (iface);
-
- iface->init = meta_kms_impl_device_dummy_initable_init;
-}
-
-static void
-meta_kms_impl_device_dummy_init (MetaKmsImplDeviceDummy *impl_device_dummy)
-{
-}
-
-static void
-meta_kms_impl_device_dummy_class_init (MetaKmsImplDeviceDummyClass *klass)
-{
- MetaKmsImplDeviceClass *impl_device_class =
- META_KMS_IMPL_DEVICE_CLASS (klass);
-
- impl_device_class->open_device_file =
- meta_kms_impl_device_dummy_open_device_file;
- impl_device_class->discard_pending_page_flips =
- meta_kms_impl_device_dummy_discard_pending_page_flips;
-}
diff --git a/src/backends/native/meta-kms-impl-device-dummy.h b/src/backends/native/meta-kms-impl-device-dummy.h
deleted file mode 100644
index 9576939ad..000000000
--- a/src/backends/native/meta-kms-impl-device-dummy.h
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Copyright (C) 2021 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-
-#ifndef META_KMS_IMPL_DEVICE_DUMMY_H
-#define META_KMS_IMPL_DEVICE_DUMMY_H
-
-#include "backends/native/meta-kms-impl-device.h"
-
-#define META_TYPE_KMS_IMPL_DEVICE_DUMMY (meta_kms_impl_device_dummy_get_type ())
-G_DECLARE_FINAL_TYPE (MetaKmsImplDeviceDummy, meta_kms_impl_device_dummy,
- META, KMS_IMPL_DEVICE_DUMMY,
- MetaKmsImplDevice)
-
-#endif /* META_KMS_IMPL_DEVICE_DUMMY_H */
diff --git a/src/backends/native/meta-kms-impl-device-simple.c b/src/backends/native/meta-kms-impl-device-simple.c
deleted file mode 100644
index 28d512720..000000000
--- a/src/backends/native/meta-kms-impl-device-simple.c
+++ /dev/null
@@ -1,1678 +0,0 @@
-/*
- * Copyright (C) 2019-2020 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-
-#include "config.h"
-
-#include "backends/native/meta-kms-impl-device-simple.h"
-
-#include "backends/native/meta-backend-native-private.h"
-#include "backends/native/meta-drm-buffer-gbm.h"
-#include "backends/native/meta-kms-connector-private.h"
-#include "backends/native/meta-kms-crtc-private.h"
-#include "backends/native/meta-kms-device-private.h"
-#include "backends/native/meta-kms-mode-private.h"
-#include "backends/native/meta-kms-plane-private.h"
-#include "backends/native/meta-kms-private.h"
-#include "backends/native/meta-kms-update-private.h"
-#include "backends/native/meta-kms-utils.h"
-
-typedef gboolean (* MetaKmsSimpleProcessFunc) (MetaKmsImplDevice *impl_device,
- MetaKmsUpdate *update,
- gpointer entry_data,
- GError **error);
-
-typedef struct _CachedModeSet
-{
- GList *connectors;
- drmModeModeInfo *drm_mode;
-} CachedModeSet;
-
-struct _MetaKmsImplDeviceSimple
-{
- MetaKmsImplDevice parent;
-
- GSource *mode_set_fallback_feedback_source;
- GList *mode_set_fallback_page_flip_datas;
-
- GList *pending_page_flip_retries;
- GSource *retry_page_flips_source;
-
- GList *postponed_page_flip_datas;
- GList *postponed_mode_set_fallback_datas;
-
- GList *posted_page_flip_datas;
-
- GHashTable *cached_mode_sets;
-};
-
-static GInitableIface *initable_parent_iface;
-
-static void
-initable_iface_init (GInitableIface *iface);
-
-G_DEFINE_TYPE_WITH_CODE (MetaKmsImplDeviceSimple, meta_kms_impl_device_simple,
- META_TYPE_KMS_IMPL_DEVICE,
- G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE,
- initable_iface_init))
-
-static void
-flush_postponed_page_flip_datas (MetaKmsImplDeviceSimple *impl_device_simple);
-
-static gboolean
-get_connector_property (MetaKmsImplDevice *impl_device,
- MetaKmsConnector *connector,
- MetaKmsConnectorProp prop,
- uint64_t *value,
- GError **error)
-{
- uint32_t prop_id;
- int fd;
- drmModeConnector *drm_connector;
- int i;
- gboolean found;
-
- prop_id = meta_kms_connector_get_prop_id (connector, prop);
- if (!prop_id)
- {
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
- "Property (%s) not found on connector %u",
- meta_kms_connector_get_prop_name (connector, prop),
- meta_kms_connector_get_id (connector));
- return FALSE;
- }
-
- fd = meta_kms_impl_device_get_fd (impl_device);
-
- drm_connector = drmModeGetConnector (fd,
- meta_kms_connector_get_id (connector));
- if (!drm_connector)
- {
- g_set_error (error, G_IO_ERROR, g_io_error_from_errno (errno),
- "Failed to get connector %u resources: %s",
- meta_kms_connector_get_id (connector),
- g_strerror (errno));
- return FALSE;
- }
-
- found = FALSE;
- for (i = 0; i < drm_connector->count_props; i++)
- {
- if (drm_connector->props[i] == prop_id)
- {
- *value = drm_connector->prop_values[i];
- found = TRUE;
- break;
- }
- }
-
- drmModeFreeConnector (drm_connector);
-
- if (!found)
- {
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND,
- "Connector property %u not found", prop_id);
- return FALSE;
- }
-
- return TRUE;
-}
-
-static gboolean
-set_connector_property (MetaKmsImplDevice *impl_device,
- MetaKmsConnector *connector,
- MetaKmsConnectorProp prop,
- uint64_t value,
- GError **error)
-{
- uint32_t prop_id;
- int fd;
- int ret;
-
- prop_id = meta_kms_connector_get_prop_id (connector, prop);
- if (!prop_id)
- {
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
- "Property (%s) not found on connector %u",
- meta_kms_connector_get_prop_name (connector, prop),
- meta_kms_connector_get_id (connector));
- return FALSE;
- }
-
- fd = meta_kms_impl_device_get_fd (impl_device);
-
- ret = drmModeObjectSetProperty (fd,
- meta_kms_connector_get_id (connector),
- DRM_MODE_OBJECT_CONNECTOR,
- prop_id,
- value);
- if (ret != 0)
- {
- g_set_error (error, G_IO_ERROR, g_io_error_from_errno (-ret),
- "Failed to set connector %u property %u: %s",
- meta_kms_connector_get_id (connector),
- prop_id,
- g_strerror (-ret));
- return FALSE;
- }
-
- return TRUE;
-}
-
-static gboolean
-process_power_save (MetaKmsImplDevice *impl_device,
- GError **error)
-{
- GList *l;
-
- for (l = meta_kms_impl_device_peek_connectors (impl_device); l; l = l->next)
- {
- MetaKmsConnector *connector = l->data;
-
- meta_topic (META_DEBUG_KMS,
- "[simple] Setting DPMS of connector %u (%s) to OFF",
- meta_kms_connector_get_id (connector),
- meta_kms_impl_device_get_path (impl_device));
-
- if (!set_connector_property (impl_device,
- connector,
- META_KMS_CONNECTOR_PROP_DPMS,
- DRM_MODE_DPMS_OFF,
- error))
- return FALSE;
- }
-
- return TRUE;
-}
-
-static gboolean
-process_connector_update (MetaKmsImplDevice *impl_device,
- MetaKmsUpdate *update,
- gpointer update_entry,
- GError **error)
-{
- MetaKmsConnectorUpdate *connector_update = update_entry;
- MetaKmsConnector *connector = connector_update->connector;
-
- if (connector_update->underscanning.has_update &&
- connector_update->underscanning.is_active)
- {
- meta_topic (META_DEBUG_KMS,
- "[simple] Setting underscanning on connector %u (%s) to "
- "%" G_GUINT64_FORMAT "x%" G_GUINT64_FORMAT,
- meta_kms_connector_get_id (connector),
- meta_kms_impl_device_get_path (impl_device),
- connector_update->underscanning.hborder,
- connector_update->underscanning.vborder);
-
- if (!set_connector_property (impl_device,
- connector,
- META_KMS_CONNECTOR_PROP_UNDERSCAN,
- 1,
- error))
- return FALSE;
- if (!set_connector_property (impl_device,
- connector,
- META_KMS_CONNECTOR_PROP_UNDERSCAN_HBORDER,
- connector_update->underscanning.hborder,
- error))
- return FALSE;
- if (!set_connector_property (impl_device,
- connector,
- META_KMS_CONNECTOR_PROP_UNDERSCAN_VBORDER,
- connector_update->underscanning.vborder,
- error))
- return FALSE;
- }
- else if (connector_update->underscanning.has_update)
- {
- meta_topic (META_DEBUG_KMS,
- "[simple] Unsetting underscanning on connector %u (%s)",
- meta_kms_connector_get_id (connector),
- meta_kms_impl_device_get_path (impl_device));
-
- if (!set_connector_property (impl_device,
- connector,
- META_KMS_CONNECTOR_PROP_UNDERSCAN,
- 0,
- error))
- return FALSE;
- }
-
- return TRUE;
-}
-
-static CachedModeSet *
-cached_mode_set_new (GList *connectors,
- const drmModeModeInfo *drm_mode)
-{
- CachedModeSet *cached_mode_set;
-
- cached_mode_set = g_new0 (CachedModeSet, 1);
- *cached_mode_set = (CachedModeSet) {
- .connectors = g_list_copy (connectors),
- .drm_mode = g_memdup2 (drm_mode, sizeof *drm_mode),
- };
-
- return cached_mode_set;
-}
-
-static void
-cached_mode_set_free (CachedModeSet *cached_mode_set)
-{
- g_list_free (cached_mode_set->connectors);
- g_free (cached_mode_set->drm_mode);
- g_free (cached_mode_set);
-}
-
-static void
-fill_connector_ids_array (GList *connectors,
- uint32_t **out_connectors,
- int *out_n_connectors)
-{
- GList *l;
- int i;
-
- *out_n_connectors = g_list_length (connectors);
- *out_connectors = g_new0 (uint32_t, *out_n_connectors);
- i = 0;
- for (l = connectors; l; l = l->next)
- {
- MetaKmsConnector *connector = l->data;
-
- (*out_connectors)[i++] = meta_kms_connector_get_id (connector);
- }
-}
-
-static gboolean
-set_plane_rotation (MetaKmsImplDevice *impl_device,
- MetaKmsPlane *plane,
- uint64_t rotation,
- GError **error)
-{
- int fd;
- uint32_t rotation_prop_id;
- int ret;
-
- fd = meta_kms_impl_device_get_fd (impl_device);
-
- rotation_prop_id = meta_kms_plane_get_prop_id (plane,
- META_KMS_PLANE_PROP_ROTATION);
-
- meta_topic (META_DEBUG_KMS,
- "[simple] Setting plane %u (%s) rotation to %" G_GUINT64_FORMAT,
- meta_kms_plane_get_id (plane),
- meta_kms_impl_device_get_path (impl_device),
- rotation);
-
- ret = drmModeObjectSetProperty (fd,
- meta_kms_plane_get_id (plane),
- DRM_MODE_OBJECT_PLANE,
- rotation_prop_id,
- rotation);
- if (ret != 0)
- {
- g_set_error (error, G_IO_ERROR, g_io_error_from_errno (-ret),
- "Failed to rotation property (%u) to %" G_GUINT64_FORMAT
- " on plane %u: %s",
- rotation_prop_id,
- rotation,
- meta_kms_plane_get_id (plane),
- g_strerror (-ret));
- return FALSE;
- }
-
- return TRUE;
-}
-
-static gboolean
-process_mode_set (MetaKmsImplDevice *impl_device,
- MetaKmsUpdate *update,
- gpointer update_entry,
- GError **error)
-{
- MetaKmsImplDeviceSimple *impl_device_simple =
- META_KMS_IMPL_DEVICE_SIMPLE (impl_device);
- MetaKmsModeSet *mode_set = update_entry;
- MetaKmsCrtc *crtc = mode_set->crtc;
- g_autofree uint32_t *connectors = NULL;
- int n_connectors;
- MetaKmsPlaneAssignment *plane_assignment;
- drmModeModeInfo *drm_mode;
- uint32_t x, y;
- uint32_t fb_id;
- int fd;
- int ret;
-
- crtc = mode_set->crtc;
-
- if (mode_set->mode)
- {
- MetaDrmBuffer *buffer;
- GList *l;
-
- drm_mode = g_alloca (sizeof *drm_mode);
- *drm_mode = *meta_kms_mode_get_drm_mode (mode_set->mode);
-
- fill_connector_ids_array (mode_set->connectors,
- &connectors,
- &n_connectors);
-
- plane_assignment = meta_kms_update_get_primary_plane_assignment (update,
- crtc);
- if (!plane_assignment)
- {
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- "Missing primary plane assignment for legacy mode set on CRTC %u",
- meta_kms_crtc_get_id (crtc));
- return FALSE;
- }
-
- x = meta_fixed_16_to_int (plane_assignment->src_rect.x);
- y = meta_fixed_16_to_int (plane_assignment->src_rect.y);
-
- if (plane_assignment->rotation)
- {
- if (!set_plane_rotation (impl_device,
- plane_assignment->plane,
- plane_assignment->rotation,
- error))
- return FALSE;
- }
-
- buffer = plane_assignment->buffer;
- fb_id = meta_drm_buffer_get_fb_id (buffer);
-
- for (l = mode_set->connectors; l; l = l->next)
- {
- MetaKmsConnector *connector = l->data;
- uint64_t dpms_value;
-
- if (!get_connector_property (impl_device,
- connector,
- META_KMS_CONNECTOR_PROP_DPMS,
- &dpms_value,
- error))
- return FALSE;
-
- if (dpms_value != DRM_MODE_DPMS_ON)
- {
- meta_topic (META_DEBUG_KMS,
- "[simple] Setting DPMS of connector %u (%s) to ON",
- meta_kms_connector_get_id (connector),
- meta_kms_impl_device_get_path (impl_device));
-
- if (!set_connector_property (impl_device,
- connector,
- META_KMS_CONNECTOR_PROP_DPMS,
- DRM_MODE_DPMS_ON,
- error))
- return FALSE;
- }
- }
-
- meta_topic (META_DEBUG_KMS,
- "[simple] Setting mode of CRTC %u (%s) to %s",
- meta_kms_crtc_get_id (crtc),
- meta_kms_impl_device_get_path (impl_device),
- drm_mode->name);
- }
- else
- {
- drm_mode = NULL;
- x = y = 0;
- n_connectors = 0;
- connectors = NULL;
- fb_id = 0;
-
- meta_topic (META_DEBUG_KMS,
- "[simple] Unsetting mode of CRTC %u (%s)",
- meta_kms_crtc_get_id (crtc),
- meta_kms_impl_device_get_path (impl_device));
- }
-
- fd = meta_kms_impl_device_get_fd (impl_device);
- ret = drmModeSetCrtc (fd,
- meta_kms_crtc_get_id (crtc),
- fb_id,
- x, y,
- connectors, n_connectors,
- drm_mode);
- if (ret != 0)
- {
- g_set_error (error, G_IO_ERROR, g_io_error_from_errno (-ret),
- "Failed to set mode %s on CRTC %u: %s",
- drm_mode ? drm_mode->name : "off",
- meta_kms_crtc_get_id (crtc),
- g_strerror (-ret));
- return FALSE;
- }
-
- if (drm_mode)
- {
- g_hash_table_replace (impl_device_simple->cached_mode_sets,
- crtc,
- cached_mode_set_new (mode_set->connectors,
- drm_mode));
- }
- else
- {
- g_hash_table_remove (impl_device_simple->cached_mode_sets, crtc);
- }
-
- return TRUE;
-}
-
-static gboolean
-process_crtc_gamma (MetaKmsImplDevice *impl_device,
- MetaKmsUpdate *update,
- gpointer update_entry,
- GError **error)
-{
- MetaKmsCrtcGamma *gamma = update_entry;
- MetaKmsCrtc *crtc = gamma->crtc;
- int fd;
- int ret;
-
- meta_topic (META_DEBUG_KMS,
- "[simple] Setting CRTC %u (%s) gamma, size: %d",
- meta_kms_crtc_get_id (crtc),
- meta_kms_impl_device_get_path (impl_device),
- gamma->size);
-
- fd = meta_kms_impl_device_get_fd (impl_device);
- ret = drmModeCrtcSetGamma (fd, meta_kms_crtc_get_id (crtc),
- gamma->size,
- gamma->red,
- gamma->green,
- gamma->blue);
- if (ret != 0)
- {
- g_set_error (error, G_IO_ERROR, g_io_error_from_errno (-ret),
- "drmModeCrtcSetGamma on CRTC %u failed: %s",
- meta_kms_crtc_get_id (crtc),
- g_strerror (-ret));
- return FALSE;
- }
-
- return TRUE;
-}
-
-static gboolean
-is_timestamp_earlier_than (uint64_t ts1,
- uint64_t ts2)
-{
- if (ts1 == ts2)
- return FALSE;
- else
- return ts2 - ts1 < UINT64_MAX / 2;
-}
-
-typedef struct _RetryPageFlipData
-{
- MetaKmsCrtc *crtc;
- uint32_t fb_id;
- MetaKmsPageFlipData *page_flip_data;
- float refresh_rate;
- uint64_t retry_time_us;
- MetaKmsCustomPageFlip *custom_page_flip;
-} RetryPageFlipData;
-
-static void
-retry_page_flip_data_free (RetryPageFlipData *retry_page_flip_data)
-{
- g_assert (!retry_page_flip_data->page_flip_data);
- g_clear_pointer (&retry_page_flip_data->custom_page_flip,
- meta_kms_custom_page_flip_free);
- g_free (retry_page_flip_data);
-}
-
-static CachedModeSet *
-get_cached_mode_set (MetaKmsImplDeviceSimple *impl_device_simple,
- MetaKmsCrtc *crtc)
-{
- return g_hash_table_lookup (impl_device_simple->cached_mode_sets, crtc);
-}
-
-static float
-get_cached_crtc_refresh_rate (MetaKmsImplDeviceSimple *impl_device_simple,
- MetaKmsCrtc *crtc)
-{
- CachedModeSet *cached_mode_set;
-
- cached_mode_set = g_hash_table_lookup (impl_device_simple->cached_mode_sets,
- crtc);
- g_assert (cached_mode_set);
-
- return meta_calculate_drm_mode_refresh_rate (cached_mode_set->drm_mode);
-}
-
-#define meta_assert_in_kms_impl(kms) \
- g_assert (meta_kms_in_impl_task (kms))
-
-static gboolean
-retry_page_flips (gpointer user_data)
-{
- MetaKmsImplDeviceSimple *impl_device_simple =
- META_KMS_IMPL_DEVICE_SIMPLE (user_data);
- MetaKmsImplDevice *impl_device = META_KMS_IMPL_DEVICE (impl_device_simple);
- uint64_t now_us;
- GList *l;
-
- now_us = g_source_get_time (impl_device_simple->retry_page_flips_source);
-
- l = impl_device_simple->pending_page_flip_retries;
- while (l)
- {
- RetryPageFlipData *retry_page_flip_data = l->data;
- MetaKmsCrtc *crtc = retry_page_flip_data->crtc;
- GList *l_next = l->next;
- int fd;
- int ret;
- MetaKmsPageFlipData *page_flip_data;
- MetaKmsCustomPageFlip *custom_page_flip;
-
- if (is_timestamp_earlier_than (now_us,
- retry_page_flip_data->retry_time_us))
- {
- l = l_next;
- continue;
- }
-
- custom_page_flip = retry_page_flip_data->custom_page_flip;
- if (custom_page_flip)
- {
- meta_topic (META_DEBUG_KMS,
- "[simple] Retrying custom page flip on CRTC %u (%s)",
- meta_kms_crtc_get_id (crtc),
- meta_kms_impl_device_get_path (impl_device));
- ret = custom_page_flip->func (custom_page_flip->user_data,
- retry_page_flip_data->page_flip_data);
- }
- else
- {
- meta_topic (META_DEBUG_KMS,
- "[simple] Retrying page flip on CRTC %u (%s) with %u",
- meta_kms_crtc_get_id (crtc),
- meta_kms_impl_device_get_path (impl_device),
- retry_page_flip_data->fb_id);
-
- fd = meta_kms_impl_device_get_fd (impl_device);
- ret = drmModePageFlip (fd,
- meta_kms_crtc_get_id (crtc),
- retry_page_flip_data->fb_id,
- DRM_MODE_PAGE_FLIP_EVENT,
- retry_page_flip_data->page_flip_data);
- }
-
- if (ret == -EBUSY)
- {
- float refresh_rate;
-
- meta_topic (META_DEBUG_KMS,
- "[simple] Rescheduling page flip retry on CRTC %u (%s)",
- meta_kms_crtc_get_id (crtc),
- meta_kms_impl_device_get_path (impl_device));
-
- refresh_rate =
- get_cached_crtc_refresh_rate (impl_device_simple, crtc);
- retry_page_flip_data->retry_time_us +=
- (uint64_t) (G_USEC_PER_SEC / refresh_rate);
- l = l_next;
- continue;
- }
-
- impl_device_simple->pending_page_flip_retries =
- g_list_remove_link (impl_device_simple->pending_page_flip_retries, l);
-
- page_flip_data = g_steal_pointer (&retry_page_flip_data->page_flip_data);
- if (ret != 0)
- {
- g_autoptr (GError) error = NULL;
-
- g_set_error (&error, G_IO_ERROR, g_io_error_from_errno (-ret),
- "drmModePageFlip on CRTC %u failed: %s",
- meta_kms_crtc_get_id (crtc),
- g_strerror (-ret));
- if (!g_error_matches (error,
- G_IO_ERROR,
- G_IO_ERROR_PERMISSION_DENIED))
- g_critical ("Failed to page flip: %s", error->message);
-
- meta_kms_page_flip_data_discard_in_impl (page_flip_data, error);
- meta_kms_impl_device_unhold_fd (impl_device);
- }
- else
- {
- impl_device_simple->posted_page_flip_datas =
- g_list_prepend (impl_device_simple->posted_page_flip_datas,
- page_flip_data);
- }
-
- retry_page_flip_data_free (retry_page_flip_data);
-
- l = l_next;
- }
-
- if (impl_device_simple->pending_page_flip_retries)
- {
- GList *l;
- uint64_t earliest_retry_time_us = 0;
-
- for (l = impl_device_simple->pending_page_flip_retries; l; l = l->next)
- {
- RetryPageFlipData *retry_page_flip_data = l->data;
-
- if (l == impl_device_simple->pending_page_flip_retries ||
- is_timestamp_earlier_than (retry_page_flip_data->retry_time_us,
- earliest_retry_time_us))
- earliest_retry_time_us = retry_page_flip_data->retry_time_us;
- }
-
- g_source_set_ready_time (impl_device_simple->retry_page_flips_source,
- earliest_retry_time_us);
- return G_SOURCE_CONTINUE;
- }
- else
- {
- g_clear_pointer (&impl_device_simple->retry_page_flips_source,
- g_source_unref);
-
- flush_postponed_page_flip_datas (impl_device_simple);
-
- return G_SOURCE_REMOVE;
- }
-}
-
-static void
-schedule_retry_page_flip (MetaKmsImplDeviceSimple *impl_device_simple,
- MetaKmsCrtc *crtc,
- uint32_t fb_id,
- float refresh_rate,
- MetaKmsPageFlipData *page_flip_data,
- MetaKmsCustomPageFlip *custom_page_flip)
-{
- RetryPageFlipData *retry_page_flip_data;
- uint64_t now_us;
- uint64_t retry_time_us;
-
- now_us = g_get_monotonic_time ();
- retry_time_us = now_us + (uint64_t) (G_USEC_PER_SEC / refresh_rate);
-
- retry_page_flip_data = g_new0 (RetryPageFlipData, 1);
- *retry_page_flip_data = (RetryPageFlipData) {
- .crtc = crtc,
- .fb_id = fb_id,
- .page_flip_data = page_flip_data,
- .refresh_rate = refresh_rate,
- .retry_time_us = retry_time_us,
- .custom_page_flip = custom_page_flip,
- };
-
- if (!impl_device_simple->retry_page_flips_source)
- {
- MetaKmsImplDevice *impl_device =
- META_KMS_IMPL_DEVICE (impl_device_simple);
- MetaKmsDevice *device = meta_kms_impl_device_get_device (impl_device);
- MetaKms *kms = meta_kms_device_get_kms (device);
- GSource *source;
-
- source = meta_kms_add_source_in_impl (kms, retry_page_flips,
- impl_device_simple, NULL);
- g_source_set_ready_time (source, retry_time_us);
-
- impl_device_simple->retry_page_flips_source = source;
- }
- else
- {
- GList *l;
-
- for (l = impl_device_simple->pending_page_flip_retries; l; l = l->next)
- {
- RetryPageFlipData *pending_retry_page_flip_data = l->data;
- uint64_t pending_retry_time_us =
- pending_retry_page_flip_data->retry_time_us;
-
- if (is_timestamp_earlier_than (retry_time_us, pending_retry_time_us))
- {
- g_source_set_ready_time (impl_device_simple->retry_page_flips_source,
- retry_time_us);
- break;
- }
- }
- }
-
- impl_device_simple->pending_page_flip_retries =
- g_list_append (impl_device_simple->pending_page_flip_retries,
- retry_page_flip_data);
-}
-
-static void
-dispatch_page_flip_datas (GList **page_flip_datas,
- GFunc func,
- gpointer user_data)
-{
- g_list_foreach (*page_flip_datas, func, user_data);
- g_clear_pointer (page_flip_datas, g_list_free);
-}
-
-static gboolean
-mode_set_fallback_feedback_idle (gpointer user_data)
-{
- MetaKmsImplDeviceSimple *impl_device_simple = user_data;
-
- g_clear_pointer (&impl_device_simple->mode_set_fallback_feedback_source,
- g_source_unref);
-
- if (impl_device_simple->pending_page_flip_retries)
- {
- impl_device_simple->postponed_mode_set_fallback_datas =
- g_steal_pointer (&impl_device_simple->mode_set_fallback_page_flip_datas);
- }
- else
- {
- dispatch_page_flip_datas (&impl_device_simple->mode_set_fallback_page_flip_datas,
- (GFunc) meta_kms_page_flip_data_mode_set_fallback_in_impl,
- NULL);
- }
-
- return G_SOURCE_REMOVE;
-}
-
-static gboolean
-mode_set_fallback (MetaKmsImplDeviceSimple *impl_device_simple,
- MetaKmsUpdate *update,
- MetaKmsPlaneAssignment *plane_assignment,
- MetaKmsPageFlipData *page_flip_data,
- GError **error)
-{
- MetaKmsImplDevice *impl_device = META_KMS_IMPL_DEVICE (impl_device_simple);
- MetaKmsDevice *device = meta_kms_impl_device_get_device (impl_device);
- MetaKms *kms = meta_kms_device_get_kms (device);
- MetaKmsCrtc *crtc = meta_kms_page_flip_data_get_crtc (page_flip_data);
- CachedModeSet *cached_mode_set;
- g_autofree uint32_t *connectors = NULL;
- int n_connectors;
- uint32_t fb_id;
- uint32_t x, y;
- int fd;
- int ret;
-
- cached_mode_set = g_hash_table_lookup (impl_device_simple->cached_mode_sets,
- crtc);
- if (!cached_mode_set)
- {
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- "Missing mode set for page flip fallback");
- return FALSE;
- }
-
- fill_connector_ids_array (cached_mode_set->connectors,
- &connectors,
- &n_connectors);
-
- fb_id = meta_drm_buffer_get_fb_id (plane_assignment->buffer);
-
- x = meta_fixed_16_to_int (plane_assignment->src_rect.x);
- y = meta_fixed_16_to_int (plane_assignment->src_rect.y);
-
- fd = meta_kms_impl_device_get_fd (impl_device);
- ret = drmModeSetCrtc (fd,
- meta_kms_crtc_get_id (crtc),
- fb_id,
- x, y,
- connectors, n_connectors,
- cached_mode_set->drm_mode);
- if (ret != 0)
- {
- g_set_error (error, G_IO_ERROR, g_io_error_from_errno (-ret),
- "drmModeSetCrtc mode '%s' on CRTC %u failed: %s",
- cached_mode_set->drm_mode->name,
- meta_kms_crtc_get_id (crtc),
- g_strerror (-ret));
- return FALSE;
- }
-
- if (!impl_device_simple->mode_set_fallback_feedback_source)
- {
- GSource *source;
-
- source = meta_kms_add_source_in_impl (kms,
- mode_set_fallback_feedback_idle,
- impl_device_simple,
- NULL);
- impl_device_simple->mode_set_fallback_feedback_source = source;
- }
-
- impl_device_simple->mode_set_fallback_page_flip_datas =
- g_list_prepend (impl_device_simple->mode_set_fallback_page_flip_datas,
- page_flip_data);
-
- return TRUE;
-}
-
-static gboolean
-symbolic_page_flip_idle (gpointer user_data)
-{
- MetaKmsPageFlipData *page_flip_data = user_data;
- MetaKmsImplDevice *impl_device;
- MetaKmsCrtc *crtc;
-
- impl_device = meta_kms_page_flip_data_get_impl_device (page_flip_data);
- crtc = meta_kms_page_flip_data_get_crtc (page_flip_data);
-
- meta_topic (META_DEBUG_KMS,
- "[simple] Handling symbolic page flip callback from %s, data: %p, CRTC: %u",
- meta_kms_impl_device_get_path (impl_device),
- page_flip_data,
- meta_kms_crtc_get_id (crtc));
-
- meta_kms_impl_device_handle_page_flip_callback (impl_device, page_flip_data);
-
- return G_SOURCE_REMOVE;
-}
-
-static gboolean
-dispatch_page_flip (MetaKmsImplDevice *impl_device,
- MetaKmsUpdate *update,
- MetaKmsPageFlipData *page_flip_data,
- GError **error)
-{
- MetaKmsImplDeviceSimple *impl_device_simple =
- META_KMS_IMPL_DEVICE_SIMPLE (impl_device);
- MetaKmsCrtc *crtc;
- MetaKmsPlaneAssignment *plane_assignment;
- g_autoptr (MetaKmsCustomPageFlip) custom_page_flip = NULL;
- int fd;
- int ret;
-
- crtc = meta_kms_page_flip_data_get_crtc (page_flip_data);
- plane_assignment = meta_kms_update_get_primary_plane_assignment (update,
- crtc);
-
- custom_page_flip = meta_kms_update_take_custom_page_flip_func (update);
-
- if (!plane_assignment && !custom_page_flip)
- {
- MetaKmsDevice *device = meta_kms_impl_device_get_device (impl_device);
- MetaKms *kms = meta_kms_device_get_kms (device);
- GSource *source;
-
- meta_kms_page_flip_data_make_symbolic (page_flip_data);
-
- source = meta_kms_add_source_in_impl (kms,
- symbolic_page_flip_idle,
- page_flip_data,
- NULL);
-
- g_source_set_ready_time (source, 0);
- g_source_unref (source);
-
- return TRUE;
- }
-
- fd = meta_kms_impl_device_get_fd (impl_device);
- if (custom_page_flip)
- {
- meta_topic (META_DEBUG_KMS,
- "[simple] Invoking custom page flip on CRTC %u (%s)",
- meta_kms_crtc_get_id (crtc),
- meta_kms_impl_device_get_path (impl_device));
- ret = custom_page_flip->func (custom_page_flip->user_data,
- page_flip_data);
- }
- else
- {
- uint32_t fb_id;
-
- fb_id = meta_drm_buffer_get_fb_id (plane_assignment->buffer);
-
- meta_topic (META_DEBUG_KMS,
- "[simple] Page flipping CRTC %u (%s) with %u, data: %p",
- meta_kms_crtc_get_id (crtc),
- meta_kms_impl_device_get_path (impl_device),
- fb_id,
- page_flip_data);
-
- ret = drmModePageFlip (fd,
- meta_kms_crtc_get_id (crtc),
- fb_id,
- DRM_MODE_PAGE_FLIP_EVENT,
- page_flip_data);
- }
-
- if (ret == -EBUSY)
- {
- CachedModeSet *cached_mode_set;
-
- meta_topic (META_DEBUG_KMS,
- "[simple] Scheduling page flip retry on CRTC %u (%s)",
- meta_kms_crtc_get_id (crtc),
- meta_kms_impl_device_get_path (impl_device));
-
- cached_mode_set = get_cached_mode_set (impl_device_simple, crtc);
- if (cached_mode_set)
- {
- uint32_t fb_id;
- drmModeModeInfo *drm_mode;
- float refresh_rate;
-
- if (plane_assignment)
- fb_id = meta_drm_buffer_get_fb_id (plane_assignment->buffer);
- else
- fb_id = 0;
- drm_mode = cached_mode_set->drm_mode;
- refresh_rate = meta_calculate_drm_mode_refresh_rate (drm_mode);
- meta_kms_impl_device_hold_fd (impl_device);
- schedule_retry_page_flip (impl_device_simple,
- crtc,
- fb_id,
- refresh_rate,
- page_flip_data,
- g_steal_pointer (&custom_page_flip));
- return TRUE;
- }
- else
- {
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- "Page flip of %u failed, and no mode set available",
- meta_kms_crtc_get_id (crtc));
- return FALSE;
- }
- }
- else if (ret == -EINVAL)
- {
- meta_topic (META_DEBUG_KMS,
- "[simple] Falling back to mode set on CRTC %u (%s)",
- meta_kms_crtc_get_id (crtc),
- meta_kms_impl_device_get_path (impl_device));
-
- return mode_set_fallback (impl_device_simple,
- update,
- plane_assignment,
- page_flip_data,
- error);
- }
- else if (ret != 0)
- {
- g_set_error (error, G_IO_ERROR, g_io_error_from_errno (-ret),
- "drmModePageFlip on CRTC %u failed: %s",
- meta_kms_crtc_get_id (crtc),
- g_strerror (-ret));
- return FALSE;
- }
- else
- {
- meta_kms_impl_device_hold_fd (impl_device);
-
- impl_device_simple->posted_page_flip_datas =
- g_list_prepend (impl_device_simple->posted_page_flip_datas,
- page_flip_data);
-
- return TRUE;
- }
-}
-
-static GList *
-generate_page_flip_datas (MetaKmsImplDevice *impl_device,
- MetaKmsUpdate *update)
-{
- GList *listeners;
- GList *page_flip_datas = NULL;
-
- listeners = g_list_copy (meta_kms_update_get_page_flip_listeners (update));
-
- while (listeners)
- {
- MetaKmsPageFlipListener *listener = listeners->data;
- MetaKmsCrtc *crtc = listener->crtc;
- MetaKmsPageFlipData *page_flip_data;
- gpointer user_data;
- GDestroyNotify destroy_notify;
- GList *l;
-
- page_flip_data = meta_kms_page_flip_data_new (impl_device, crtc);
- page_flip_datas = g_list_append (page_flip_datas, page_flip_data);
-
- user_data = g_steal_pointer (&listener->user_data);
- destroy_notify = g_steal_pointer (&listener->destroy_notify);
- meta_kms_page_flip_data_add_listener (page_flip_data,
- listener->vtable,
- listener->flags,
- user_data,
- destroy_notify);
-
- listeners = g_list_delete_link (listeners, listeners);
-
- l = listeners;
- while (l)
- {
- MetaKmsPageFlipListener *other_listener = l->data;
- GList *l_next = l->next;
-
- if (other_listener->crtc == crtc)
- {
- gpointer other_user_data;
- GDestroyNotify other_destroy_notify;
-
- other_user_data = g_steal_pointer (&other_listener->user_data);
- other_destroy_notify =
- g_steal_pointer (&other_listener->destroy_notify);
- meta_kms_page_flip_data_add_listener (page_flip_data,
- other_listener->vtable,
- other_listener->flags,
- other_user_data,
- other_destroy_notify);
- listeners = g_list_delete_link (listeners, l);
- }
-
- l = l_next;
- }
- }
-
- return page_flip_datas;
-}
-
-static gboolean
-maybe_dispatch_page_flips (MetaKmsImplDevice *impl_device,
- MetaKmsUpdate *update,
- GList **failed_planes,
- MetaKmsUpdateFlag flags,
- GError **error)
-{
- g_autoptr (GList) page_flip_datas = NULL;
- GList *l;
-
- page_flip_datas = generate_page_flip_datas (impl_device, update);
-
- while (page_flip_datas)
- {
- g_autoptr (GList) l = NULL;
- MetaKmsPageFlipData *page_flip_data;
-
- l = page_flip_datas;
- page_flip_datas = g_list_remove_link (page_flip_datas, l);
- page_flip_data = g_steal_pointer (&l->data);
-
- if (!dispatch_page_flip (impl_device, update, page_flip_data, error))
- {
- if (!g_error_matches (*error,
- G_IO_ERROR,
- G_IO_ERROR_PERMISSION_DENIED))
- {
- MetaKmsCrtc *crtc =
- meta_kms_page_flip_data_get_crtc (page_flip_data);
- MetaKmsPlaneAssignment *plane_assignment;
- MetaKmsPlaneFeedback *plane_feedback;
-
- plane_assignment =
- meta_kms_update_get_primary_plane_assignment (update, crtc);
-
- plane_feedback =
- meta_kms_plane_feedback_new_take_error (plane_assignment->plane,
- plane_assignment->crtc,
- g_error_copy (*error));
- *failed_planes = g_list_prepend (*failed_planes, plane_feedback);
- }
-
- if (!(flags & META_KMS_UPDATE_FLAG_PRESERVE_ON_ERROR))
- meta_kms_page_flip_data_discard_in_impl (page_flip_data, *error);
-
- goto err;
- }
- }
-
- return TRUE;
-
-err:
- if (!(flags & META_KMS_UPDATE_FLAG_PRESERVE_ON_ERROR))
- {
- for (l = page_flip_datas; l; l = l->next)
- {
- MetaKmsPageFlipData *page_flip_data = l->data;
-
- meta_kms_page_flip_data_discard_in_impl (page_flip_data, *error);
- }
- }
- g_list_free (page_flip_datas);
-
- return FALSE;
-}
-
-static gboolean
-process_entries (MetaKmsImplDevice *impl_device,
- MetaKmsUpdate *update,
- GList *entries,
- MetaKmsSimpleProcessFunc func,
- GError **error)
-{
- GList *l;
-
- for (l = entries; l; l = l->next)
- {
- if (!func (impl_device, update, l->data, error))
- return FALSE;
- }
-
- return TRUE;
-}
-
-static gboolean
-process_cursor_plane_assignment (MetaKmsImplDevice *impl_device,
- MetaKmsUpdate *update,
- MetaKmsPlaneAssignment *plane_assignment,
- GError **error)
-{
- uint32_t crtc_id;
- int fd;
-
- crtc_id = meta_kms_crtc_get_id (plane_assignment->crtc),
- fd = meta_kms_impl_device_get_fd (impl_device);
-
- if (!(plane_assignment->flags & META_KMS_ASSIGN_PLANE_FLAG_FB_UNCHANGED))
- {
- int width, height;
- int ret = -1;
- uint32_t handle_u32;
-
- width = plane_assignment->dst_rect.width;
- height = plane_assignment->dst_rect.height;
-
- if (plane_assignment->buffer)
- {
- MetaDrmBufferGbm *buffer_gbm =
- META_DRM_BUFFER_GBM (plane_assignment->buffer);
- struct gbm_bo *bo;
- union gbm_bo_handle handle;
-
- bo = meta_drm_buffer_gbm_get_bo (buffer_gbm);
- handle = gbm_bo_get_handle (bo);
- handle_u32 = handle.u32;
- }
- else
- {
- handle_u32 = 0;
- }
-
- meta_topic (META_DEBUG_KMS,
- "[simple] Setting HW cursor of CRTC %u (%s) to %u "
- "(size: %dx%d, hot: (%d, %d))",
- crtc_id,
- meta_kms_impl_device_get_path (impl_device),
- handle_u32,
- width, height,
- plane_assignment->cursor_hotspot.x,
- plane_assignment->cursor_hotspot.y);
-
- if (plane_assignment->cursor_hotspot.is_valid)
- {
- ret = drmModeSetCursor2 (fd,
- crtc_id,
- handle_u32,
- width, height,
- plane_assignment->cursor_hotspot.x,
- plane_assignment->cursor_hotspot.y);
- }
-
- if (ret != 0)
- {
- ret = drmModeSetCursor (fd, crtc_id,
- handle_u32,
- width, height);
- }
-
- if (ret != 0)
- {
- g_set_error (error, G_IO_ERROR, g_io_error_from_errno (-ret),
- "drmModeSetCursor failed: %s", g_strerror (-ret));
- return FALSE;
- }
- }
-
- meta_topic (META_DEBUG_KMS,
- "[simple] Moving HW cursor of CRTC %u (%s) to (%d, %d)",
- crtc_id,
- meta_kms_impl_device_get_path (impl_device),
- plane_assignment->dst_rect.x,
- plane_assignment->dst_rect.y);
-
- drmModeMoveCursor (fd,
- crtc_id,
- plane_assignment->dst_rect.x,
- plane_assignment->dst_rect.y);
-
- return TRUE;
-}
-
-static gboolean
-process_plane_assignment (MetaKmsImplDevice *impl_device,
- MetaKmsUpdate *update,
- MetaKmsPlaneAssignment *plane_assignment,
- MetaKmsPlaneFeedback **plane_feedback)
-{
- MetaKmsPlane *plane;
- MetaKmsPlaneType plane_type;
- GError *error = NULL;
-
- plane = plane_assignment->plane;
- plane_type = meta_kms_plane_get_plane_type (plane);
- switch (plane_type)
- {
- case META_KMS_PLANE_TYPE_PRIMARY:
- /* Handled as part of the mode-set and page flip. */
- return TRUE;
- case META_KMS_PLANE_TYPE_CURSOR:
- if (!process_cursor_plane_assignment (impl_device, update,
- plane_assignment,
- &error))
- {
- *plane_feedback =
- meta_kms_plane_feedback_new_take_error (plane,
- plane_assignment->crtc,
- g_steal_pointer (&error));
- return FALSE;
- }
- else
- {
- return TRUE;
- }
- case META_KMS_PLANE_TYPE_OVERLAY:
- error = g_error_new_literal (G_IO_ERROR, G_IO_ERROR_FAILED,
- "Overlay planes cannot be assigned");
- *plane_feedback =
- meta_kms_plane_feedback_new_take_error (plane,
- plane_assignment->crtc,
- g_steal_pointer (&error));
- return TRUE;
- }
-
- g_assert_not_reached ();
-}
-
-static gboolean
-process_plane_assignments (MetaKmsImplDevice *impl_device,
- MetaKmsUpdate *update,
- GList **failed_planes,
- GError **error)
-{
- GList *l;
-
- for (l = meta_kms_update_get_plane_assignments (update); l; l = l->next)
- {
- MetaKmsPlaneAssignment *plane_assignment = l->data;
- MetaKmsPlaneFeedback *plane_feedback;
-
- if (!process_plane_assignment (impl_device, update, plane_assignment,
- &plane_feedback))
- {
- if (g_error_matches (plane_feedback->error,
- G_IO_ERROR,
- G_IO_ERROR_PERMISSION_DENIED))
- {
- g_propagate_error (error,
- g_steal_pointer (&plane_feedback->error));
- meta_kms_plane_feedback_free (plane_feedback);
- return FALSE;
- }
-
- *failed_planes = g_list_prepend (*failed_planes, plane_feedback);
- if (plane_assignment->flags & META_KMS_ASSIGN_PLANE_FLAG_ALLOW_FAIL)
- {
- continue;
- }
- else
- {
- g_propagate_error (error, g_error_copy (plane_feedback->error));
- return FALSE;
- }
- }
- }
-
- return TRUE;
-}
-
-static void
-page_flip_handler (int fd,
- unsigned int sequence,
- unsigned int tv_sec,
- unsigned int tv_usec,
- void *user_data)
-{
- MetaKmsPageFlipData *page_flip_data = user_data;
- MetaKmsImplDevice *impl_device;
- MetaKmsImplDeviceSimple *impl_device_simple;
- MetaKmsCrtc *crtc;
-
- meta_kms_page_flip_data_set_timings_in_impl (page_flip_data,
- sequence, tv_sec, tv_usec);
-
- impl_device = meta_kms_page_flip_data_get_impl_device (page_flip_data);
- impl_device_simple = META_KMS_IMPL_DEVICE_SIMPLE (impl_device);
- crtc = meta_kms_page_flip_data_get_crtc (page_flip_data);
-
- meta_topic (META_DEBUG_KMS,
- "[simple] Handling page flip callback from %s, data: %p, CRTC: %u",
- meta_kms_impl_device_get_path (impl_device),
- page_flip_data,
- meta_kms_crtc_get_id (crtc));
-
- meta_kms_impl_device_unhold_fd (impl_device);
-
- meta_kms_impl_device_handle_page_flip_callback (impl_device, page_flip_data);
- impl_device_simple->posted_page_flip_datas =
- g_list_remove (impl_device_simple->posted_page_flip_datas,
- page_flip_data);
-}
-
-static void
-meta_kms_impl_device_simple_setup_drm_event_context (MetaKmsImplDevice *impl_device,
- drmEventContext *drm_event_context)
-{
- drm_event_context->version = 2;
- drm_event_context->page_flip_handler = page_flip_handler;
-}
-
-static MetaKmsFeedback *
-meta_kms_impl_device_simple_process_update (MetaKmsImplDevice *impl_device,
- MetaKmsUpdate *update,
- MetaKmsUpdateFlag flags)
-{
- GError *error = NULL;
- GList *failed_planes = NULL;
-
- meta_topic (META_DEBUG_KMS,
- "[simple] Processing update %" G_GUINT64_FORMAT,
- meta_kms_update_get_sequence_number (update));
-
- if (meta_kms_update_is_power_save (update))
- {
- if (!process_power_save (impl_device, &error))
- goto err;
- goto out;
- }
-
- if (!process_entries (impl_device,
- update,
- meta_kms_update_get_mode_sets (update),
- process_mode_set,
- &error))
- goto err;
-
- if (!process_entries (impl_device,
- update,
- meta_kms_update_get_connector_updates (update),
- process_connector_update,
- &error))
- goto err;
-
- if (!process_entries (impl_device,
- update,
- meta_kms_update_get_crtc_gammas (update),
- process_crtc_gamma,
- &error))
- goto err;
-
- if (!process_plane_assignments (impl_device, update, &failed_planes, &error))
- goto err;
-
- if (!maybe_dispatch_page_flips (impl_device, update, &failed_planes, flags,
- &error))
- goto err;
-
-out:
- return meta_kms_feedback_new_passed (failed_planes);
-
-err:
- return meta_kms_feedback_new_failed (failed_planes, error);
-}
-
-static void
-flush_postponed_page_flip_datas (MetaKmsImplDeviceSimple *impl_device_simple)
-{
- dispatch_page_flip_datas (&impl_device_simple->postponed_page_flip_datas,
- (GFunc) meta_kms_page_flip_data_flipped_in_impl,
- NULL);
- dispatch_page_flip_datas (&impl_device_simple->postponed_mode_set_fallback_datas,
- (GFunc) meta_kms_page_flip_data_mode_set_fallback_in_impl,
- NULL);
-}
-
-static void
-meta_kms_impl_device_simple_handle_page_flip_callback (MetaKmsImplDevice *impl_device,
- MetaKmsPageFlipData *page_flip_data)
-{
- MetaKmsImplDeviceSimple *impl_device_simple =
- META_KMS_IMPL_DEVICE_SIMPLE (impl_device);
-
- if (impl_device_simple->pending_page_flip_retries)
- {
- impl_device_simple->postponed_page_flip_datas =
- g_list_append (impl_device_simple->postponed_page_flip_datas,
- page_flip_data);
- }
- else
- {
- meta_kms_page_flip_data_flipped_in_impl (page_flip_data);
- }
-}
-
-static void
-dispose_page_flip_data (MetaKmsPageFlipData *page_flip_data,
- MetaKmsImplDevice *impl_device)
-{
- meta_kms_page_flip_data_discard_in_impl (page_flip_data, NULL);
- meta_kms_impl_device_unhold_fd (impl_device);
-}
-
-static void
-meta_kms_impl_device_simple_discard_pending_page_flips (MetaKmsImplDevice *impl_device)
-{
- MetaKmsImplDeviceSimple *impl_device_simple =
- META_KMS_IMPL_DEVICE_SIMPLE (impl_device);
- GList *l;
-
- if (!impl_device_simple->pending_page_flip_retries)
- return;
-
- for (l = impl_device_simple->pending_page_flip_retries; l; l = l->next)
- {
- RetryPageFlipData *retry_page_flip_data = l->data;
- MetaKmsPageFlipData *page_flip_data;
-
- page_flip_data = g_steal_pointer (&retry_page_flip_data->page_flip_data);
-
- meta_topic (META_DEBUG_KMS,
- "[simple] Discarding page flip retry for CRTC %u (%s)",
- meta_kms_crtc_get_id (
- meta_kms_page_flip_data_get_crtc (page_flip_data)),
- meta_kms_impl_device_get_path (
- meta_kms_page_flip_data_get_impl_device (page_flip_data)));
-
- dispose_page_flip_data (page_flip_data, impl_device);
- retry_page_flip_data_free (retry_page_flip_data);
- }
- g_clear_pointer (&impl_device_simple->pending_page_flip_retries, g_list_free);
-
- g_clear_pointer (&impl_device_simple->retry_page_flips_source,
- g_source_destroy);
-}
-
-static void
-meta_kms_impl_device_simple_prepare_shutdown (MetaKmsImplDevice *impl_device)
-{
- MetaKmsImplDeviceSimple *impl_device_simple =
- META_KMS_IMPL_DEVICE_SIMPLE (impl_device);
-
- g_list_foreach (impl_device_simple->posted_page_flip_datas,
- (GFunc) dispose_page_flip_data,
- impl_device);
- g_clear_list (&impl_device_simple->posted_page_flip_datas, NULL);
-}
-
-static void
-meta_kms_impl_device_simple_finalize (GObject *object)
-{
- MetaKmsImplDeviceSimple *impl_device_simple =
- META_KMS_IMPL_DEVICE_SIMPLE (object);
- MetaKmsImplDevice *impl_device = META_KMS_IMPL_DEVICE (impl_device_simple);
-
- g_list_free_full (impl_device_simple->pending_page_flip_retries,
- (GDestroyNotify) retry_page_flip_data_free);
- dispatch_page_flip_datas (&impl_device_simple->postponed_page_flip_datas,
- (GFunc) dispose_page_flip_data,
- impl_device);
- dispatch_page_flip_datas (&impl_device_simple->postponed_mode_set_fallback_datas,
- (GFunc) dispose_page_flip_data,
- impl_device);
-
- g_assert (!impl_device_simple->posted_page_flip_datas);
-
- g_clear_pointer (&impl_device_simple->mode_set_fallback_feedback_source,
- g_source_destroy);
- g_hash_table_destroy (impl_device_simple->cached_mode_sets);
-
- G_OBJECT_CLASS (meta_kms_impl_device_simple_parent_class)->finalize (object);
-}
-
-static MetaDeviceFile *
-meta_kms_impl_device_simple_open_device_file (MetaKmsImplDevice *impl_device,
- const char *path,
- GError **error)
-{
- MetaKmsDevice *device = meta_kms_impl_device_get_device (impl_device);
- MetaKms *kms = meta_kms_device_get_kms (device);
- MetaBackend *backend = meta_kms_get_backend (kms);
- MetaDevicePool *device_pool =
- meta_backend_native_get_device_pool (META_BACKEND_NATIVE (backend));
- g_autoptr (MetaDeviceFile) device_file = NULL;
-
- device_file = meta_device_pool_open (device_pool, path,
- META_DEVICE_FILE_FLAG_TAKE_CONTROL,
- error);
- if (!device_file)
- return NULL;
-
- if (!meta_device_file_has_tag (device_file,
- META_DEVICE_FILE_TAG_KMS,
- META_KMS_DEVICE_FILE_TAG_SIMPLE))
- {
- int fd = meta_device_file_get_fd (device_file);
-
- g_warn_if_fail (!meta_device_file_has_tag (device_file,
- META_DEVICE_FILE_TAG_KMS,
- META_KMS_DEVICE_FILE_TAG_ATOMIC));
-
- if (drmSetClientCap (fd, DRM_CLIENT_CAP_UNIVERSAL_PLANES, 1) != 0)
- {
- g_set_error (error, META_KMS_ERROR, META_KMS_ERROR_NOT_SUPPORTED,
- "DRM_CLIENT_CAP_UNIVERSAL_PLANES not supported");
- return NULL;
- }
-
- meta_device_file_tag (device_file,
- META_DEVICE_FILE_TAG_KMS,
- META_KMS_DEVICE_FILE_TAG_SIMPLE);
- }
-
- return g_steal_pointer (&device_file);
-}
-
-static gboolean
-meta_kms_impl_device_simple_initable_init (GInitable *initable,
- GCancellable *cancellable,
- GError **error)
-{
- MetaKmsImplDeviceSimple *impl_device_simple =
- META_KMS_IMPL_DEVICE_SIMPLE (initable);
- MetaKmsImplDevice *impl_device = META_KMS_IMPL_DEVICE (impl_device_simple);
- MetaKmsDevice *device = meta_kms_impl_device_get_device (impl_device);
- GList *l;
-
- if (!initable_parent_iface->init (initable, cancellable, error))
- return FALSE;
-
- if (!meta_kms_impl_device_init_mode_setting (impl_device, error))
- return FALSE;
-
- impl_device_simple->cached_mode_sets =
- g_hash_table_new_full (NULL,
- NULL,
- NULL,
- (GDestroyNotify) cached_mode_set_free);
-
- for (l = meta_kms_device_get_crtcs (device); l; l = l->next)
- {
- MetaKmsCrtc *crtc = l->data;
- MetaKmsPlane *plane;
-
- plane = meta_kms_device_get_cursor_plane_for (device, crtc);
- if (plane)
- continue;
-
- meta_topic (META_DEBUG_KMS,
- "[simple] Adding fake cursor plane for CRTC %u (%s)",
- meta_kms_crtc_get_id (crtc),
- meta_kms_impl_device_get_path (impl_device));
-
- meta_kms_device_add_fake_plane_in_impl (device,
- META_KMS_PLANE_TYPE_CURSOR,
- crtc);
- }
-
- g_message ("Added device '%s' (%s) using non-atomic mode setting.",
- meta_kms_impl_device_get_path (impl_device),
- meta_kms_impl_device_get_driver_name (impl_device));
-
- return TRUE;
-}
-
-static void
-meta_kms_impl_device_simple_init (MetaKmsImplDeviceSimple *impl_device_simple)
-{
-}
-
-static void
-initable_iface_init (GInitableIface *iface)
-{
- initable_parent_iface = g_type_interface_peek_parent (iface);
-
- iface->init = meta_kms_impl_device_simple_initable_init;
-}
-
-static void
-meta_kms_impl_device_simple_class_init (MetaKmsImplDeviceSimpleClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
- MetaKmsImplDeviceClass *impl_device_class =
- META_KMS_IMPL_DEVICE_CLASS (klass);
-
- object_class->finalize = meta_kms_impl_device_simple_finalize;
-
- impl_device_class->open_device_file =
- meta_kms_impl_device_simple_open_device_file;
- impl_device_class->setup_drm_event_context =
- meta_kms_impl_device_simple_setup_drm_event_context;
- impl_device_class->process_update =
- meta_kms_impl_device_simple_process_update;
- impl_device_class->handle_page_flip_callback =
- meta_kms_impl_device_simple_handle_page_flip_callback;
- impl_device_class->discard_pending_page_flips =
- meta_kms_impl_device_simple_discard_pending_page_flips;
- impl_device_class->prepare_shutdown =
- meta_kms_impl_device_simple_prepare_shutdown;
-}
diff --git a/src/backends/native/meta-kms-impl-device-simple.h b/src/backends/native/meta-kms-impl-device-simple.h
deleted file mode 100644
index 7be5f0a83..000000000
--- a/src/backends/native/meta-kms-impl-device-simple.h
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Copyright (C) 2018-2020 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-
-#ifndef META_KMS_IMPL_DEVICE_SIMPLE_H
-#define META_KMS_IMPL_DEVICE_SIMPLE_H
-
-#include "backends/native/meta-kms-impl-device.h"
-
-#define META_TYPE_KMS_IMPL_DEVICE_SIMPLE (meta_kms_impl_device_simple_get_type ())
-G_DECLARE_FINAL_TYPE (MetaKmsImplDeviceSimple, meta_kms_impl_device_simple,
- META, KMS_IMPL_DEVICE_SIMPLE, MetaKmsImplDevice)
-
-#endif /* META_KMS_IMPL_DEVICE_SIMPLE_H */
diff --git a/src/backends/native/meta-kms-impl-device.c b/src/backends/native/meta-kms-impl-device.c
deleted file mode 100644
index e08e672e5..000000000
--- a/src/backends/native/meta-kms-impl-device.c
+++ /dev/null
@@ -1,1070 +0,0 @@
-/*
- * Copyright (C) 2019 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-
-#include "config.h"
-
-#include "backends/native/meta-kms-impl-device.h"
-
-#include <errno.h>
-#include <xf86drm.h>
-
-#include "backends/native/meta-backend-native.h"
-#include "backends/native/meta-device-pool.h"
-#include "backends/native/meta-kms-connector-private.h"
-#include "backends/native/meta-kms-connector.h"
-#include "backends/native/meta-kms-crtc-private.h"
-#include "backends/native/meta-kms-crtc.h"
-#include "backends/native/meta-kms-impl.h"
-#include "backends/native/meta-kms-mode-private.h"
-#include "backends/native/meta-kms-page-flip-private.h"
-#include "backends/native/meta-kms-plane-private.h"
-#include "backends/native/meta-kms-plane.h"
-#include "backends/native/meta-kms-private.h"
-#include "backends/native/meta-kms-update-private.h"
-
-#include "meta-default-modes.h"
-#include "meta-private-enum-types.h"
-
-enum
-{
- PROP_0,
-
- PROP_DEVICE,
- PROP_IMPL,
- PROP_PATH,
- PROP_FLAGS,
-
- N_PROPS
-};
-
-static GParamSpec *obj_props[N_PROPS];
-
-typedef struct _MetaKmsImplDevicePrivate
-{
- MetaKmsDevice *device;
- MetaKmsImpl *impl;
-
- int fd_hold_count;
- MetaDeviceFile *device_file;
- GSource *fd_source;
- char *path;
- MetaKmsDeviceFlag flags;
- gboolean has_latched_fd_hold;
-
- char *driver_name;
- char *driver_description;
-
- GList *crtcs;
- GList *connectors;
- GList *planes;
-
- MetaKmsDeviceCaps caps;
-
- GList *fallback_modes;
-} MetaKmsImplDevicePrivate;
-
-static void
-initable_iface_init (GInitableIface *iface);
-
-G_DEFINE_TYPE_WITH_CODE (MetaKmsImplDevice, meta_kms_impl_device,
- G_TYPE_OBJECT,
- G_ADD_PRIVATE (MetaKmsImplDevice)
- G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE,
- initable_iface_init))
-
-G_DEFINE_QUARK (-meta-kms-error-quark, meta_kms_error)
-
-MetaKmsDevice *
-meta_kms_impl_device_get_device (MetaKmsImplDevice *impl_device)
-{
- MetaKmsImplDevicePrivate *priv =
- meta_kms_impl_device_get_instance_private (impl_device);
-
- return priv->device;
-}
-
-GList *
-meta_kms_impl_device_copy_connectors (MetaKmsImplDevice *impl_device)
-{
- MetaKmsImplDevicePrivate *priv =
- meta_kms_impl_device_get_instance_private (impl_device);
-
- return g_list_copy (priv->connectors);
-}
-
-GList *
-meta_kms_impl_device_copy_crtcs (MetaKmsImplDevice *impl_device)
-{
- MetaKmsImplDevicePrivate *priv =
- meta_kms_impl_device_get_instance_private (impl_device);
-
- return g_list_copy (priv->crtcs);
-}
-
-GList *
-meta_kms_impl_device_copy_planes (MetaKmsImplDevice *impl_device)
-{
- MetaKmsImplDevicePrivate *priv =
- meta_kms_impl_device_get_instance_private (impl_device);
-
- return g_list_copy (priv->planes);
-}
-
-GList *
-meta_kms_impl_device_peek_connectors (MetaKmsImplDevice *impl_device)
-{
- MetaKmsImplDevicePrivate *priv =
- meta_kms_impl_device_get_instance_private (impl_device);
-
- return priv->connectors;
-}
-
-GList *
-meta_kms_impl_device_peek_crtcs (MetaKmsImplDevice *impl_device)
-{
- MetaKmsImplDevicePrivate *priv =
- meta_kms_impl_device_get_instance_private (impl_device);
-
- return priv->crtcs;
-}
-
-GList *
-meta_kms_impl_device_peek_planes (MetaKmsImplDevice *impl_device)
-{
- MetaKmsImplDevicePrivate *priv =
- meta_kms_impl_device_get_instance_private (impl_device);
-
- return priv->planes;
-}
-
-const MetaKmsDeviceCaps *
-meta_kms_impl_device_get_caps (MetaKmsImplDevice *impl_device)
-{
- MetaKmsImplDevicePrivate *priv =
- meta_kms_impl_device_get_instance_private (impl_device);
-
- return &priv->caps;
-}
-
-GList *
-meta_kms_impl_device_copy_fallback_modes (MetaKmsImplDevice *impl_device)
-{
- MetaKmsImplDevicePrivate *priv =
- meta_kms_impl_device_get_instance_private (impl_device);
-
- return g_list_copy (priv->fallback_modes);
-}
-
-const char *
-meta_kms_impl_device_get_driver_name (MetaKmsImplDevice *impl_device)
-{
- MetaKmsImplDevicePrivate *priv =
- meta_kms_impl_device_get_instance_private (impl_device);
-
- return priv->driver_name;
-}
-
-const char *
-meta_kms_impl_device_get_driver_description (MetaKmsImplDevice *impl_device)
-{
- MetaKmsImplDevicePrivate *priv =
- meta_kms_impl_device_get_instance_private (impl_device);
-
- return priv->driver_description;
-}
-
-const char *
-meta_kms_impl_device_get_path (MetaKmsImplDevice *impl_device)
-{
- MetaKmsImplDevicePrivate *priv =
- meta_kms_impl_device_get_instance_private (impl_device);
-
- return priv->path;
-}
-
-gboolean
-meta_kms_impl_device_dispatch (MetaKmsImplDevice *impl_device,
- GError **error)
-{
- MetaKmsImplDevicePrivate *priv =
- meta_kms_impl_device_get_instance_private (impl_device);
- MetaKmsImplDeviceClass *klass = META_KMS_IMPL_DEVICE_GET_CLASS (impl_device);
- int fd;
-
- drmEventContext drm_event_context;
-
- meta_assert_in_kms_impl (meta_kms_impl_get_kms (priv->impl));
-
- drm_event_context = (drmEventContext) { 0 };
- klass->setup_drm_event_context (impl_device, &drm_event_context);
-
- fd = meta_device_file_get_fd (priv->device_file);
-
- while (TRUE)
- {
- if (drmHandleEvent (fd, &drm_event_context) != 0)
- {
- struct pollfd pfd;
- int ret;
-
- if (errno != EAGAIN)
- {
- g_set_error_literal (error, G_IO_ERROR,
- g_io_error_from_errno (errno),
- strerror (errno));
- return FALSE;
- }
-
- pfd.fd = fd;
- pfd.events = POLL_IN | POLL_ERR;
- do
- {
- ret = poll (&pfd, 1, -1);
- }
- while (ret == -1 && errno == EINTR);
- }
- else
- {
- break;
- }
- }
-
- return TRUE;
-}
-
-static gpointer
-kms_event_dispatch_in_impl (MetaKmsImpl *impl,
- gpointer user_data,
- GError **error)
-{
- MetaKmsImplDevice *impl_device = user_data;
- gboolean ret;
-
- ret = meta_kms_impl_device_dispatch (impl_device, error);
- return GINT_TO_POINTER (ret);
-}
-
-drmModePropertyPtr
-meta_kms_impl_device_find_property (MetaKmsImplDevice *impl_device,
- drmModeObjectProperties *props,
- const char *prop_name,
- int *out_idx)
-{
- MetaKmsImplDevicePrivate *priv =
- meta_kms_impl_device_get_instance_private (impl_device);
- int fd;
- unsigned int i;
-
- meta_assert_in_kms_impl (meta_kms_impl_get_kms (priv->impl));
-
- fd = meta_device_file_get_fd (priv->device_file);
-
- for (i = 0; i < props->count_props; i++)
- {
- drmModePropertyPtr prop;
-
- prop = drmModeGetProperty (fd, props->props[i]);
- if (!prop)
- continue;
-
- if (strcmp (prop->name, prop_name) == 0)
- {
- *out_idx = i;
- return prop;
- }
-
- drmModeFreeProperty (prop);
- }
-
- return NULL;
-}
-
-static void
-init_caps (MetaKmsImplDevice *impl_device)
-{
- MetaKmsImplDevicePrivate *priv =
- meta_kms_impl_device_get_instance_private (impl_device);
- int fd;
- uint64_t cursor_width, cursor_height;
- uint64_t prefer_shadow;
- uint64_t uses_monotonic_clock;
-
- fd = meta_device_file_get_fd (priv->device_file);
- if (drmGetCap (fd, DRM_CAP_CURSOR_WIDTH, &cursor_width) == 0 &&
- drmGetCap (fd, DRM_CAP_CURSOR_HEIGHT, &cursor_height) == 0)
- {
- priv->caps.has_cursor_size = TRUE;
- priv->caps.cursor_width = cursor_width;
- priv->caps.cursor_height = cursor_height;
- }
-
- if (drmGetCap (fd, DRM_CAP_DUMB_PREFER_SHADOW, &prefer_shadow) == 0)
- {
- if (prefer_shadow)
- g_message ("Device '%s' prefers shadow buffer", priv->path);
-
- priv->caps.prefers_shadow_buffer = prefer_shadow;
- }
-
- if (drmGetCap (fd, DRM_CAP_TIMESTAMP_MONOTONIC, &uses_monotonic_clock) == 0)
- {
- priv->caps.uses_monotonic_clock = uses_monotonic_clock;
- }
-}
-
-static void
-init_crtcs (MetaKmsImplDevice *impl_device,
- drmModeRes *drm_resources)
-{
- MetaKmsImplDevicePrivate *priv =
- meta_kms_impl_device_get_instance_private (impl_device);
- int idx;
- int fd;
-
- fd = meta_device_file_get_fd (priv->device_file);
-
- for (idx = 0; idx < drm_resources->count_crtcs; idx++)
- {
- uint32_t crtc_id;
- drmModeCrtc *drm_crtc;
- MetaKmsCrtc *crtc;
- g_autoptr (GError) error = NULL;
-
- crtc_id = drm_resources->crtcs[idx];
- drm_crtc = drmModeGetCrtc (fd, crtc_id);
- if (!drm_crtc)
- {
- g_warning ("Failed to get CRTC %u info on '%s': %s",
- crtc_id, priv->path, error->message);
- continue;
- }
-
- crtc = meta_kms_crtc_new (impl_device, drm_crtc, idx, &error);
-
- drmModeFreeCrtc (drm_crtc);
-
- if (!crtc)
- {
- g_warning ("Failed to create CRTC for %u on '%s': %s",
- crtc_id, priv->path, error->message);
- continue;
- }
-
- priv->crtcs = g_list_prepend (priv->crtcs, crtc);
- }
- priv->crtcs = g_list_reverse (priv->crtcs);
-}
-
-static MetaKmsConnector *
-find_existing_connector (MetaKmsImplDevice *impl_device,
- drmModeConnector *drm_connector)
-{
- MetaKmsImplDevicePrivate *priv =
- meta_kms_impl_device_get_instance_private (impl_device);
- GList *l;
-
- for (l = priv->connectors; l; l = l->next)
- {
- MetaKmsConnector *connector = l->data;
-
- if (meta_kms_connector_is_same_as (connector, drm_connector))
- return connector;
- }
-
- return NULL;
-}
-
-static void
-update_connectors (MetaKmsImplDevice *impl_device,
- drmModeRes *drm_resources)
-{
- MetaKmsImplDevicePrivate *priv =
- meta_kms_impl_device_get_instance_private (impl_device);
- GList *connectors = NULL;
- unsigned int i;
- int fd;
-
- fd = meta_device_file_get_fd (priv->device_file);
-
- for (i = 0; i < drm_resources->count_connectors; i++)
- {
- drmModeConnector *drm_connector;
- MetaKmsConnector *connector;
-
- drm_connector = drmModeGetConnector (fd, drm_resources->connectors[i]);
- if (!drm_connector)
- continue;
-
- connector = find_existing_connector (impl_device, drm_connector);
- if (connector)
- connector = g_object_ref (connector);
- else
- connector = meta_kms_connector_new (impl_device, drm_connector,
- drm_resources);
- drmModeFreeConnector (drm_connector);
-
- connectors = g_list_prepend (connectors, connector);
- }
-
- g_list_free_full (priv->connectors, g_object_unref);
- priv->connectors = g_list_reverse (connectors);
-}
-
-static MetaKmsPlaneType
-get_plane_type (MetaKmsImplDevice *impl_device,
- drmModeObjectProperties *props)
-{
- drmModePropertyPtr prop;
- int idx;
-
- prop = meta_kms_impl_device_find_property (impl_device, props, "type", &idx);
- if (!prop)
- return FALSE;
- drmModeFreeProperty (prop);
-
- switch (props->prop_values[idx])
- {
- case DRM_PLANE_TYPE_PRIMARY:
- return META_KMS_PLANE_TYPE_PRIMARY;
- case DRM_PLANE_TYPE_CURSOR:
- return META_KMS_PLANE_TYPE_CURSOR;
- case DRM_PLANE_TYPE_OVERLAY:
- return META_KMS_PLANE_TYPE_OVERLAY;
- default:
- g_warning ("Unhandled plane type %" G_GUINT64_FORMAT,
- props->prop_values[idx]);
- return -1;
- }
-}
-
-MetaKmsPlane *
-meta_kms_impl_device_add_fake_plane (MetaKmsImplDevice *impl_device,
- MetaKmsPlaneType plane_type,
- MetaKmsCrtc *crtc)
-{
- MetaKmsImplDevicePrivate *priv =
- meta_kms_impl_device_get_instance_private (impl_device);
- MetaKmsPlane *plane;
-
- plane = meta_kms_plane_new_fake (plane_type, crtc);
- priv->planes = g_list_append (priv->planes, plane);
-
- return plane;
-}
-
-static MetaKmsProp *
-find_prop (MetaKmsProp *props,
- int n_props,
- const char *name)
-{
- int i;
-
- for (i = 0; i < n_props; i++)
- {
- MetaKmsProp *prop = &props[i];
-
- g_warn_if_fail (prop->name);
-
- if (g_strcmp0 (prop->name, name) == 0)
- return prop;
- }
-
- return NULL;
-}
-
-void
-meta_kms_impl_device_init_prop_table (MetaKmsImplDevice *impl_device,
- uint32_t *drm_props,
- uint64_t *drm_prop_values,
- int n_drm_props,
- MetaKmsProp *props,
- int n_props,
- gpointer user_data)
-{
- int fd;
- uint32_t i;
-
- fd = meta_kms_impl_device_get_fd (impl_device);
-
- for (i = 0; i < n_drm_props; i++)
- {
- drmModePropertyRes *drm_prop;
- MetaKmsProp *prop;
-
- drm_prop = drmModeGetProperty (fd, drm_props[i]);
- if (!drm_prop)
- continue;
-
- prop = find_prop (props, n_props, drm_prop->name);
- if (!prop)
- {
- drmModeFreeProperty (drm_prop);
- continue;
- }
-
- if (!(drm_prop->flags & prop->type))
- {
- g_warning ("DRM property '%s' (%u) had unexpected flags (0x%x), "
- "ignoring",
- drm_prop->name, drm_props[i], drm_prop->flags);
- drmModeFreeProperty (drm_prop);
- continue;
- }
-
- prop->prop_id = drm_props[i];
-
- if (prop->parse)
- {
- prop->parse (impl_device, prop,
- drm_prop, drm_prop_values[i],
- user_data);
- }
-
- drmModeFreeProperty (drm_prop);
- }
-}
-
-static void
-init_planes (MetaKmsImplDevice *impl_device)
-{
- MetaKmsImplDevicePrivate *priv =
- meta_kms_impl_device_get_instance_private (impl_device);
- int fd;
- drmModePlaneRes *drm_planes;
- unsigned int i;
-
- fd = meta_device_file_get_fd (priv->device_file);
-
- drm_planes = drmModeGetPlaneResources (fd);
- if (!drm_planes)
- return;
-
- for (i = 0; i < drm_planes->count_planes; i++)
- {
- drmModePlane *drm_plane;
- drmModeObjectProperties *props;
-
- drm_plane = drmModeGetPlane (fd, drm_planes->planes[i]);
- if (!drm_plane)
- continue;
-
- props = drmModeObjectGetProperties (fd,
- drm_plane->plane_id,
- DRM_MODE_OBJECT_PLANE);
- if (props)
- {
- MetaKmsPlaneType plane_type;
-
- plane_type = get_plane_type (impl_device, props);
- if (plane_type != -1)
- {
- MetaKmsPlane *plane;
-
- plane = meta_kms_plane_new (plane_type,
- impl_device,
- drm_plane, props);
-
- priv->planes = g_list_prepend (priv->planes, plane);
- }
- }
-
- g_clear_pointer (&props, drmModeFreeObjectProperties);
- drmModeFreePlane (drm_plane);
- }
- priv->planes = g_list_reverse (priv->planes);
-}
-
-static void
-init_fallback_modes (MetaKmsImplDevice *impl_device)
-{
- MetaKmsImplDevicePrivate *priv =
- meta_kms_impl_device_get_instance_private (impl_device);
- GList *modes = NULL;
- int i;
-
- for (i = 0; i < G_N_ELEMENTS (meta_default_landscape_drm_mode_infos); i++)
- {
- MetaKmsMode *mode;
-
- mode = meta_kms_mode_new (impl_device,
- &meta_default_landscape_drm_mode_infos[i],
- META_KMS_MODE_FLAG_FALLBACK_LANDSCAPE);
- modes = g_list_prepend (modes, mode);
- }
-
- for (i = 0; i < G_N_ELEMENTS (meta_default_portrait_drm_mode_infos); i++)
- {
- MetaKmsMode *mode;
-
- mode = meta_kms_mode_new (impl_device,
- &meta_default_portrait_drm_mode_infos[i],
- META_KMS_MODE_FLAG_FALLBACK_PORTRAIT);
- modes = g_list_prepend (modes, mode);
- }
-
- priv->fallback_modes = g_list_reverse (modes);
-}
-
-static MetaDeviceFile *
-meta_kms_impl_device_open_device_file (MetaKmsImplDevice *impl_device,
- const char *path,
- GError **error)
-{
- MetaKmsImplDevicePrivate *priv =
- meta_kms_impl_device_get_instance_private (impl_device);
- MetaKmsImplDeviceClass *klass = META_KMS_IMPL_DEVICE_GET_CLASS (impl_device);
-
- return klass->open_device_file (impl_device, priv->path, error);
-}
-
-static gboolean
-ensure_device_file (MetaKmsImplDevice *impl_device,
- GError **error)
-{
- MetaKmsImplDevicePrivate *priv =
- meta_kms_impl_device_get_instance_private (impl_device);
- MetaDeviceFile *device_file;
-
- if (priv->device_file)
- return TRUE;
-
- device_file = meta_kms_impl_device_open_device_file (impl_device,
- priv->path,
- error);
- if (!device_file)
- return FALSE;
-
- priv->device_file = device_file;
-
- if (!(priv->flags & META_KMS_DEVICE_FLAG_NO_MODE_SETTING))
- {
- priv->fd_source =
- meta_kms_register_fd_in_impl (meta_kms_impl_get_kms (priv->impl),
- meta_device_file_get_fd (device_file),
- kms_event_dispatch_in_impl,
- impl_device);
- }
-
- return TRUE;
-}
-
-static void
-ensure_latched_fd_hold (MetaKmsImplDevice *impl_device)
-{
- MetaKmsImplDevicePrivate *priv =
- meta_kms_impl_device_get_instance_private (impl_device);
-
- if (!priv->has_latched_fd_hold)
- {
- meta_kms_impl_device_hold_fd (impl_device);
- priv->has_latched_fd_hold = TRUE;
- }
-}
-
-static void
-clear_latched_fd_hold (MetaKmsImplDevice *impl_device)
-{
- MetaKmsImplDevicePrivate *priv =
- meta_kms_impl_device_get_instance_private (impl_device);
-
- if (priv->has_latched_fd_hold)
- {
- meta_kms_impl_device_unhold_fd (impl_device);
- priv->has_latched_fd_hold = FALSE;
- }
-}
-
-void
-meta_kms_impl_device_update_states (MetaKmsImplDevice *impl_device)
-{
- MetaKmsImplDevicePrivate *priv =
- meta_kms_impl_device_get_instance_private (impl_device);
- g_autoptr (GError) error = NULL;
- int fd;
- drmModeRes *drm_resources;
-
- meta_assert_in_kms_impl (meta_kms_impl_get_kms (priv->impl));
-
- meta_topic (META_DEBUG_KMS, "Updating device state for %s", priv->path);
-
- if (!ensure_device_file (impl_device, &error))
- {
- g_warning ("Failed to reopen '%s': %s", priv->path, error->message);
- goto err;
- }
-
- ensure_latched_fd_hold (impl_device);
-
- fd = meta_device_file_get_fd (priv->device_file);
- drm_resources = drmModeGetResources (fd);
- if (!drm_resources)
- {
- meta_topic (META_DEBUG_KMS, "Device '%s' didn't return any resources",
- priv->path);
- goto err;
- }
-
- update_connectors (impl_device, drm_resources);
-
- g_list_foreach (priv->crtcs, (GFunc) meta_kms_crtc_update_state,
- NULL);
- g_list_foreach (priv->connectors, (GFunc) meta_kms_connector_update_state,
- drm_resources);
- drmModeFreeResources (drm_resources);
-
- return;
-
-err:
- g_clear_list (&priv->planes, g_object_unref);
- g_clear_list (&priv->crtcs, g_object_unref);
- g_clear_list (&priv->connectors, g_object_unref);
-}
-
-void
-meta_kms_impl_device_predict_states (MetaKmsImplDevice *impl_device,
- MetaKmsUpdate *update)
-{
- MetaKmsImplDevicePrivate *priv =
- meta_kms_impl_device_get_instance_private (impl_device);
-
- g_list_foreach (priv->crtcs, (GFunc) meta_kms_crtc_predict_state,
- update);
- g_list_foreach (priv->connectors, (GFunc) meta_kms_connector_predict_state,
- update);
-}
-
-void
-meta_kms_impl_device_notify_modes_set (MetaKmsImplDevice *impl_device)
-{
- clear_latched_fd_hold (impl_device);
-}
-
-int
-meta_kms_impl_device_get_fd (MetaKmsImplDevice *impl_device)
-{
- MetaKmsImplDevicePrivate *priv =
- meta_kms_impl_device_get_instance_private (impl_device);
-
- meta_assert_in_kms_impl (meta_kms_impl_get_kms (priv->impl));
-
- return meta_device_file_get_fd (priv->device_file);
-}
-
-MetaKmsFeedback *
-meta_kms_impl_device_process_update (MetaKmsImplDevice *impl_device,
- MetaKmsUpdate *update,
- MetaKmsUpdateFlag flags)
-{
- MetaKmsImplDeviceClass *klass = META_KMS_IMPL_DEVICE_GET_CLASS (impl_device);
- MetaKmsFeedback *feedback;
- g_autoptr (GError) error = NULL;
-
- if (!ensure_device_file (impl_device, &error))
- return meta_kms_feedback_new_failed (NULL, g_steal_pointer (&error));
-
- meta_kms_impl_device_hold_fd (impl_device);
- feedback = klass->process_update (impl_device, update, flags);
- meta_kms_impl_device_unhold_fd (impl_device);
-
- return feedback;
-}
-
-void
-meta_kms_impl_device_handle_page_flip_callback (MetaKmsImplDevice *impl_device,
- MetaKmsPageFlipData *page_flip_data)
-{
- MetaKmsImplDeviceClass *klass = META_KMS_IMPL_DEVICE_GET_CLASS (impl_device);
-
- klass->handle_page_flip_callback (impl_device, page_flip_data);
-}
-
-void
-meta_kms_impl_device_discard_pending_page_flips (MetaKmsImplDevice *impl_device)
-{
- MetaKmsImplDeviceClass *klass = META_KMS_IMPL_DEVICE_GET_CLASS (impl_device);
-
- klass->discard_pending_page_flips (impl_device);
-}
-
-void
-meta_kms_impl_device_hold_fd (MetaKmsImplDevice *impl_device)
-{
- MetaKmsImplDevicePrivate *priv =
- meta_kms_impl_device_get_instance_private (impl_device);
- MetaKms *kms = meta_kms_device_get_kms (priv->device);
-
- meta_assert_in_kms_impl (kms);
-
- g_assert (priv->device_file);
-
- priv->fd_hold_count++;
-}
-
-void
-meta_kms_impl_device_unhold_fd (MetaKmsImplDevice *impl_device)
-{
- MetaKmsImplDevicePrivate *priv =
- meta_kms_impl_device_get_instance_private (impl_device);
- MetaKms *kms = meta_kms_device_get_kms (priv->device);
-
- meta_assert_in_kms_impl (kms);
-
- g_return_if_fail (priv->fd_hold_count > 0);
-
- priv->fd_hold_count--;
- if (priv->fd_hold_count == 0)
- {
- g_clear_pointer (&priv->device_file, meta_device_file_release);
-
- if (priv->fd_source)
- {
- g_source_destroy (priv->fd_source);
- g_clear_pointer (&priv->fd_source, g_source_unref);
- }
- }
-}
-
-static void
-meta_kms_impl_device_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- MetaKmsImplDevice *impl_device = META_KMS_IMPL_DEVICE (object);
- MetaKmsImplDevicePrivate *priv =
- meta_kms_impl_device_get_instance_private (impl_device);
-
- switch (prop_id)
- {
- case PROP_DEVICE:
- g_value_set_object (value, priv->device);
- break;
- case PROP_IMPL:
- g_value_set_object (value, priv->impl);
- break;
- case PROP_FLAGS:
- g_value_set_flags (value, priv->flags);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-
-static void
-meta_kms_impl_device_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- MetaKmsImplDevice *impl_device = META_KMS_IMPL_DEVICE (object);
- MetaKmsImplDevicePrivate *priv =
- meta_kms_impl_device_get_instance_private (impl_device);
-
- switch (prop_id)
- {
- case PROP_DEVICE:
- priv->device = g_value_get_object (value);
- break;
- case PROP_IMPL:
- priv->impl = g_value_get_object (value);
- break;
- case PROP_PATH:
- priv->path = g_value_dup_string (value);
- break;
- case PROP_FLAGS:
- priv->flags = g_value_get_flags (value);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-
-static void
-meta_kms_impl_device_finalize (GObject *object)
-{
- MetaKmsImplDevice *impl_device = META_KMS_IMPL_DEVICE (object);
- MetaKmsImplDevicePrivate *priv =
- meta_kms_impl_device_get_instance_private (impl_device);
-
- meta_kms_impl_remove_impl_device (priv->impl, impl_device);
-
- g_list_free_full (priv->planes, g_object_unref);
- g_list_free_full (priv->crtcs, g_object_unref);
- g_list_free_full (priv->connectors, g_object_unref);
- g_list_free_full (priv->fallback_modes,
- (GDestroyNotify) meta_kms_mode_free);
-
- clear_latched_fd_hold (impl_device);
- g_warn_if_fail (!priv->device_file);
-
- g_free (priv->driver_name);
- g_free (priv->driver_description);
- g_free (priv->path);
-
- G_OBJECT_CLASS (meta_kms_impl_device_parent_class)->finalize (object);
-}
-
-gboolean
-meta_kms_impl_device_init_mode_setting (MetaKmsImplDevice *impl_device,
- GError **error)
-{
- MetaKmsImplDevicePrivate *priv =
- meta_kms_impl_device_get_instance_private (impl_device);
- int fd;
- drmModeRes *drm_resources;
-
- fd = meta_device_file_get_fd (priv->device_file);
-
- drm_resources = drmModeGetResources (fd);
- if (!drm_resources)
- {
- g_set_error (error, G_IO_ERROR, g_io_error_from_errno (errno),
- "Failed to activate universal planes: %s",
- g_strerror (errno));
- return FALSE;
- }
-
- init_caps (impl_device);
-
- init_crtcs (impl_device, drm_resources);
- init_planes (impl_device);
-
- init_fallback_modes (impl_device);
-
- update_connectors (impl_device, drm_resources);
-
- drmModeFreeResources (drm_resources);
-
- return TRUE;
-}
-
-void
-meta_kms_impl_device_prepare_shutdown (MetaKmsImplDevice *impl_device)
-{
- MetaKmsImplDeviceClass *klass = META_KMS_IMPL_DEVICE_GET_CLASS (impl_device);
-
- if (klass->prepare_shutdown)
- klass->prepare_shutdown (impl_device);
-}
-
-static gboolean
-get_driver_info (int fd,
- char **name,
- char **description)
-{
- drmVersion *drm_version;
-
- drm_version = drmGetVersion (fd);
- if (!drm_version)
- return FALSE;
-
- *name = g_strndup (drm_version->name,
- drm_version->name_len);
- *description = g_strndup (drm_version->desc,
- drm_version->desc_len);
- drmFreeVersion (drm_version);
-
- return TRUE;
-}
-
-static gboolean
-meta_kms_impl_device_initable_init (GInitable *initable,
- GCancellable *cancellable,
- GError **error)
-{
- MetaKmsImplDevice *impl_device = META_KMS_IMPL_DEVICE (initable);
- MetaKmsImplDevicePrivate *priv =
- meta_kms_impl_device_get_instance_private (impl_device);
- int fd;
-
- if (!ensure_device_file (impl_device, error))
- return FALSE;
-
- ensure_latched_fd_hold (impl_device);
-
- g_clear_pointer (&priv->path, g_free);
- priv->path = g_strdup (meta_device_file_get_path (priv->device_file));
-
- fd = meta_device_file_get_fd (priv->device_file);
- if (!get_driver_info (fd, &priv->driver_name, &priv->driver_description))
- {
- priv->driver_name = g_strdup ("unknown");
- priv->driver_description = g_strdup ("Unknown");
- }
-
- return TRUE;
-}
-
-static void
-meta_kms_impl_device_init (MetaKmsImplDevice *impl_device)
-{
-}
-
-static void
-initable_iface_init (GInitableIface *iface)
-{
- iface->init = meta_kms_impl_device_initable_init;
-}
-
-static void
-meta_kms_impl_device_class_init (MetaKmsImplDeviceClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- object_class->get_property = meta_kms_impl_device_get_property;
- object_class->set_property = meta_kms_impl_device_set_property;
- object_class->finalize = meta_kms_impl_device_finalize;
-
- obj_props[PROP_DEVICE] =
- g_param_spec_object ("device",
- "device",
- "MetaKmsDevice",
- META_TYPE_KMS_DEVICE,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT_ONLY |
- G_PARAM_STATIC_STRINGS);
- obj_props[PROP_IMPL] =
- g_param_spec_object ("impl",
- "impl",
- "MetaKmsImpl",
- META_TYPE_KMS_IMPL,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT_ONLY |
- G_PARAM_STATIC_STRINGS);
- obj_props[PROP_PATH] =
- g_param_spec_string ("path",
- "path",
- "Device path",
- NULL,
- G_PARAM_WRITABLE |
- G_PARAM_CONSTRUCT_ONLY |
- G_PARAM_STATIC_STRINGS);
- obj_props[PROP_FLAGS] =
- g_param_spec_flags ("flags",
- "flags",
- "KMS impl device flags",
- META_TYPE_KMS_DEVICE_FLAG,
- META_KMS_DEVICE_FLAG_NONE,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT_ONLY |
- G_PARAM_STATIC_STRINGS);
- g_object_class_install_properties (object_class, N_PROPS, obj_props);
-}
diff --git a/src/backends/native/meta-kms-impl-device.h b/src/backends/native/meta-kms-impl-device.h
deleted file mode 100644
index e77024ecd..000000000
--- a/src/backends/native/meta-kms-impl-device.h
+++ /dev/null
@@ -1,178 +0,0 @@
-/*
- * Copyright (C) 2019 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-
-#ifndef META_KMS_IMPL_DEVICE_H
-#define META_KMS_IMPL_DEVICE_H
-
-#include <glib-object.h>
-#include <stdint.h>
-#include <xf86drm.h>
-#include <xf86drmMode.h>
-
-#include "backends/native/meta-device-pool.h"
-#include "backends/native/meta-kms-device.h"
-#include "backends/native/meta-kms-page-flip-private.h"
-#include "backends/native/meta-kms-types.h"
-#include "backends/native/meta-kms-update.h"
-#include "backends/native/meta-kms.h"
-
-typedef struct _MetaKmsDeviceCaps
-{
- gboolean has_cursor_size;
- uint64_t cursor_width;
- uint64_t cursor_height;
-
- gboolean prefers_shadow_buffer;
- gboolean uses_monotonic_clock;
-} MetaKmsDeviceCaps;
-
-typedef struct _MetaKmsProp MetaKmsProp;
-
-struct _MetaKmsProp
-{
- const char *name;
- uint32_t type;
- MetaKmsPropType internal_type;
- void (* parse) (MetaKmsImplDevice *impl_device,
- MetaKmsProp *prop,
- drmModePropertyPtr drm_prop,
- uint64_t value,
- gpointer user_data);
-
- uint32_t prop_id;
-};
-
-#define META_TYPE_KMS_IMPL_DEVICE (meta_kms_impl_device_get_type ())
-G_DECLARE_DERIVABLE_TYPE (MetaKmsImplDevice, meta_kms_impl_device,
- META, KMS_IMPL_DEVICE,
- GObject)
-
-struct _MetaKmsImplDeviceClass
-{
- GObjectClass parent_class;
-
- MetaDeviceFile * (* open_device_file) (MetaKmsImplDevice *impl_device,
- const char *path,
- GError **error);
- void (* setup_drm_event_context) (MetaKmsImplDevice *impl_device,
- drmEventContext *drm_event_context);
- MetaKmsFeedback * (* process_update) (MetaKmsImplDevice *impl_device,
- MetaKmsUpdate *update,
- MetaKmsUpdateFlag flags);
- void (* handle_page_flip_callback) (MetaKmsImplDevice *impl_device,
- MetaKmsPageFlipData *page_flip_data);
- void (* discard_pending_page_flips) (MetaKmsImplDevice *impl_device);
- void (* prepare_shutdown) (MetaKmsImplDevice *impl_device);
-};
-
-enum
-{
- META_KMS_ERROR_USER_INHIBITED,
- META_KMS_ERROR_DENY_LISTED,
- META_KMS_ERROR_NOT_SUPPORTED,
-};
-
-enum
-{
- META_KMS_DEVICE_FILE_TAG_ATOMIC = 1 << 0,
- META_KMS_DEVICE_FILE_TAG_SIMPLE = 1 << 1,
-};
-
-#define META_KMS_ERROR meta_kms_error_quark ()
-GQuark meta_kms_error_quark (void);
-
-MetaKmsDevice * meta_kms_impl_device_get_device (MetaKmsImplDevice *impl_device);
-
-GList * meta_kms_impl_device_copy_connectors (MetaKmsImplDevice *impl_device);
-
-GList * meta_kms_impl_device_copy_crtcs (MetaKmsImplDevice *impl_device);
-
-GList * meta_kms_impl_device_copy_planes (MetaKmsImplDevice *impl_device);
-
-GList * meta_kms_impl_device_peek_connectors (MetaKmsImplDevice *impl_device);
-
-GList * meta_kms_impl_device_peek_crtcs (MetaKmsImplDevice *impl_device);
-
-GList * meta_kms_impl_device_peek_planes (MetaKmsImplDevice *impl_device);
-
-const MetaKmsDeviceCaps * meta_kms_impl_device_get_caps (MetaKmsImplDevice *impl_device);
-
-GList * meta_kms_impl_device_copy_fallback_modes (MetaKmsImplDevice *impl_device);
-
-const char * meta_kms_impl_device_get_driver_name (MetaKmsImplDevice *impl_device);
-
-const char * meta_kms_impl_device_get_driver_description (MetaKmsImplDevice *impl_device);
-
-const char * meta_kms_impl_device_get_path (MetaKmsImplDevice *impl_device);
-
-gboolean meta_kms_impl_device_dispatch (MetaKmsImplDevice *impl_device,
- GError **error);
-
-drmModePropertyPtr meta_kms_impl_device_find_property (MetaKmsImplDevice *impl_device,
- drmModeObjectProperties *props,
- const char *prop_name,
- int *idx);
-
-int meta_kms_impl_device_get_fd (MetaKmsImplDevice *impl_device);
-
-void meta_kms_impl_device_hold_fd (MetaKmsImplDevice *impl_device);
-
-void meta_kms_impl_device_unhold_fd (MetaKmsImplDevice *impl_device);
-
-void meta_kms_impl_device_update_states (MetaKmsImplDevice *impl_device);
-
-void meta_kms_impl_device_predict_states (MetaKmsImplDevice *impl_device,
- MetaKmsUpdate *update);
-
-void meta_kms_impl_device_notify_modes_set (MetaKmsImplDevice *impl_device);
-
-MetaKmsPlane * meta_kms_impl_device_add_fake_plane (MetaKmsImplDevice *impl_device,
- MetaKmsPlaneType plane_type,
- MetaKmsCrtc *crtc);
-
-void meta_kms_impl_device_init_prop_table (MetaKmsImplDevice *impl_device,
- uint32_t *drm_props,
- uint64_t *drm_props_values,
- int n_drm_props,
- MetaKmsProp *props,
- int n_props,
- gpointer user_data);
-
-void meta_kms_impl_device_reload_prop_values (MetaKmsImplDevice *impl_device,
- uint32_t *drm_props,
- uint64_t *drm_prop_values,
- int n_drm_props,
- gpointer user_data,
- ...);
-
-MetaKmsFeedback * meta_kms_impl_device_process_update (MetaKmsImplDevice *impl_device,
- MetaKmsUpdate *update,
- MetaKmsUpdateFlag flags);
-
-void meta_kms_impl_device_handle_page_flip_callback (MetaKmsImplDevice *impl_device,
- MetaKmsPageFlipData *page_flip_data);
-
-void meta_kms_impl_device_discard_pending_page_flips (MetaKmsImplDevice *impl_device);
-
-gboolean meta_kms_impl_device_init_mode_setting (MetaKmsImplDevice *impl_device,
- GError **error);
-
-void meta_kms_impl_device_prepare_shutdown (MetaKmsImplDevice *impl_device);
-
-#endif /* META_KMS_IMPL_DEVICE_H */
diff --git a/src/backends/native/meta-kms-impl.c b/src/backends/native/meta-kms-impl.c
deleted file mode 100644
index 0ad76e085..000000000
--- a/src/backends/native/meta-kms-impl.c
+++ /dev/null
@@ -1,204 +0,0 @@
-/*
- * Copyright (C) 2018 Red Hat
- * Copyright (C) 2019 DisplayLink (UK) Ltd.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-
-#include "config.h"
-
-#include "backends/native/meta-kms-impl.h"
-
-#include "backends/native/meta-kms-private.h"
-#include "backends/native/meta-kms-device-private.h"
-#include "backends/native/meta-kms-update-private.h"
-
-enum
-{
- PROP_0,
-
- PROP_KMS,
-};
-
-struct _MetaKmsImpl
-{
- GObject parent;
-};
-
-typedef struct _MetaKmsImplPrivate
-{
- MetaKms *kms;
-
- GList *impl_devices;
-} MetaKmsImplPrivate;
-
-G_DEFINE_TYPE_WITH_PRIVATE (MetaKmsImpl, meta_kms_impl, G_TYPE_OBJECT)
-
-MetaKms *
-meta_kms_impl_get_kms (MetaKmsImpl *impl)
-{
- MetaKmsImplPrivate *priv = meta_kms_impl_get_instance_private (impl);
-
- return priv->kms;
-}
-
-void
-meta_kms_impl_add_impl_device (MetaKmsImpl *impl,
- MetaKmsImplDevice *impl_device)
-{
- MetaKmsImplPrivate *priv = meta_kms_impl_get_instance_private (impl);
-
- meta_assert_in_kms_impl (priv->kms);
-
- priv->impl_devices = g_list_append (priv->impl_devices, impl_device);
-}
-
-void
-meta_kms_impl_remove_impl_device (MetaKmsImpl *impl,
- MetaKmsImplDevice *impl_device)
-{
- MetaKmsImplPrivate *priv = meta_kms_impl_get_instance_private (impl);
-
- meta_assert_in_kms_impl (priv->kms);
-
- priv->impl_devices = g_list_remove (priv->impl_devices, impl_device);
-}
-
-MetaKmsFeedback *
-meta_kms_impl_process_update (MetaKmsImpl *impl,
- MetaKmsUpdate *update,
- MetaKmsUpdateFlag flags)
-{
- MetaKmsImplPrivate *priv = meta_kms_impl_get_instance_private (impl);
- MetaKmsDevice *device;
- MetaKmsImplDevice *impl_device;
-
- meta_assert_in_kms_impl (priv->kms);
-
- device = meta_kms_update_get_device (update);
- impl_device = meta_kms_device_get_impl_device (device);
-
- return meta_kms_impl_device_process_update (impl_device, update, flags);
-}
-
-void
-meta_kms_impl_discard_pending_page_flips (MetaKmsImpl *impl)
-{
- MetaKmsImplPrivate *priv = meta_kms_impl_get_instance_private (impl);
-
- g_list_foreach (priv->impl_devices,
- (GFunc) meta_kms_impl_device_discard_pending_page_flips,
- NULL);
-}
-
-void
-meta_kms_impl_prepare_shutdown (MetaKmsImpl *impl)
-{
- MetaKmsImplPrivate *priv = meta_kms_impl_get_instance_private (impl);
- GList *l;
-
- for (l = priv->impl_devices; l; l = l->next)
- {
- MetaKmsImplDevice *impl_device = l->data;
-
- meta_kms_impl_device_discard_pending_page_flips (impl_device);
- meta_kms_impl_device_prepare_shutdown (impl_device);
- }
-}
-
-void
-meta_kms_impl_notify_modes_set (MetaKmsImpl *impl)
-{
- MetaKmsImplPrivate *priv = meta_kms_impl_get_instance_private (impl);
-
- g_list_foreach (priv->impl_devices,
- (GFunc) meta_kms_impl_device_notify_modes_set,
- NULL);
-}
-
-MetaKmsImpl *
-meta_kms_impl_new (MetaKms *kms)
-{
- return g_object_new (META_TYPE_KMS_IMPL,
- "kms", kms,
- NULL);
-}
-
-static void
-meta_kms_impl_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- MetaKmsImpl *impl = META_KMS_IMPL (object);
- MetaKmsImplPrivate *priv = meta_kms_impl_get_instance_private (impl);
-
- switch (prop_id)
- {
- case PROP_KMS:
- priv->kms = g_value_get_object (value);
- break;
-
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- }
-}
-
-static void
-meta_kms_impl_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- MetaKmsImpl *impl = META_KMS_IMPL (object);
- MetaKmsImplPrivate *priv = meta_kms_impl_get_instance_private (impl);
-
- switch (prop_id)
- {
- case PROP_KMS:
- g_value_set_object (value, priv->kms);
- break;
-
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- }
-}
-
-static void
-meta_kms_impl_init (MetaKmsImpl *kms_impl)
-{
-}
-
-static void
-meta_kms_impl_class_init (MetaKmsImplClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
- GParamSpec *pspec;
-
- object_class->set_property = meta_kms_impl_set_property;
- object_class->get_property = meta_kms_impl_get_property;
-
- pspec = g_param_spec_object ("kms",
- "kms",
- "MetaKms",
- META_TYPE_KMS,
- G_PARAM_READWRITE |
- G_PARAM_STATIC_STRINGS |
- G_PARAM_CONSTRUCT_ONLY);
- g_object_class_install_property (object_class,
- PROP_KMS,
- pspec);
-}
diff --git a/src/backends/native/meta-kms-impl.h b/src/backends/native/meta-kms-impl.h
deleted file mode 100644
index 58f03f81a..000000000
--- a/src/backends/native/meta-kms-impl.h
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Copyright (C) 2018 Red Hat
- * Copyright (C) 2019 DisplayLink (UK) Ltd.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-
-#ifndef META_KMS_IMPL_H
-#define META_KMS_IMPL_H
-
-#include "backends/native/meta-kms-impl-device.h"
-#include "backends/native/meta-kms-page-flip-private.h"
-#include "backends/native/meta-kms.h"
-
-#define META_TYPE_KMS_IMPL (meta_kms_impl_get_type ())
-G_DECLARE_FINAL_TYPE (MetaKmsImpl, meta_kms_impl,
- META, KMS_IMPL, GObject)
-
-MetaKms * meta_kms_impl_get_kms (MetaKmsImpl *impl);
-
-MetaKmsFeedback * meta_kms_impl_process_update (MetaKmsImpl *impl,
- MetaKmsUpdate *update,
- MetaKmsUpdateFlag flags);
-
-void meta_kms_impl_add_impl_device (MetaKmsImpl *impl,
- MetaKmsImplDevice *impl_device);
-
-void meta_kms_impl_remove_impl_device (MetaKmsImpl *impl,
- MetaKmsImplDevice *impl_device);
-
-void meta_kms_impl_discard_pending_page_flips (MetaKmsImpl *impl);
-
-void meta_kms_impl_prepare_shutdown (MetaKmsImpl *impl);
-
-void meta_kms_impl_notify_modes_set (MetaKmsImpl *impl);
-
-MetaKmsImpl * meta_kms_impl_new (MetaKms *kms);
-
-#endif /* META_KMS_IMPL_H */
diff --git a/src/backends/native/meta-kms-mode-private.h b/src/backends/native/meta-kms-mode-private.h
deleted file mode 100644
index ded03c52e..000000000
--- a/src/backends/native/meta-kms-mode-private.h
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright (C) 2020 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-
-#ifndef META_KMS_MODE_PRIVATE_H
-#define META_KMS_MODE_PRIVATE_H
-
-#include "backends/native/meta-kms-mode.h"
-
-uint32_t meta_kms_mode_create_blob_id (MetaKmsMode *mode,
- GError **error);
-
-void meta_kms_mode_free (MetaKmsMode *mode);
-
-MetaKmsMode * meta_kms_mode_new (MetaKmsImplDevice *impl_device,
- const drmModeModeInfo *drm_mode,
- MetaKmsModeFlag flags);
-
-#endif /* META_KMS_MODE_PRIVATE_H */
diff --git a/src/backends/native/meta-kms-mode.c b/src/backends/native/meta-kms-mode.c
deleted file mode 100644
index 7094cd0da..000000000
--- a/src/backends/native/meta-kms-mode.c
+++ /dev/null
@@ -1,143 +0,0 @@
-/*
- * Copyright (C) 2020 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-
-#include "config.h"
-
-#include "backends/native/meta-kms-mode-private.h"
-
-#include "backends/native/meta-kms-impl-device.h"
-
-struct _MetaKmsMode
-{
- MetaKmsImplDevice *impl_device;
- MetaKmsModeFlag flags;
- drmModeModeInfo drm_mode;
-};
-
-uint32_t
-meta_kms_mode_create_blob_id (MetaKmsMode *mode,
- GError **error)
-{
- int fd;
- int ret;
- uint32_t blob_id;
-
- fd = meta_kms_impl_device_get_fd (mode->impl_device);
-
- ret = drmModeCreatePropertyBlob (fd,
- &mode->drm_mode,
- sizeof (mode->drm_mode),
- &blob_id);
- if (ret < 0)
- {
- g_set_error (error, G_IO_ERROR, g_io_error_from_errno (-ret),
- "drmModeCreatePropertyBlob: %s",
- g_strerror (-ret));
- return 0;
- }
-
- return blob_id;
-}
-
-const char *
-meta_kms_mode_get_name (MetaKmsMode *mode)
-{
- return mode->drm_mode.name;
-}
-
-MetaKmsModeFlag
-meta_kms_mode_get_flags (MetaKmsMode *mode)
-{
- return mode->flags;
-}
-
-const drmModeModeInfo *
-meta_kms_mode_get_drm_mode (MetaKmsMode *mode)
-{
- return &mode->drm_mode;
-}
-
-static gboolean
-meta_drm_mode_equal (const drmModeModeInfo *one,
- const drmModeModeInfo *two)
-{
- return (one->clock == two->clock &&
- one->hdisplay == two->hdisplay &&
- one->hsync_start == two->hsync_start &&
- one->hsync_end == two->hsync_end &&
- one->htotal == two->htotal &&
- one->hskew == two->hskew &&
- one->vdisplay == two->vdisplay &&
- one->vsync_start == two->vsync_start &&
- one->vsync_end == two->vsync_end &&
- one->vtotal == two->vtotal &&
- one->vscan == two->vscan &&
- one->vrefresh == two->vrefresh &&
- one->flags == two->flags &&
- one->type == two->type &&
- strncmp (one->name, two->name, DRM_DISPLAY_MODE_LEN) == 0);
-}
-
-gboolean
-meta_kms_mode_equal (MetaKmsMode *mode,
- MetaKmsMode *other_mode)
-{
- return meta_drm_mode_equal (&mode->drm_mode, &other_mode->drm_mode);
-}
-
-unsigned int
-meta_kms_mode_hash (MetaKmsMode *mode)
-{
- const drmModeModeInfo *drm_mode = &mode->drm_mode;
- unsigned int hash = 0;
-
- /*
- * We don't include the name in the hash because it's generally
- * derived from the other fields (hdisplay, vdisplay and flags)
- */
-
- hash ^= drm_mode->clock;
- hash ^= drm_mode->hdisplay ^ drm_mode->hsync_start ^ drm_mode->hsync_end;
- hash ^= drm_mode->vdisplay ^ drm_mode->vsync_start ^ drm_mode->vsync_end;
- hash ^= drm_mode->vrefresh;
- hash ^= drm_mode->flags ^ drm_mode->type;
-
- return hash;
-}
-
-void
-meta_kms_mode_free (MetaKmsMode *mode)
-{
- g_free (mode);
-}
-
-MetaKmsMode *
-meta_kms_mode_new (MetaKmsImplDevice *impl_device,
- const drmModeModeInfo *drm_mode,
- MetaKmsModeFlag flags)
-{
- MetaKmsMode *mode;
-
- mode = g_new0 (MetaKmsMode, 1);
- mode->impl_device = impl_device;
- mode->flags = flags;
- mode->drm_mode = *drm_mode;
-
- return mode;
-}
diff --git a/src/backends/native/meta-kms-mode.h b/src/backends/native/meta-kms-mode.h
deleted file mode 100644
index 40e844796..000000000
--- a/src/backends/native/meta-kms-mode.h
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Copyright (C) 2020 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-
-#ifndef META_KMS_MODE_H
-#define META_KMS_MODE_H
-
-#include <glib.h>
-#include <xf86drm.h>
-#include <xf86drmMode.h>
-
-#include "backends/native/meta-kms-types.h"
-
-typedef enum _MetaKmsModeFlag
-{
- META_KMS_MODE_FLAG_NONE = 0,
- META_KMS_MODE_FLAG_FALLBACK_LANDSCAPE = 1 << 0,
- META_KMS_MODE_FLAG_FALLBACK_PORTRAIT = 1 << 1,
-} MetaKmsModeFlag;
-
-const char * meta_kms_mode_get_name (MetaKmsMode *mode);
-
-MetaKmsModeFlag meta_kms_mode_get_flags (MetaKmsMode *mode);
-
-const drmModeModeInfo * meta_kms_mode_get_drm_mode (MetaKmsMode *mode);
-
-gboolean meta_kms_mode_equal (MetaKmsMode *mode,
- MetaKmsMode *other_mode);
-
-unsigned int meta_kms_mode_hash (MetaKmsMode *mode);
-
-#endif /* META_KMS_MODE_H */
diff --git a/src/backends/native/meta-kms-page-flip-private.h b/src/backends/native/meta-kms-page-flip-private.h
deleted file mode 100644
index b23272ad9..000000000
--- a/src/backends/native/meta-kms-page-flip-private.h
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Copyright (C) 2019 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-
-#ifndef META_KMS_PAGE_FLIP_H
-#define META_KMS_PAGE_FLIP_H
-
-#include <glib.h>
-
-#include "backends/native/meta-kms-types.h"
-
-typedef struct _MetaKmsPageFlipData MetaKmsPageFlipData;
-
-typedef void (* MetaPageFlipDataFeedbackFunc) (MetaKmsPageFlipData *page_flip_data);
-
-MetaKmsPageFlipData * meta_kms_page_flip_data_new (MetaKmsImplDevice *impl_device,
- MetaKmsCrtc *crtc);
-
-MetaKmsPageFlipData * meta_kms_page_flip_data_ref (MetaKmsPageFlipData *page_flip_data);
-
-void meta_kms_page_flip_data_unref (MetaKmsPageFlipData *page_flip_data);
-
-void meta_kms_page_flip_data_add_listener (MetaKmsPageFlipData *page_flip_data,
- const MetaKmsPageFlipListenerVtable *vtable,
- MetaKmsPageFlipListenerFlag flags,
- gpointer user_data,
- GDestroyNotify destroy_notify);
-
-MetaKmsImplDevice * meta_kms_page_flip_data_get_impl_device (MetaKmsPageFlipData *page_flip_data);
-
-MetaKmsCrtc * meta_kms_page_flip_data_get_crtc (MetaKmsPageFlipData *page_flip_data);
-
-void meta_kms_page_flip_data_set_timings_in_impl (MetaKmsPageFlipData *page_flip_data,
- unsigned int sequence,
- unsigned int sec,
- unsigned int usec);
-
-void meta_kms_page_flip_data_flipped_in_impl (MetaKmsPageFlipData *page_flip_data);
-
-void meta_kms_page_flip_data_mode_set_fallback_in_impl (MetaKmsPageFlipData *page_flip_data);
-
-void meta_kms_page_flip_data_discard_in_impl (MetaKmsPageFlipData *page_flip_data,
- const GError *error);
-
-void meta_kms_page_flip_data_take_error (MetaKmsPageFlipData *page_flip_data,
- GError *error);
-
-void meta_kms_page_flip_data_make_symbolic (MetaKmsPageFlipData *page_flip_data);
-
-#endif /* META_KMS_PAGE_FLIP_H */
diff --git a/src/backends/native/meta-kms-page-flip.c b/src/backends/native/meta-kms-page-flip.c
deleted file mode 100644
index 817f4e7c8..000000000
--- a/src/backends/native/meta-kms-page-flip.c
+++ /dev/null
@@ -1,288 +0,0 @@
-/*
- * Copyright (C) 2019 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-
-#include "config.h"
-
-#include "backends/native/meta-kms-page-flip-private.h"
-
-#include "backends/native/meta-kms-impl.h"
-#include "backends/native/meta-kms-private.h"
-#include "backends/native/meta-kms-update.h"
-
-typedef struct _MetaKmsPageFlipClosure
-{
- const MetaKmsPageFlipListenerVtable *vtable;
- MetaKmsPageFlipListenerFlag flags;
- gpointer user_data;
- GDestroyNotify destroy_notify;
-} MetaKmsPageFlipClosure;
-
-struct _MetaKmsPageFlipData
-{
- gatomicrefcount ref_count;
-
- MetaKmsImplDevice *impl_device;
- MetaKmsCrtc *crtc;
-
- GList *closures;
-
- unsigned int sequence;
- unsigned int sec;
- unsigned int usec;
-
- gboolean is_symbolic;
-
- GError *error;
-};
-
-static MetaKmsPageFlipClosure *
-meta_kms_page_flip_closure_new (const MetaKmsPageFlipListenerVtable *vtable,
- MetaKmsPageFlipListenerFlag flags,
- gpointer user_data,
- GDestroyNotify destroy_notify)
-{
- MetaKmsPageFlipClosure *closure;
-
- closure = g_new0 (MetaKmsPageFlipClosure, 1);
- *closure = (MetaKmsPageFlipClosure) {
- .vtable = vtable,
- .flags = flags,
- .user_data = user_data,
- .destroy_notify = destroy_notify,
- };
-
- return closure;
-}
-
-static void
-meta_kms_page_flip_closure_free (MetaKmsPageFlipClosure *closure)
-{
- g_clear_pointer (&closure->user_data, closure->destroy_notify);
- g_free (closure);
-}
-
-MetaKmsPageFlipData *
-meta_kms_page_flip_data_new (MetaKmsImplDevice *impl_device,
- MetaKmsCrtc *crtc)
-{
- MetaKmsPageFlipData *page_flip_data;
-
- page_flip_data = g_new0 (MetaKmsPageFlipData , 1);
- *page_flip_data = (MetaKmsPageFlipData) {
- .impl_device = impl_device,
- .crtc = crtc,
- };
- g_atomic_ref_count_init (&page_flip_data->ref_count);
-
- return page_flip_data;
-}
-
-MetaKmsPageFlipData *
-meta_kms_page_flip_data_ref (MetaKmsPageFlipData *page_flip_data)
-{
- g_atomic_ref_count_inc (&page_flip_data->ref_count);
-
- return page_flip_data;
-}
-
-void
-meta_kms_page_flip_data_unref (MetaKmsPageFlipData *page_flip_data)
-{
- if (g_atomic_ref_count_dec (&page_flip_data->ref_count))
- {
- g_list_free_full (page_flip_data->closures,
- (GDestroyNotify) meta_kms_page_flip_closure_free);
- g_clear_error (&page_flip_data->error);
- g_free (page_flip_data);
- }
-}
-
-void
-meta_kms_page_flip_data_add_listener (MetaKmsPageFlipData *page_flip_data,
- const MetaKmsPageFlipListenerVtable *vtable,
- MetaKmsPageFlipListenerFlag flags,
- gpointer user_data,
- GDestroyNotify destroy_notify)
-{
- MetaKmsPageFlipClosure *closure;
-
- closure = meta_kms_page_flip_closure_new (vtable, flags,
- user_data,
- destroy_notify);
- page_flip_data->closures = g_list_append (page_flip_data->closures, closure);
-}
-
-MetaKmsImplDevice *
-meta_kms_page_flip_data_get_impl_device (MetaKmsPageFlipData *page_flip_data)
-{
- return page_flip_data->impl_device;
-}
-
-MetaKmsCrtc *
-meta_kms_page_flip_data_get_crtc (MetaKmsPageFlipData *page_flip_data)
-{
- return page_flip_data->crtc;
-}
-
-static void
-meta_kms_page_flip_data_flipped (MetaKms *kms,
- gpointer user_data)
-{
- MetaKmsPageFlipData *page_flip_data = user_data;
- GList *l;
-
- meta_assert_not_in_kms_impl (kms);
-
- for (l = page_flip_data->closures; l; l = l->next)
- {
- MetaKmsPageFlipClosure *closure = l->data;
-
- if (page_flip_data->is_symbolic)
- {
- closure->vtable->ready (page_flip_data->crtc,
- closure->user_data);
- }
- else
- {
- closure->vtable->flipped (page_flip_data->crtc,
- page_flip_data->sequence,
- page_flip_data->sec,
- page_flip_data->usec,
- closure->user_data);
- }
- }
-}
-
-static MetaKms *
-meta_kms_from_impl_device (MetaKmsImplDevice *impl_device)
-{
- MetaKmsDevice *device = meta_kms_impl_device_get_device (impl_device);
-
- return meta_kms_device_get_kms (device);
-}
-
-void
-meta_kms_page_flip_data_set_timings_in_impl (MetaKmsPageFlipData *page_flip_data,
- unsigned int sequence,
- unsigned int sec,
- unsigned int usec)
-{
- MetaKms *kms = meta_kms_from_impl_device (page_flip_data->impl_device);
-
- meta_assert_in_kms_impl (kms);
-
- page_flip_data->sequence = sequence;
- page_flip_data->sec = sec;
- page_flip_data->usec = usec;
-}
-
-void
-meta_kms_page_flip_data_make_symbolic (MetaKmsPageFlipData *page_flip_data)
-{
- page_flip_data->is_symbolic = TRUE;
-}
-
-void
-meta_kms_page_flip_data_flipped_in_impl (MetaKmsPageFlipData *page_flip_data)
-{
- MetaKms *kms = meta_kms_from_impl_device (page_flip_data->impl_device);
-
- meta_assert_in_kms_impl (kms);
-
- meta_kms_queue_callback (kms,
- meta_kms_page_flip_data_flipped,
- page_flip_data,
- (GDestroyNotify) meta_kms_page_flip_data_unref);
-}
-
-static void
-meta_kms_page_flip_data_mode_set_fallback (MetaKms *kms,
- gpointer user_data)
-{
- MetaKmsPageFlipData *page_flip_data = user_data;
- GList *l;
-
- meta_assert_not_in_kms_impl (kms);
-
- for (l = page_flip_data->closures; l; l = l->next)
- {
- MetaKmsPageFlipClosure *closure = l->data;
-
- closure->vtable->mode_set_fallback (page_flip_data->crtc,
- closure->user_data);
- }
-}
-
-void
-meta_kms_page_flip_data_mode_set_fallback_in_impl (MetaKmsPageFlipData *page_flip_data)
-{
- MetaKms *kms = meta_kms_from_impl_device (page_flip_data->impl_device);
-
- meta_assert_in_kms_impl (kms);
-
- meta_kms_queue_callback (kms,
- meta_kms_page_flip_data_mode_set_fallback,
- page_flip_data,
- (GDestroyNotify) meta_kms_page_flip_data_unref);
-}
-
-static void
-meta_kms_page_flip_data_discard (MetaKms *kms,
- gpointer user_data)
-{
- MetaKmsPageFlipData *page_flip_data = user_data;
- GList *l;
-
- meta_assert_not_in_kms_impl (kms);
-
- for (l = page_flip_data->closures; l; l = l->next)
- {
- MetaKmsPageFlipClosure *closure = l->data;
-
- closure->vtable->discarded (page_flip_data->crtc,
- closure->user_data,
- page_flip_data->error);
- }
-}
-
-void
-meta_kms_page_flip_data_take_error (MetaKmsPageFlipData *page_flip_data,
- GError *error)
-{
- g_assert (!page_flip_data->error);
-
- page_flip_data->error = error;
-}
-
-void
-meta_kms_page_flip_data_discard_in_impl (MetaKmsPageFlipData *page_flip_data,
- const GError *error)
-{
- MetaKms *kms = meta_kms_from_impl_device (page_flip_data->impl_device);
-
- meta_assert_in_kms_impl (kms);
-
- if (error)
- meta_kms_page_flip_data_take_error (page_flip_data, g_error_copy (error));
-
- meta_kms_queue_callback (kms,
- meta_kms_page_flip_data_discard,
- page_flip_data,
- (GDestroyNotify) meta_kms_page_flip_data_unref);
-}
diff --git a/src/backends/native/meta-kms-plane-private.h b/src/backends/native/meta-kms-plane-private.h
deleted file mode 100644
index 92f9cfcc9..000000000
--- a/src/backends/native/meta-kms-plane-private.h
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * Copyright (C) 2018-2019 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-
-#ifndef META_KMS_PLANE_PRIVATE_H
-#define META_KMS_PLANE_PRIVATE_H
-
-#include <xf86drm.h>
-#include <xf86drmMode.h>
-
-#include "backends/native/meta-kms-plane.h"
-#include "backends/native/meta-kms-types.h"
-
-typedef enum _MetaKmsPlaneProp
-{
- META_KMS_PLANE_PROP_TYPE = 0,
- META_KMS_PLANE_PROP_ROTATION,
- META_KMS_PLANE_PROP_IN_FORMATS,
- META_KMS_PLANE_PROP_SRC_X,
- META_KMS_PLANE_PROP_SRC_Y,
- META_KMS_PLANE_PROP_SRC_W,
- META_KMS_PLANE_PROP_SRC_H,
- META_KMS_PLANE_PROP_CRTC_X,
- META_KMS_PLANE_PROP_CRTC_Y,
- META_KMS_PLANE_PROP_CRTC_W,
- META_KMS_PLANE_PROP_CRTC_H,
- META_KMS_PLANE_PROP_FB_ID,
- META_KMS_PLANE_PROP_CRTC_ID,
- META_KMS_PLANE_N_PROPS
-} MetaKmsPlaneProp;
-
-MetaKmsPlane * meta_kms_plane_new (MetaKmsPlaneType type,
- MetaKmsImplDevice *impl_device,
- drmModePlane *drm_plane,
- drmModeObjectProperties *drm_plane_props);
-
-MetaKmsPlane * meta_kms_plane_new_fake (MetaKmsPlaneType type,
- MetaKmsCrtc *crtc);
-
-uint32_t meta_kms_plane_get_prop_id (MetaKmsPlane *plane,
- MetaKmsPlaneProp prop);
-
-const char * meta_kms_plane_get_prop_name (MetaKmsPlane *plane,
- MetaKmsPlaneProp prop);
-
-MetaKmsPropType meta_kms_plane_get_prop_internal_type (MetaKmsPlane *plane,
- MetaKmsPlaneProp prop);
-
-#endif /* META_KMS_PLANE_PRIVATE_H */
diff --git a/src/backends/native/meta-kms-plane.c b/src/backends/native/meta-kms-plane.c
deleted file mode 100644
index 73fab7d8f..000000000
--- a/src/backends/native/meta-kms-plane.c
+++ /dev/null
@@ -1,537 +0,0 @@
-/*
- * Copyright (C) 2013-2019 Red Hat
- * Copyright (C) 2018 DisplayLink (UK) Ltd.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-
-#include "config.h"
-
-#include "backends/native/meta-kms-plane-private.h"
-
-#include <drm_fourcc.h>
-#include <stdio.h>
-
-#include "backends/meta-monitor-transform.h"
-#include "backends/native/meta-kms-crtc.h"
-#include "backends/native/meta-kms-impl-device.h"
-#include "backends/native/meta-kms-update-private.h"
-
-typedef struct _MetaKmsPlanePropTable
-{
- MetaKmsProp props[META_KMS_PLANE_N_PROPS];
-} MetaKmsPlanePropTable;
-
-struct _MetaKmsPlane
-{
- GObject parent;
-
- MetaKmsPlaneType type;
- gboolean is_fake;
-
- uint32_t id;
-
- uint32_t possible_crtcs;
-
- uint32_t rotation_map[META_MONITOR_N_TRANSFORMS];
- uint32_t all_hw_transforms;
-
- /*
- * primary plane's supported formats and maybe modifiers
- * key: GUINT_TO_POINTER (format)
- * value: owned GArray* (uint64_t modifier), or NULL
- */
- GHashTable *formats_modifiers;
-
- MetaKmsPlanePropTable prop_table;
-
- MetaKmsDevice *device;
-};
-
-G_DEFINE_TYPE (MetaKmsPlane, meta_kms_plane, G_TYPE_OBJECT)
-
-MetaKmsDevice *
-meta_kms_plane_get_device (MetaKmsPlane *plane)
-{
- return plane->device;
-}
-
-uint32_t
-meta_kms_plane_get_id (MetaKmsPlane *plane)
-{
- g_return_val_if_fail (!plane->is_fake, 0);
-
- return plane->id;
-}
-
-MetaKmsPlaneType
-meta_kms_plane_get_plane_type (MetaKmsPlane *plane)
-{
- return plane->type;
-}
-
-uint32_t
-meta_kms_plane_get_prop_id (MetaKmsPlane *plane,
- MetaKmsPlaneProp prop)
-{
- return plane->prop_table.props[prop].prop_id;
-}
-
-const char *
-meta_kms_plane_get_prop_name (MetaKmsPlane *plane,
- MetaKmsPlaneProp prop)
-{
- return plane->prop_table.props[prop].name;
-}
-
-MetaKmsPropType
-meta_kms_plane_get_prop_internal_type (MetaKmsPlane *plane,
- MetaKmsPlaneProp prop)
-{
- return plane->prop_table.props[prop].internal_type;
-}
-
-void
-meta_kms_plane_update_set_rotation (MetaKmsPlane *plane,
- MetaKmsPlaneAssignment *plane_assignment,
- MetaMonitorTransform transform)
-{
- g_return_if_fail (meta_kms_plane_is_transform_handled (plane, transform));
-
- meta_kms_plane_assignment_set_rotation (plane_assignment,
- plane->rotation_map[transform]);
-}
-
-gboolean
-meta_kms_plane_is_transform_handled (MetaKmsPlane *plane,
- MetaMonitorTransform transform)
-{
- switch (transform)
- {
- case META_MONITOR_TRANSFORM_NORMAL:
- case META_MONITOR_TRANSFORM_180:
- case META_MONITOR_TRANSFORM_FLIPPED:
- case META_MONITOR_TRANSFORM_FLIPPED_180:
- break;
- case META_MONITOR_TRANSFORM_90:
- case META_MONITOR_TRANSFORM_270:
- case META_MONITOR_TRANSFORM_FLIPPED_90:
- case META_MONITOR_TRANSFORM_FLIPPED_270:
- /*
- * Blacklist these transforms as testing shows that they don't work
- * anyway, e.g. due to the wrong buffer modifiers. They might as well be
- * less optimal due to the complexity dealing with rotation at scan-out,
- * potentially resulting in higher power consumption.
- */
- return FALSE;
- }
- return plane->all_hw_transforms & (1 << transform);
-}
-
-GArray *
-meta_kms_plane_get_modifiers_for_format (MetaKmsPlane *plane,
- uint32_t format)
-{
- return g_hash_table_lookup (plane->formats_modifiers,
- GUINT_TO_POINTER (format));
-}
-
-GArray *
-meta_kms_plane_copy_drm_format_list (MetaKmsPlane *plane)
-{
- GArray *formats;
- GHashTableIter it;
- gpointer key;
- unsigned int n_formats_modifiers;
-
- n_formats_modifiers = g_hash_table_size (plane->formats_modifiers);
- formats = g_array_sized_new (FALSE, FALSE,
- sizeof (uint32_t),
- n_formats_modifiers);
- g_hash_table_iter_init (&it, plane->formats_modifiers);
- while (g_hash_table_iter_next (&it, &key, NULL))
- {
- uint32_t drm_format = GPOINTER_TO_UINT (key);
-
- g_array_append_val (formats, drm_format);
- }
-
- return formats;
-}
-
-gboolean
-meta_kms_plane_is_format_supported (MetaKmsPlane *plane,
- uint32_t drm_format)
-{
- return g_hash_table_lookup_extended (plane->formats_modifiers,
- GUINT_TO_POINTER (drm_format),
- NULL, NULL);
-}
-
-gboolean
-meta_kms_plane_is_usable_with (MetaKmsPlane *plane,
- MetaKmsCrtc *crtc)
-{
- return !!(plane->possible_crtcs & (1 << meta_kms_crtc_get_idx (crtc)));
-}
-
-static void
-parse_rotations (MetaKmsImplDevice *impl_device,
- MetaKmsProp *prop,
- drmModePropertyPtr drm_prop,
- uint64_t drm_prop_value,
- gpointer user_data)
-{
- MetaKmsPlane *plane = user_data;
- int i;
-
- for (i = 0; i < drm_prop->count_enums; i++)
- {
- MetaMonitorTransform transform = -1;
-
- if (strcmp (drm_prop->enums[i].name, "rotate-0") == 0)
- transform = META_MONITOR_TRANSFORM_NORMAL;
- else if (strcmp (drm_prop->enums[i].name, "rotate-90") == 0)
- transform = META_MONITOR_TRANSFORM_90;
- else if (strcmp (drm_prop->enums[i].name, "rotate-180") == 0)
- transform = META_MONITOR_TRANSFORM_180;
- else if (strcmp (drm_prop->enums[i].name, "rotate-270") == 0)
- transform = META_MONITOR_TRANSFORM_270;
-
- if (transform != -1)
- {
- plane->all_hw_transforms |= 1 << transform;
- plane->rotation_map[transform] = 1 << drm_prop->enums[i].value;
- }
- }
-}
-
-static inline uint32_t *
-drm_formats_ptr (struct drm_format_modifier_blob *blob)
-{
- return (uint32_t *) (((char *) blob) + blob->formats_offset);
-}
-
-static inline struct drm_format_modifier *
-drm_modifiers_ptr (struct drm_format_modifier_blob *blob)
-{
- return (struct drm_format_modifier *) (((char *) blob) +
- blob->modifiers_offset);
-}
-
-static void
-free_modifier_array (GArray *array)
-{
- if (!array)
- return;
-
- g_array_free (array, TRUE);
-}
-
-static void
-parse_formats (MetaKmsImplDevice *impl_device,
- MetaKmsProp *prop,
- drmModePropertyPtr drm_prop,
- uint64_t drm_prop_value,
- gpointer user_data)
-{
- MetaKmsPlane *plane = user_data;
- uint64_t blob_id;
- int fd;
- drmModePropertyBlobPtr blob;
- struct drm_format_modifier_blob *blob_fmt;
- uint32_t *formats;
- struct drm_format_modifier *drm_modifiers;
- unsigned int fmt_i, mod_i;
-
- g_return_if_fail (g_hash_table_size (plane->formats_modifiers) == 0);
-
- blob_id = drm_prop_value;
- if (blob_id == 0)
- return;
-
- fd = meta_kms_impl_device_get_fd (impl_device);
- blob = drmModeGetPropertyBlob (fd, blob_id);
- if (!blob)
- return;
-
- if (blob->length < sizeof (struct drm_format_modifier_blob))
- {
- drmModeFreePropertyBlob (blob);
- return;
- }
-
- blob_fmt = blob->data;
-
- formats = drm_formats_ptr (blob_fmt);
- drm_modifiers = drm_modifiers_ptr (blob_fmt);
-
- for (fmt_i = 0; fmt_i < blob_fmt->count_formats; fmt_i++)
- {
- GArray *modifiers = g_array_new (FALSE, FALSE, sizeof (uint64_t));
-
- for (mod_i = 0; mod_i < blob_fmt->count_modifiers; mod_i++)
- {
- struct drm_format_modifier *drm_modifier = &drm_modifiers[mod_i];
-
- /*
- * The modifier advertisement blob is partitioned into groups of
- * 64 formats.
- */
- if (fmt_i < drm_modifier->offset || fmt_i > drm_modifier->offset + 63)
- continue;
-
- if (!(drm_modifier->formats & (1 << (fmt_i - drm_modifier->offset))))
- continue;
-
- g_array_append_val (modifiers, drm_modifier->modifier);
- }
-
- if (modifiers->len == 0)
- {
- free_modifier_array (modifiers);
- modifiers = NULL;
- }
-
- g_hash_table_insert (plane->formats_modifiers,
- GUINT_TO_POINTER (formats[fmt_i]),
- modifiers);
- }
-
- drmModeFreePropertyBlob (blob);
-}
-
-static void
-set_formats_from_array (MetaKmsPlane *plane,
- const uint32_t *formats,
- size_t n_formats)
-{
- size_t i;
-
- for (i = 0; i < n_formats; i++)
- {
- g_hash_table_insert (plane->formats_modifiers,
- GUINT_TO_POINTER (formats[i]), NULL);
- }
-}
-
-/*
- * In case the DRM driver does not expose a format list for the
- * primary plane (does not support universal planes nor
- * IN_FORMATS property), hardcode something that is probably supported.
- */
-static const uint32_t drm_default_formats[] =
- {
- /* The format everything should always support by convention */
- DRM_FORMAT_XRGB8888,
-#if G_BYTE_ORDER == G_LITTLE_ENDIAN
- /* OpenGL GL_RGBA, GL_UNSIGNED_BYTE format, hopefully supported */
- DRM_FORMAT_XBGR8888
-#endif
- };
-
-static void
-init_legacy_formats (MetaKmsPlane *plane,
- MetaKmsImplDevice *impl_device,
- drmModePlane *drm_plane,
- drmModeObjectProperties *drm_plane_props)
-{
- if (g_hash_table_size (plane->formats_modifiers) == 0)
- {
- set_formats_from_array (plane,
- drm_plane->formats,
- drm_plane->count_formats);
- }
-
- /* final formats fallback to something hardcoded */
- if (g_hash_table_size (plane->formats_modifiers) == 0)
- {
- set_formats_from_array (plane,
- drm_default_formats,
- G_N_ELEMENTS (drm_default_formats));
- }
-}
-
-static void
-init_properties (MetaKmsPlane *plane,
- MetaKmsImplDevice *impl_device,
- drmModePlane *drm_plane,
- drmModeObjectProperties *drm_plane_props)
-{
- MetaKmsPlanePropTable *prop_table = &plane->prop_table;
-
- *prop_table = (MetaKmsPlanePropTable) {
- .props = {
- [META_KMS_PLANE_PROP_TYPE] =
- {
- .name = "type",
- .type = DRM_MODE_PROP_ENUM,
- },
- [META_KMS_PLANE_PROP_ROTATION] =
- {
- .name = "rotation",
- .type = DRM_MODE_PROP_BITMASK,
- .parse = parse_rotations,
- },
- [META_KMS_PLANE_PROP_IN_FORMATS] =
- {
- .name = "IN_FORMATS",
- .type = DRM_MODE_PROP_BLOB,
- .parse = parse_formats,
- },
- [META_KMS_PLANE_PROP_SRC_X] =
- {
- .name = "SRC_X",
- .type = DRM_MODE_PROP_RANGE,
- .internal_type = META_KMS_PROP_TYPE_FIXED_16,
- },
- [META_KMS_PLANE_PROP_SRC_Y] =
- {
- .name = "SRC_Y",
- .type = DRM_MODE_PROP_RANGE,
- .internal_type = META_KMS_PROP_TYPE_FIXED_16,
- },
- [META_KMS_PLANE_PROP_SRC_W] =
- {
- .name = "SRC_W",
- .type = DRM_MODE_PROP_RANGE,
- .internal_type = META_KMS_PROP_TYPE_FIXED_16,
- },
- [META_KMS_PLANE_PROP_SRC_H] =
- {
- .name = "SRC_H",
- .type = DRM_MODE_PROP_RANGE,
- .internal_type = META_KMS_PROP_TYPE_FIXED_16,
- },
- [META_KMS_PLANE_PROP_CRTC_X] =
- {
- .name = "CRTC_X",
- .type = DRM_MODE_PROP_SIGNED_RANGE,
- },
- [META_KMS_PLANE_PROP_CRTC_Y] =
- {
- .name = "CRTC_Y",
- .type = DRM_MODE_PROP_SIGNED_RANGE,
- },
- [META_KMS_PLANE_PROP_CRTC_W] =
- {
- .name = "CRTC_W",
- .type = DRM_MODE_PROP_RANGE,
- },
- [META_KMS_PLANE_PROP_CRTC_H] =
- {
- .name = "CRTC_H",
- .type = DRM_MODE_PROP_RANGE,
- },
- [META_KMS_PLANE_PROP_FB_ID] =
- {
- .name = "FB_ID",
- .type = DRM_MODE_PROP_OBJECT,
- },
- [META_KMS_PLANE_PROP_CRTC_ID] =
- {
- .name = "CRTC_ID",
- .type = DRM_MODE_PROP_OBJECT,
- },
- }
- };
-
- meta_kms_impl_device_init_prop_table (impl_device,
- drm_plane_props->props,
- drm_plane_props->prop_values,
- drm_plane_props->count_props,
- plane->prop_table.props,
- META_KMS_PLANE_N_PROPS,
- plane);
-}
-
-MetaKmsPlane *
-meta_kms_plane_new (MetaKmsPlaneType type,
- MetaKmsImplDevice *impl_device,
- drmModePlane *drm_plane,
- drmModeObjectProperties *drm_plane_props)
-{
- MetaKmsPlane *plane;
-
- plane = g_object_new (META_TYPE_KMS_PLANE, NULL);
- plane->type = type;
- plane->id = drm_plane->plane_id;
- plane->possible_crtcs = drm_plane->possible_crtcs;
- plane->device = meta_kms_impl_device_get_device (impl_device);
-
- init_properties (plane, impl_device, drm_plane, drm_plane_props);
- init_legacy_formats (plane, impl_device, drm_plane, drm_plane_props);
-
- return plane;
-}
-
-MetaKmsPlane *
-meta_kms_plane_new_fake (MetaKmsPlaneType type,
- MetaKmsCrtc *crtc)
-{
- MetaKmsPlane *plane;
-
- static const uint32_t fake_plane_drm_formats[] =
- {
- DRM_FORMAT_XRGB8888,
- DRM_FORMAT_ARGB8888,
-#if G_BYTE_ORDER == G_LITTLE_ENDIAN
- /* OpenGL GL_RGBA, GL_UNSIGNED_BYTE format, hopefully supported */
- DRM_FORMAT_XBGR8888,
- DRM_FORMAT_ABGR8888
-#endif
- };
-
- plane = g_object_new (META_TYPE_KMS_PLANE, NULL);
- plane->type = type;
- plane->is_fake = TRUE;
- plane->possible_crtcs = 1 << meta_kms_crtc_get_idx (crtc);
- plane->device = meta_kms_crtc_get_device (crtc);
-
- set_formats_from_array (plane,
- fake_plane_drm_formats,
- G_N_ELEMENTS (fake_plane_drm_formats));
-
- return plane;
-}
-
-static void
-meta_kms_plane_finalize (GObject *object)
-{
- MetaKmsPlane *plane = META_KMS_PLANE (object);
-
- g_hash_table_destroy (plane->formats_modifiers);
-
- G_OBJECT_CLASS (meta_kms_plane_parent_class)->finalize (object);
-}
-
-static void
-meta_kms_plane_init (MetaKmsPlane *plane)
-{
- plane->formats_modifiers =
- g_hash_table_new_full (g_direct_hash,
- g_direct_equal,
- NULL,
- (GDestroyNotify) free_modifier_array);
-}
-
-static void
-meta_kms_plane_class_init (MetaKmsPlaneClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- object_class->finalize = meta_kms_plane_finalize;
-}
diff --git a/src/backends/native/meta-kms-plane.h b/src/backends/native/meta-kms-plane.h
deleted file mode 100644
index 941c16680..000000000
--- a/src/backends/native/meta-kms-plane.h
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Copyright (C) 2018 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-
-#ifndef META_KMS_PLANE_H
-#define META_KMS_PLANE_H
-
-#include <glib-object.h>
-#include <stdint.h>
-#include <xf86drmMode.h>
-
-#include "backends/native/meta-kms-types.h"
-#include "backends/meta-monitor-transform.h"
-
-enum _MetaKmsPlaneType
-{
- META_KMS_PLANE_TYPE_PRIMARY,
- META_KMS_PLANE_TYPE_CURSOR,
- META_KMS_PLANE_TYPE_OVERLAY,
-};
-
-#define META_TYPE_KMS_PLANE meta_kms_plane_get_type ()
-G_DECLARE_FINAL_TYPE (MetaKmsPlane, meta_kms_plane,
- META, KMS_PLANE, GObject)
-
-MetaKmsDevice * meta_kms_plane_get_device (MetaKmsPlane *plane);
-
-uint32_t meta_kms_plane_get_id (MetaKmsPlane *plane);
-
-MetaKmsPlaneType meta_kms_plane_get_plane_type (MetaKmsPlane *plane);
-
-gboolean meta_kms_plane_is_transform_handled (MetaKmsPlane *plane,
- MetaMonitorTransform transform);
-
-GArray * meta_kms_plane_get_modifiers_for_format (MetaKmsPlane *plane,
- uint32_t format);
-
-GArray * meta_kms_plane_copy_drm_format_list (MetaKmsPlane *plane);
-
-gboolean meta_kms_plane_is_format_supported (MetaKmsPlane *plane,
- uint32_t format);
-
-gboolean meta_kms_plane_is_usable_with (MetaKmsPlane *plane,
- MetaKmsCrtc *crtc);
-
-void meta_kms_plane_update_set_rotation (MetaKmsPlane *plane,
- MetaKmsPlaneAssignment *plane_assignment,
- MetaMonitorTransform transform);
-
-#endif /* META_KMS_PLANE_H */
diff --git a/src/backends/native/meta-kms-private.h b/src/backends/native/meta-kms-private.h
deleted file mode 100644
index 8d0954c72..000000000
--- a/src/backends/native/meta-kms-private.h
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Copyright (C) 2019 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-
-#ifndef META_KMS_PRIVATE_H
-#define META_KMS_PRIVATE_H
-
-#include "backends/native/meta-kms.h"
-
-#include "backends/native/meta-kms-types.h"
-
-typedef void (* MetaKmsCallback) (MetaKms *kms,
- gpointer user_data);
-
-typedef gpointer (* MetaKmsImplTaskFunc) (MetaKmsImpl *impl,
- gpointer user_data,
- GError **error);
-
-void meta_kms_queue_callback (MetaKms *kms,
- MetaKmsCallback callback,
- gpointer user_data,
- GDestroyNotify user_data_destroy);
-
-gpointer meta_kms_run_impl_task_sync (MetaKms *kms,
- MetaKmsImplTaskFunc func,
- gpointer user_data,
- GError **error);
-
-GSource * meta_kms_add_source_in_impl (MetaKms *kms,
- GSourceFunc func,
- gpointer user_data,
- GDestroyNotify user_data_destroy);
-
-GSource * meta_kms_register_fd_in_impl (MetaKms *kms,
- int fd,
- MetaKmsImplTaskFunc dispatch,
- gpointer user_data);
-
-gboolean meta_kms_in_impl_task (MetaKms *kms);
-
-gboolean meta_kms_is_waiting_for_impl_task (MetaKms *kms);
-
-#define meta_assert_in_kms_impl(kms) \
- g_assert (meta_kms_in_impl_task (kms))
-#define meta_assert_not_in_kms_impl(kms) \
- g_assert (!meta_kms_in_impl_task (kms))
-#define meta_assert_is_waiting_for_kms_impl_task(kms) \
- g_assert (meta_kms_is_waiting_for_impl_task (kms))
-
-#endif /* META_KMS_PRIVATE_H */
diff --git a/src/backends/native/meta-kms-types.h b/src/backends/native/meta-kms-types.h
deleted file mode 100644
index 5786ff51f..000000000
--- a/src/backends/native/meta-kms-types.h
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Copyright (C) 2019 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-
-#ifndef META_KMS_IMPL_TYPES_H
-#define META_KMS_IMPL_TYPES_H
-
-#include <stdint.h>
-
-typedef struct _MetaKms MetaKms;
-typedef struct _MetaKmsDevice MetaKmsDevice;
-
-typedef struct _MetaKmsPlane MetaKmsPlane;
-typedef struct _MetaKmsCrtc MetaKmsCrtc;
-typedef struct _MetaKmsConnector MetaKmsConnector;
-
-typedef struct _MetaKmsUpdate MetaKmsUpdate;
-typedef struct _MetaKmsPlaneAssignment MetaKmsPlaneAssignment;
-typedef struct _MetaKmsModeSet MetaKmsModeSet;
-
-typedef struct _MetaKmsMode MetaKmsMode;
-
-typedef struct _MetaKmsFeedback MetaKmsFeedback;
-
-typedef struct _MetaKmsPageFlipListenerVtable MetaKmsPageFlipListenerVtable;
-typedef enum _MetaKmsPageFlipListenerFlag MetaKmsPageFlipListenerFlag;
-
-typedef struct _MetaKmsImpl MetaKmsImpl;
-typedef struct _MetaKmsImplDevice MetaKmsImplDevice;
-
-/* 16:16 fixed point */
-typedef int32_t MetaFixed16;
-
-typedef struct _MetaFixed16Rectangle
-{
- MetaFixed16 x;
- MetaFixed16 y;
- MetaFixed16 width;
- MetaFixed16 height;
-} MetaFixed16Rectangle;
-
-typedef enum _MetaKmsDeviceFlag
-{
- META_KMS_DEVICE_FLAG_NONE = 0,
- META_KMS_DEVICE_FLAG_BOOT_VGA = 1 << 0,
- META_KMS_DEVICE_FLAG_PLATFORM_DEVICE = 1 << 1,
- META_KMS_DEVICE_FLAG_DISABLE_MODIFIERS = 1 << 2,
- META_KMS_DEVICE_FLAG_PREFERRED_PRIMARY = 1 << 3,
- META_KMS_DEVICE_FLAG_NO_MODE_SETTING = 1 << 4,
-} MetaKmsDeviceFlag;
-
-typedef enum _MetaKmsPlaneType MetaKmsPlaneType;
-
-typedef enum _MetaKmsPropType
-{
- META_KMS_PROP_TYPE_RAW = 0,
- META_KMS_PROP_TYPE_FIXED_16,
-} MetaKmsPropType;
-
-#endif /* META_KMS_IMPL_TYPES_H */
diff --git a/src/backends/native/meta-kms-update-private.h b/src/backends/native/meta-kms-update-private.h
deleted file mode 100644
index 22491ece2..000000000
--- a/src/backends/native/meta-kms-update-private.h
+++ /dev/null
@@ -1,157 +0,0 @@
-/*
- * Copyright (C) 2019 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-
-#ifndef META_KMS_UPDATE_PRIVATE_H
-#define META_KMS_UPDATE_PRIVATE_H
-
-#include <glib.h>
-#include <stdint.h>
-
-#include "backends/native/meta-kms-types.h"
-#include "backends/native/meta-kms-update.h"
-
-typedef struct _MetaKmsFeedback
-{
- MetaKmsFeedbackResult result;
-
- GList *failed_planes;
- GError *error;
-} MetaKmsFeedback;
-
-typedef struct _MetaKmsPlaneAssignment
-{
- MetaKmsUpdate *update;
- MetaKmsCrtc *crtc;
- MetaKmsPlane *plane;
- MetaDrmBuffer *buffer;
- MetaFixed16Rectangle src_rect;
- MetaRectangle dst_rect;
- MetaKmsAssignPlaneFlag flags;
-
- uint64_t rotation;
-
- struct {
- gboolean is_valid;
- int x;
- int y;
- } cursor_hotspot;
-} MetaKmsPlaneAssignment;
-
-typedef struct _MetaKmsModeSet
-{
- MetaKmsCrtc *crtc;
- GList *connectors;
- MetaKmsMode *mode;
-} MetaKmsModeSet;
-
-typedef struct _MetaKmsConnectorUpdate
-{
- MetaKmsConnector *connector;
-
- struct {
- gboolean has_update;
- gboolean is_active;
- uint64_t hborder;
- uint64_t vborder;
- } underscanning;
-} MetaKmsConnectorUpdate;
-
-typedef struct _MetaKmsPageFlipListener
-{
- MetaKmsCrtc *crtc;
- const MetaKmsPageFlipListenerVtable *vtable;
- MetaKmsPageFlipListenerFlag flags;
- gpointer user_data;
- GDestroyNotify destroy_notify;
-} MetaKmsPageFlipListener;
-
-typedef struct _MetaKmsResultListener
-{
- MetaKmsResultListenerFunc func;
- gpointer user_data;
-} MetaKmsResultListener;
-
-typedef struct _MetaKmsCustomPageFlip
-{
- MetaKmsCustomPageFlipFunc func;
- gpointer user_data;
-} MetaKmsCustomPageFlip;
-
-void meta_kms_plane_feedback_free (MetaKmsPlaneFeedback *plane_feedback);
-
-MetaKmsPlaneFeedback * meta_kms_plane_feedback_new_take_error (MetaKmsPlane *plane,
- MetaKmsCrtc *crtc,
- GError *error);
-
-MetaKmsFeedback * meta_kms_feedback_new_passed (GList *failed_planes);
-
-MetaKmsFeedback * meta_kms_feedback_new_failed (GList *failed_planes,
- GError *error);
-
-void meta_kms_update_lock (MetaKmsUpdate *update);
-
-void meta_kms_update_unlock (MetaKmsUpdate *update);
-
-gboolean meta_kms_update_is_locked (MetaKmsUpdate *update);
-
-uint64_t meta_kms_update_get_sequence_number (MetaKmsUpdate *update);
-
-MetaKmsDevice * meta_kms_update_get_device (MetaKmsUpdate *update);
-
-void meta_kms_plane_assignment_set_rotation (MetaKmsPlaneAssignment *plane_assignment,
- uint64_t rotation);
-
-MetaKmsPlaneAssignment * meta_kms_update_get_primary_plane_assignment (MetaKmsUpdate *update,
- MetaKmsCrtc *crtc);
-
-GList * meta_kms_update_get_plane_assignments (MetaKmsUpdate *update);
-
-GList * meta_kms_update_get_mode_sets (MetaKmsUpdate *update);
-
-GList * meta_kms_update_get_page_flip_listeners (MetaKmsUpdate *update);
-
-void meta_kms_update_drop_defunct_page_flip_listeners (MetaKmsUpdate *update);
-
-GList * meta_kms_update_get_connector_updates (MetaKmsUpdate *update);
-
-GList * meta_kms_update_get_crtc_gammas (MetaKmsUpdate *update);
-
-gboolean meta_kms_update_is_power_save (MetaKmsUpdate *update);
-
-MetaKmsCustomPageFlip * meta_kms_update_take_custom_page_flip_func (MetaKmsUpdate *update);
-
-void meta_kms_update_drop_plane_assignment (MetaKmsUpdate *update,
- MetaKmsPlane *plane);
-
-GList * meta_kms_update_take_result_listeners (MetaKmsUpdate *update);
-
-void meta_kms_result_listener_notify (MetaKmsResultListener *listener,
- const MetaKmsFeedback *feedback);
-
-void meta_kms_result_listener_free (MetaKmsResultListener *listener);
-
-void meta_kms_custom_page_flip_free (MetaKmsCustomPageFlip *custom_page_flip);
-
-G_DEFINE_AUTOPTR_CLEANUP_FUNC (MetaKmsPlaneFeedback,
- meta_kms_plane_feedback_free)
-
-G_DEFINE_AUTOPTR_CLEANUP_FUNC (MetaKmsCustomPageFlip,
- meta_kms_custom_page_flip_free)
-
-#endif /* META_KMS_UPDATE_PRIVATE_H */
diff --git a/src/backends/native/meta-kms-update.c b/src/backends/native/meta-kms-update.c
deleted file mode 100644
index be6eaefcc..000000000
--- a/src/backends/native/meta-kms-update.c
+++ /dev/null
@@ -1,645 +0,0 @@
-/*
- * Copyright (C) 2018 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-
-#include "config.h"
-
-#include "backends/native/meta-kms-update.h"
-#include "backends/native/meta-kms-update-private.h"
-
-#include "backends/meta-display-config-shared.h"
-#include "backends/native/meta-kms-connector.h"
-#include "backends/native/meta-kms-crtc.h"
-#include "backends/native/meta-kms-mode-private.h"
-#include "backends/native/meta-kms-plane.h"
-
-struct _MetaKmsUpdate
-{
- MetaKmsDevice *device;
-
- gboolean is_locked;
- uint64_t sequence_number;
-
- gboolean power_save;
-
- GList *mode_sets;
- GList *plane_assignments;
- GList *connector_updates;
- GList *crtc_gammas;
-
- MetaKmsCustomPageFlip *custom_page_flip;
-
- GList *page_flip_listeners;
- GList *result_listeners;
-};
-
-void
-meta_kms_plane_feedback_free (MetaKmsPlaneFeedback *plane_feedback)
-{
- g_error_free (plane_feedback->error);
- g_free (plane_feedback);
-}
-
-MetaKmsPlaneFeedback *
-meta_kms_plane_feedback_new_take_error (MetaKmsPlane *plane,
- MetaKmsCrtc *crtc,
- GError *error)
-{
- MetaKmsPlaneFeedback *plane_feedback;
-
- plane_feedback = g_new0 (MetaKmsPlaneFeedback, 1);
- *plane_feedback = (MetaKmsPlaneFeedback) {
- .plane = plane,
- .crtc = crtc,
- .error = error,
- };
-
- return plane_feedback;
-}
-
-MetaKmsFeedback *
-meta_kms_feedback_new_passed (GList *failed_planes)
-{
- MetaKmsFeedback *feedback;
-
- feedback = g_new0 (MetaKmsFeedback, 1);
- *feedback = (MetaKmsFeedback) {
- .result = META_KMS_FEEDBACK_PASSED,
- .failed_planes = failed_planes,
- };
-
- return feedback;
-}
-
-MetaKmsFeedback *
-meta_kms_feedback_new_failed (GList *failed_planes,
- GError *error)
-{
- MetaKmsFeedback *feedback;
-
- feedback = g_new0 (MetaKmsFeedback, 1);
- *feedback = (MetaKmsFeedback) {
- .result = META_KMS_FEEDBACK_FAILED,
- .error = error,
- .failed_planes = failed_planes,
- };
-
- return feedback;
-}
-
-void
-meta_kms_feedback_free (MetaKmsFeedback *feedback)
-{
- g_list_free_full (feedback->failed_planes,
- (GDestroyNotify) meta_kms_plane_feedback_free);
- g_clear_error (&feedback->error);
- g_free (feedback);
-}
-
-MetaKmsFeedbackResult
-meta_kms_feedback_get_result (const MetaKmsFeedback *feedback)
-{
- return feedback->result;
-}
-
-GList *
-meta_kms_feedback_get_failed_planes (const MetaKmsFeedback *feedback)
-{
- return feedback->failed_planes;
-}
-
-const GError *
-meta_kms_feedback_get_error (const MetaKmsFeedback *feedback)
-{
- return feedback->error;
-}
-
-static void
-meta_kms_plane_assignment_free (MetaKmsPlaneAssignment *plane_assignment)
-{
- g_free (plane_assignment);
-}
-
-static void
-meta_kms_mode_set_free (MetaKmsModeSet *mode_set)
-{
- g_list_free (mode_set->connectors);
- g_free (mode_set);
-}
-
-static void
-meta_kms_page_flip_listener_free (MetaKmsPageFlipListener *listener)
-{
- g_clear_pointer (&listener->user_data, listener->destroy_notify);
- g_free (listener);
-}
-
-static gboolean
-drop_plane_assignment (MetaKmsUpdate *update,
- MetaKmsPlane *plane,
- MetaKmsAssignPlaneFlag *out_flags)
-{
- GList *l;
-
- for (l = update->plane_assignments; l; l = l->next)
- {
- MetaKmsPlaneAssignment *plane_assignment = l->data;
-
- if (plane_assignment->plane == plane)
- {
- update->plane_assignments =
- g_list_delete_link (update->plane_assignments, l);
- if (out_flags)
- *out_flags = plane_assignment->flags;
- meta_kms_plane_assignment_free (plane_assignment);
- return TRUE;
- }
- }
-
- return FALSE;
-}
-
-void
-meta_kms_update_drop_plane_assignment (MetaKmsUpdate *update,
- MetaKmsPlane *plane)
-{
- drop_plane_assignment (update, plane, NULL);
-}
-
-MetaKmsPlaneAssignment *
-meta_kms_update_assign_plane (MetaKmsUpdate *update,
- MetaKmsCrtc *crtc,
- MetaKmsPlane *plane,
- MetaDrmBuffer *buffer,
- MetaFixed16Rectangle src_rect,
- MetaRectangle dst_rect,
- MetaKmsAssignPlaneFlag flags)
-{
- MetaKmsPlaneAssignment *plane_assignment;
- MetaKmsAssignPlaneFlag old_flags;
-
- g_assert (!meta_kms_update_is_locked (update));
- g_assert (meta_kms_crtc_get_device (crtc) == update->device);
- g_assert (!update->power_save);
- g_assert (meta_kms_plane_get_device (plane) == update->device);
- g_assert (meta_kms_plane_get_plane_type (plane) !=
- META_KMS_PLANE_TYPE_PRIMARY ||
- !(flags & META_KMS_ASSIGN_PLANE_FLAG_ALLOW_FAIL));
-
- if (drop_plane_assignment (update, plane, &old_flags))
- {
- if (!(old_flags & META_KMS_ASSIGN_PLANE_FLAG_FB_UNCHANGED))
- flags &= ~META_KMS_ASSIGN_PLANE_FLAG_FB_UNCHANGED;
- }
-
- plane_assignment = g_new0 (MetaKmsPlaneAssignment, 1);
- *plane_assignment = (MetaKmsPlaneAssignment) {
- .update = update,
- .crtc = crtc,
- .plane = plane,
- .buffer = buffer,
- .src_rect = src_rect,
- .dst_rect = dst_rect,
- .flags = flags,
- };
-
- update->plane_assignments = g_list_prepend (update->plane_assignments,
- plane_assignment);
-
- return plane_assignment;
-}
-
-MetaKmsPlaneAssignment *
-meta_kms_update_unassign_plane (MetaKmsUpdate *update,
- MetaKmsCrtc *crtc,
- MetaKmsPlane *plane)
-{
- MetaKmsPlaneAssignment *plane_assignment;
-
- g_assert (!meta_kms_update_is_locked (update));
- g_assert (meta_kms_crtc_get_device (crtc) == update->device);
- g_assert (meta_kms_plane_get_device (plane) == update->device);
- g_assert (!update->power_save);
-
- plane_assignment = g_new0 (MetaKmsPlaneAssignment, 1);
- *plane_assignment = (MetaKmsPlaneAssignment) {
- .update = update,
- .crtc = crtc,
- .plane = plane,
- .buffer = NULL,
- };
-
- update->plane_assignments = g_list_prepend (update->plane_assignments,
- plane_assignment);
-
- return plane_assignment;
-}
-
-void
-meta_kms_update_mode_set (MetaKmsUpdate *update,
- MetaKmsCrtc *crtc,
- GList *connectors,
- MetaKmsMode *mode)
-{
- MetaKmsModeSet *mode_set;
-
- g_assert (!meta_kms_update_is_locked (update));
- g_assert (meta_kms_crtc_get_device (crtc) == update->device);
- g_assert (!update->power_save);
-
- mode_set = g_new0 (MetaKmsModeSet, 1);
- *mode_set = (MetaKmsModeSet) {
- .crtc = crtc,
- .connectors = connectors,
- .mode = mode,
- };
-
- update->mode_sets = g_list_prepend (update->mode_sets, mode_set);
-}
-
-static MetaKmsConnectorUpdate *
-ensure_connector_update (MetaKmsUpdate *update,
- MetaKmsConnector *connector)
-{
- GList *l;
- MetaKmsConnectorUpdate *connector_update;
-
- for (l = update->connector_updates; l; l = l->next)
- {
- connector_update = l->data;
-
- if (connector_update->connector == connector)
- return connector_update;
- }
-
- connector_update = g_new0 (MetaKmsConnectorUpdate, 1);
- connector_update->connector = connector;
-
- update->connector_updates = g_list_prepend (update->connector_updates,
- connector_update);
-
- return connector_update;
-}
-
-void
-meta_kms_update_set_underscanning (MetaKmsUpdate *update,
- MetaKmsConnector *connector,
- uint64_t hborder,
- uint64_t vborder)
-{
- MetaKmsConnectorUpdate *connector_update;
-
- g_assert (!meta_kms_update_is_locked (update));
- g_assert (meta_kms_connector_get_device (connector) == update->device);
- g_assert (!update->power_save);
-
- connector_update = ensure_connector_update (update, connector);
- connector_update->underscanning.has_update = TRUE;
- connector_update->underscanning.is_active = TRUE;
- connector_update->underscanning.hborder = hborder;
- connector_update->underscanning.vborder = vborder;
-}
-
-void
-meta_kms_update_unset_underscanning (MetaKmsUpdate *update,
- MetaKmsConnector *connector)
-{
- MetaKmsConnectorUpdate *connector_update;
-
- g_assert (!meta_kms_update_is_locked (update));
- g_assert (meta_kms_connector_get_device (connector) == update->device);
- g_assert (!update->power_save);
-
- connector_update = ensure_connector_update (update, connector);
- connector_update->underscanning.has_update = TRUE;
- connector_update->underscanning.is_active = FALSE;
-}
-
-void
-meta_kms_update_set_power_save (MetaKmsUpdate *update)
-{
- g_assert (!meta_kms_update_is_locked (update));
- g_assert (!update->mode_sets);
- g_assert (!update->plane_assignments);
- g_assert (!update->connector_updates);
- g_assert (!update->crtc_gammas);
-
- update->power_save = TRUE;
-}
-
-void
-meta_kms_crtc_gamma_free (MetaKmsCrtcGamma *gamma)
-{
- g_free (gamma->red);
- g_free (gamma->green);
- g_free (gamma->blue);
- g_free (gamma);
-}
-
-MetaKmsCrtcGamma *
-meta_kms_crtc_gamma_new (MetaKmsCrtc *crtc,
- int size,
- const uint16_t *red,
- const uint16_t *green,
- const uint16_t *blue)
-{
- MetaKmsCrtcGamma *gamma;
-
- gamma = g_new0 (MetaKmsCrtcGamma, 1);
- *gamma = (MetaKmsCrtcGamma) {
- .crtc = crtc,
- .size = size,
- .red = g_memdup2 (red, size * sizeof (*red)),
- .green = g_memdup2 (green, size * sizeof (*green)),
- .blue = g_memdup2 (blue, size * sizeof (*blue)),
- };
-
- return gamma;
-}
-
-void
-meta_kms_update_set_crtc_gamma (MetaKmsUpdate *update,
- MetaKmsCrtc *crtc,
- int size,
- const uint16_t *red,
- const uint16_t *green,
- const uint16_t *blue)
-{
- MetaKmsCrtcGamma *gamma;
-
- g_assert (!meta_kms_update_is_locked (update));
- g_assert (meta_kms_crtc_get_device (crtc) == update->device);
- g_assert (!update->power_save);
-
- gamma = meta_kms_crtc_gamma_new (crtc, size, red, green, blue);
-
- update->crtc_gammas = g_list_prepend (update->crtc_gammas, gamma);
-}
-
-void
-meta_kms_update_add_page_flip_listener (MetaKmsUpdate *update,
- MetaKmsCrtc *crtc,
- const MetaKmsPageFlipListenerVtable *vtable,
- MetaKmsPageFlipListenerFlag flags,
- gpointer user_data,
- GDestroyNotify destroy_notify)
-{
- MetaKmsPageFlipListener *listener;
-
- g_assert (!meta_kms_update_is_locked (update));
- g_assert (meta_kms_crtc_get_device (crtc) == update->device);
-
- listener = g_new0 (MetaKmsPageFlipListener, 1);
- *listener = (MetaKmsPageFlipListener) {
- .crtc = crtc,
- .vtable = vtable,
- .flags = flags,
- .user_data = user_data,
- .destroy_notify = destroy_notify,
- };
-
- update->page_flip_listeners = g_list_prepend (update->page_flip_listeners,
- listener);
-}
-
-void
-meta_kms_update_drop_defunct_page_flip_listeners (MetaKmsUpdate *update)
-{
- GList *l;
-
- l = update->page_flip_listeners;
- while (l)
- {
- MetaKmsPageFlipListener *listener = l->data;
- GList *l_next = l->next;
-
- if (listener->flags & META_KMS_PAGE_FLIP_LISTENER_FLAG_DROP_ON_ERROR)
- {
- meta_kms_page_flip_listener_free (listener);
- update->page_flip_listeners =
- g_list_delete_link (update->page_flip_listeners, l);
- }
-
- l = l_next;
- }
-}
-
-void
-meta_kms_update_set_custom_page_flip (MetaKmsUpdate *update,
- MetaKmsCustomPageFlipFunc func,
- gpointer user_data)
-{
- MetaKmsCustomPageFlip *custom_page_flip;
-
- g_assert (!meta_kms_update_is_locked (update));
- g_assert (!update->power_save);
-
- custom_page_flip = g_new0 (MetaKmsCustomPageFlip, 1);
- custom_page_flip->func = func;
- custom_page_flip->user_data = user_data;
-
- update->custom_page_flip = custom_page_flip;
-}
-
-void
-meta_kms_plane_assignment_set_rotation (MetaKmsPlaneAssignment *plane_assignment,
- uint64_t rotation)
-{
- g_assert (!meta_kms_update_is_locked (plane_assignment->update));
- g_warn_if_fail (rotation);
-
- plane_assignment->rotation = rotation;
-}
-
-void
-meta_kms_plane_assignment_set_cursor_hotspot (MetaKmsPlaneAssignment *plane_assignment,
- int x,
- int y)
-{
- plane_assignment->cursor_hotspot.is_valid = TRUE;
- plane_assignment->cursor_hotspot.x = x;
- plane_assignment->cursor_hotspot.y = y;
-}
-
-void
-meta_kms_update_add_result_listener (MetaKmsUpdate *update,
- MetaKmsResultListenerFunc func,
- gpointer user_data)
-{
- MetaKmsResultListener *listener;
-
- listener = g_new0 (MetaKmsResultListener, 1);
- *listener = (MetaKmsResultListener) {
- .func = func,
- .user_data = user_data,
- };
-
- update->result_listeners = g_list_append (update->result_listeners,
- listener);
-}
-
-GList *
-meta_kms_update_take_result_listeners (MetaKmsUpdate *update)
-{
- return g_steal_pointer (&update->result_listeners);
-}
-
-void
-meta_kms_result_listener_notify (MetaKmsResultListener *listener,
- const MetaKmsFeedback *feedback)
-{
- listener->func (feedback, listener->user_data);
-}
-
-void
-meta_kms_result_listener_free (MetaKmsResultListener *listener)
-{
- g_free (listener);
-}
-
-MetaKmsPlaneAssignment *
-meta_kms_update_get_primary_plane_assignment (MetaKmsUpdate *update,
- MetaKmsCrtc *crtc)
-{
- GList *l;
-
- for (l = meta_kms_update_get_plane_assignments (update); l; l = l->next)
- {
- MetaKmsPlaneAssignment *plane_assignment = l->data;
-
- if (meta_kms_plane_get_plane_type (plane_assignment->plane) !=
- META_KMS_PLANE_TYPE_PRIMARY)
- continue;
-
- if (plane_assignment->crtc != crtc)
- continue;
-
- return plane_assignment;
- }
-
- return NULL;
-}
-
-GList *
-meta_kms_update_get_plane_assignments (MetaKmsUpdate *update)
-{
- return update->plane_assignments;
-}
-
-GList *
-meta_kms_update_get_mode_sets (MetaKmsUpdate *update)
-{
- return update->mode_sets;
-}
-
-GList *
-meta_kms_update_get_page_flip_listeners (MetaKmsUpdate *update)
-{
- return update->page_flip_listeners;
-}
-
-GList *
-meta_kms_update_get_connector_updates (MetaKmsUpdate *update)
-{
- return update->connector_updates;
-}
-
-GList *
-meta_kms_update_get_crtc_gammas (MetaKmsUpdate *update)
-{
- return update->crtc_gammas;
-}
-
-gboolean
-meta_kms_update_is_power_save (MetaKmsUpdate *update)
-{
- return update->power_save;
-}
-
-void
-meta_kms_update_lock (MetaKmsUpdate *update)
-{
- update->is_locked = TRUE;
-}
-
-void
-meta_kms_update_unlock (MetaKmsUpdate *update)
-{
- update->is_locked = FALSE;
-}
-
-gboolean
-meta_kms_update_is_locked (MetaKmsUpdate *update)
-{
- return update->is_locked;
-}
-
-MetaKmsDevice *
-meta_kms_update_get_device (MetaKmsUpdate *update)
-{
- return update->device;
-}
-
-MetaKmsCustomPageFlip *
-meta_kms_update_take_custom_page_flip_func (MetaKmsUpdate *update)
-{
- return g_steal_pointer (&update->custom_page_flip);
-}
-
-void
-meta_kms_custom_page_flip_free (MetaKmsCustomPageFlip *custom_page_flip)
-{
- g_free (custom_page_flip);
-}
-
-uint64_t
-meta_kms_update_get_sequence_number (MetaKmsUpdate *update)
-{
- return update->sequence_number;
-}
-
-MetaKmsUpdate *
-meta_kms_update_new (MetaKmsDevice *device)
-{
- MetaKmsUpdate *update;
- static uint64_t sequence_number = 0;
-
- update = g_new0 (MetaKmsUpdate, 1);
- update->device = device;
- update->sequence_number = sequence_number++;
-
- return update;
-}
-
-void
-meta_kms_update_free (MetaKmsUpdate *update)
-{
- g_list_free_full (update->result_listeners,
- (GDestroyNotify) meta_kms_result_listener_free);
- g_list_free_full (update->plane_assignments,
- (GDestroyNotify) meta_kms_plane_assignment_free);
- g_list_free_full (update->mode_sets,
- (GDestroyNotify) meta_kms_mode_set_free);
- g_list_free_full (update->page_flip_listeners,
- (GDestroyNotify) meta_kms_page_flip_listener_free);
- g_list_free_full (update->connector_updates, g_free);
- g_list_free_full (update->crtc_gammas, (GDestroyNotify) meta_kms_crtc_gamma_free);
- g_clear_pointer (&update->custom_page_flip, meta_kms_custom_page_flip_free);
-
- g_free (update);
-}
diff --git a/src/backends/native/meta-kms-update.h b/src/backends/native/meta-kms-update.h
deleted file mode 100644
index 4a6a8bb43..000000000
--- a/src/backends/native/meta-kms-update.h
+++ /dev/null
@@ -1,181 +0,0 @@
-/*
- * Copyright (C) 2018 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-
-#ifndef META_KMS_UPDATE_H
-#define META_KMS_UPDATE_H
-
-#include <glib-object.h>
-#include <glib.h>
-#include <stdint.h>
-#include <xf86drmMode.h>
-
-#include "backends/meta-monitor-transform.h"
-#include "backends/native/meta-drm-buffer.h"
-#include "backends/native/meta-kms-types.h"
-#include "meta/boxes.h"
-
-typedef enum _MetaKmsFeedbackResult
-{
- META_KMS_FEEDBACK_PASSED,
- META_KMS_FEEDBACK_FAILED,
-} MetaKmsFeedbackResult;
-
-typedef enum _MetaKmsAssignPlaneFlag
-{
- META_KMS_ASSIGN_PLANE_FLAG_NONE = 0,
- META_KMS_ASSIGN_PLANE_FLAG_FB_UNCHANGED = 1 << 0,
- META_KMS_ASSIGN_PLANE_FLAG_ALLOW_FAIL = 1 << 1,
-} MetaKmsAssignPlaneFlag;
-
-enum _MetaKmsPageFlipListenerFlag
-{
- META_KMS_PAGE_FLIP_LISTENER_FLAG_NONE = 0,
- META_KMS_PAGE_FLIP_LISTENER_FLAG_DROP_ON_ERROR = 1 << 0,
-};
-
-struct _MetaKmsPageFlipListenerVtable
-{
- void (* flipped) (MetaKmsCrtc *crtc,
- unsigned int sequence,
- unsigned int tv_sec,
- unsigned int tv_usec,
- gpointer user_data);
-
- void (* ready) (MetaKmsCrtc *crtc,
- gpointer user_data);
-
- void (* mode_set_fallback) (MetaKmsCrtc *crtc,
- gpointer user_data);
-
- void (* discarded) (MetaKmsCrtc *crtc,
- gpointer user_data,
- const GError *error);
-};
-
-typedef int (* MetaKmsCustomPageFlipFunc) (gpointer custom_page_flip_data,
- gpointer user_data);
-
-typedef struct _MetaKmsPlaneFeedback
-{
- MetaKmsPlane *plane;
- MetaKmsCrtc *crtc;
- GError *error;
-} MetaKmsPlaneFeedback;
-
-typedef void (* MetaKmsResultListenerFunc) (const MetaKmsFeedback *feedback,
- gpointer user_data);
-
-void meta_kms_feedback_free (MetaKmsFeedback *feedback);
-
-MetaKmsFeedbackResult meta_kms_feedback_get_result (const MetaKmsFeedback *feedback);
-
-GList * meta_kms_feedback_get_failed_planes (const MetaKmsFeedback *feedback);
-
-const GError * meta_kms_feedback_get_error (const MetaKmsFeedback *feedback);
-
-MetaKmsUpdate * meta_kms_update_new (MetaKmsDevice *device);
-
-void meta_kms_update_free (MetaKmsUpdate *update);
-
-void meta_kms_update_set_underscanning (MetaKmsUpdate *update,
- MetaKmsConnector *connector,
- uint64_t hborder,
- uint64_t vborder);
-
-void meta_kms_update_unset_underscanning (MetaKmsUpdate *update,
- MetaKmsConnector *connector);
-
-void meta_kms_update_set_power_save (MetaKmsUpdate *update);
-
-void meta_kms_update_mode_set (MetaKmsUpdate *update,
- MetaKmsCrtc *crtc,
- GList *connectors,
- MetaKmsMode *mode);
-
-void meta_kms_update_set_crtc_gamma (MetaKmsUpdate *update,
- MetaKmsCrtc *crtc,
- int size,
- const uint16_t *red,
- const uint16_t *green,
- const uint16_t *blue);
-
-MetaKmsPlaneAssignment * meta_kms_update_assign_plane (MetaKmsUpdate *update,
- MetaKmsCrtc *crtc,
- MetaKmsPlane *plane,
- MetaDrmBuffer *buffer,
- MetaFixed16Rectangle src_rect,
- MetaRectangle dst_rect,
- MetaKmsAssignPlaneFlag flags);
-
-MetaKmsPlaneAssignment * meta_kms_update_unassign_plane (MetaKmsUpdate *update,
- MetaKmsCrtc *crtc,
- MetaKmsPlane *plane);
-
-void meta_kms_update_add_page_flip_listener (MetaKmsUpdate *update,
- MetaKmsCrtc *crtc,
- const MetaKmsPageFlipListenerVtable *vtable,
- MetaKmsPageFlipListenerFlag flags,
- gpointer user_data,
- GDestroyNotify destroy_notify);
-
-void meta_kms_update_set_custom_page_flip (MetaKmsUpdate *update,
- MetaKmsCustomPageFlipFunc func,
- gpointer user_data);
-
-void meta_kms_plane_assignment_set_cursor_hotspot (MetaKmsPlaneAssignment *plane_assignment,
- int x,
- int y);
-
-void meta_kms_update_add_result_listener (MetaKmsUpdate *update,
- MetaKmsResultListenerFunc func,
- gpointer user_data);
-
-static inline MetaFixed16
-meta_fixed_16_from_int (int16_t d)
-{
- return d * 65536;
-}
-
-static inline int16_t
-meta_fixed_16_to_int (MetaFixed16 fixed)
-{
- return fixed / 65536;
-}
-
-static inline double
-meta_fixed_16_to_double (MetaFixed16 fixed)
-{
- return fixed / 65536.0;
-}
-
-static inline MetaRectangle
-meta_fixed_16_rectangle_to_rectangle (MetaFixed16Rectangle fixed_rect)
-{
- return (MetaRectangle) {
- .x = meta_fixed_16_to_int (fixed_rect.x),
- .y = meta_fixed_16_to_int (fixed_rect.y),
- .width = meta_fixed_16_to_int (fixed_rect.width),
- .height = meta_fixed_16_to_int (fixed_rect.height),
- };
-}
-
-G_DEFINE_AUTOPTR_CLEANUP_FUNC (MetaKmsFeedback, meta_kms_feedback_free)
-G_DEFINE_AUTOPTR_CLEANUP_FUNC (MetaKmsUpdate, meta_kms_update_free)
-
-#endif /* META_KMS_UPDATE_H */
diff --git a/src/backends/native/meta-kms-utils.c b/src/backends/native/meta-kms-utils.c
deleted file mode 100644
index 2289cfa91..000000000
--- a/src/backends/native/meta-kms-utils.c
+++ /dev/null
@@ -1,103 +0,0 @@
-/*
- * Copyright (C) 2013-2019 Red Hat
- * Copyright (c) 2018 DisplayLink (UK) Ltd.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-
-#include "config.h"
-
-#include "backends/native/meta-kms-utils.h"
-
-#include <drm_fourcc.h>
-#include <glib.h>
-
-/* added in libdrm 2.4.95 */
-#ifndef DRM_FORMAT_INVALID
-#define DRM_FORMAT_INVALID 0
-#endif
-
-float
-meta_calculate_drm_mode_refresh_rate (const drmModeModeInfo *drm_mode)
-{
- double numerator;
- double denominator;
-
- if (drm_mode->htotal <= 0 || drm_mode->vtotal <= 0)
- return 0.0;
-
- numerator = drm_mode->clock * 1000.0;
- denominator = (double) drm_mode->vtotal * drm_mode->htotal;
- if (drm_mode->vscan > 1)
- denominator *= drm_mode->vscan;
-
- return numerator / denominator;
-}
-
-int64_t
-meta_calculate_drm_mode_vblank_duration_us (const drmModeModeInfo *drm_mode)
-{
- int64_t value;
-
- if (drm_mode->htotal <= 0 || drm_mode->vtotal <= 0)
- return 0;
-
- /* Convert to int64_t early. */
- value = drm_mode->vtotal - drm_mode->vdisplay;
- value *= drm_mode->htotal;
-
- if (drm_mode->flags & DRM_MODE_FLAG_DBLSCAN)
- value *= 2;
-
- /* Round the duration up as it is used for buffer swap deadline computation. */
- value = (value * 1000 + drm_mode->clock - 1) / drm_mode->clock;
-
- return value;
-}
-
-/**
- * meta_drm_format_to_string:
- * @tmp: temporary buffer
- * @drm_format: DRM fourcc pixel format
- *
- * Returns a pointer to a string naming the given pixel format,
- * usually a pointer to the temporary buffer but not always.
- * Invalid formats may return nonsense names.
- *
- * When calling this, allocate one MetaDrmFormatBuf on the stack to
- * be used as the temporary buffer.
- */
-const char *
-meta_drm_format_to_string (MetaDrmFormatBuf *tmp,
- uint32_t drm_format)
-{
- int i;
-
- if (drm_format == DRM_FORMAT_INVALID)
- return "INVALID";
-
- G_STATIC_ASSERT (sizeof (tmp->s) == 5);
- for (i = 0; i < 4; i++)
- {
- char c = (drm_format >> (i * 8)) & 0xff;
- tmp->s[i] = g_ascii_isgraph (c) ? c : '.';
- }
-
- tmp->s[i] = 0;
-
- return tmp->s;
-}
-
diff --git a/src/backends/native/meta-kms-utils.h b/src/backends/native/meta-kms-utils.h
deleted file mode 100644
index 2f2bad1f9..000000000
--- a/src/backends/native/meta-kms-utils.h
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright (C) 2018 DisplayLink (UK) Ltd.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-
-#ifndef META_KMS_UTILS_H
-#define META_KMS_UTILS_H
-
-#include <stddef.h>
-#include <stdint.h>
-#include <xf86drmMode.h>
-
-#include "core/util-private.h"
-
-typedef struct _MetaDrmFormatBuf
-{
- char s[5];
-} MetaDrmFormatBuf;
-
-META_EXPORT_TEST
-float meta_calculate_drm_mode_refresh_rate (const drmModeModeInfo *drm_mode);
-
-META_EXPORT_TEST
-int64_t meta_calculate_drm_mode_vblank_duration_us (const drmModeModeInfo *drm_mode);
-
-const char * meta_drm_format_to_string (MetaDrmFormatBuf *tmp,
- uint32_t drm_format);
-
-#endif /* META_KMS_UTILS_H */
diff --git a/src/backends/native/meta-kms.c b/src/backends/native/meta-kms.c
deleted file mode 100644
index 70feccc22..000000000
--- a/src/backends/native/meta-kms.c
+++ /dev/null
@@ -1,754 +0,0 @@
-/*
- * Copyright (C) 2018 Red Hat
- * Copyright 2020 DisplayLink (UK) Ltd.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-
-#include "config.h"
-
-#include "backends/native/meta-kms-private.h"
-
-#include "backends/native/meta-backend-native.h"
-#include "backends/native/meta-kms-device-private.h"
-#include "backends/native/meta-kms-impl.h"
-#include "backends/native/meta-kms-update-private.h"
-#include "backends/native/meta-udev.h"
-#include "cogl/cogl.h"
-
-/**
- * SECTION:kms
- * @short description: KMS abstraction
- * @title: KMS abstraction
- *
- * The KMS abstraction consists of various building blocks for helping out with
- * interacting with the various drm API's, enabling users to use a
- * transactional API, aiming to hide all interaction with the underlying APIs.
- *
- * The subsystem defines two separate contexts, the "main" context, and the
- * "impl" context. The main context is the context of which mutter as a whole
- * runs in. It uses the main GLib main loop and main context and always runs in
- * the main thread.
- *
- * The impl context is where all underlying API is being executed. While in the
- * current state, it always runs in the main thread, the aim is to be able to
- * execute the impl context in a dedicated thread.
- *
- * The public facing MetaKms API is always assumed to be executed from the main
- * context.
- *
- * The KMS abstraction consists of the following public components:
- *
- * #MetaKms:
- *
- * Main entry point; used by the native backend to create devices, post updates
- * etc.
- *
- * #MetaKmsDevice:
- *
- * A device (usually /dev/dri/cardN, where N being a number). Used to get KMS
- * objects, such as connectors, CRTCs, planes, as well as basic meta data such
- * as device path etc.
- *
- * #MetaKmsCrtc:
- *
- * Represents a CRTC. It manages a representation of the current CRTC state,
- * including current mode, coordinates, possible clones.
- *
- * #MetaKmsConnector:
- *
- * Represents a connector, e.g. a display port connection. It also manages a
- * representation of the current state, including meta data such as physical
- * dimension of the connected, available modes, EDID, tile info etc. It also
- * contains helper functions for configuration, as well as methods for adding
- * configuration to a transaction (See #MetaKmsUpdate).
- *
- * #MetaKmsPlane:
- *
- * Represents a hardware plane. A plane is used to define the content of what
- * should be presented on a CRTC. Planes can either be primary planes, used as
- * a backdrop for CRTCs, overlay planes, and cursor planes.
- *
- * #MetaKmsMode:
- *
- * Represents a mode a CRTC and connector can be configured with.
- * Represents both modes directly derived from the devices, as well as
- * fall back modes when the CRTC supports scaling.
- *
- * #MetaKmsUpdate:
- *
- * A KMS transaction object, meant to be processed potentially atomically when
- * posted. An update consists of plane assignments, mode sets and KMS object
- * property entries. The user adds updates to the object, and then posts it via
- * MetaKms. It will then be processed by the MetaKms backend (See
- * #MetaKmsImpl), potentially atomically. Each #MetaKmsUpdate deals with
- * updating a single device.
- *
- *
- * There are also these private objects, without public facing API:
- *
- * #MetaKmsImpl:
- *
- * The KMS impl context object, managing things in the impl context.
- *
- * #MetaKmsImplDevice:
- *
- * An object linked to a #MetaKmsDevice, but where it is executed in the impl
- * context. It takes care of the updating of the various KMS object (CRTC,
- * connector, ..) states.
- *
- * This is an abstract type, with currently #MetaKmsImplDeviceSimple,
- * implementing mode setting and page flipping using legacy DRM API.
- *
- * #MetaKmsPageFlip:
- *
- * A object representing a page flip. It's created when a page flip is queued,
- * and contains information necessary to provide feedback to the one requesting
- * the page flip.
- *
- */
-
-enum
-{
- RESOURCES_CHANGED,
-
- N_SIGNALS
-};
-
-static int signals[N_SIGNALS];
-
-typedef struct _MetaKmsCallbackData
-{
- MetaKmsCallback callback;
- gpointer user_data;
- GDestroyNotify user_data_destroy;
-} MetaKmsCallbackData;
-
-typedef struct _MetaKmsSimpleImplSource
-{
- GSource source;
- MetaKms *kms;
-} MetaKmsSimpleImplSource;
-
-typedef struct _MetaKmsFdImplSource
-{
- GSource source;
-
- gpointer fd_tag;
- MetaKms *kms;
-
- MetaKmsImplTaskFunc dispatch;
- gpointer user_data;
-} MetaKmsFdImplSource;
-
-struct _MetaKms
-{
- GObject parent;
-
- MetaKmsFlags flags;
-
- MetaBackend *backend;
-
- gulong hotplug_handler_id;
- gulong removed_handler_id;
-
- MetaKmsImpl *impl;
- gboolean in_impl_task;
- gboolean waiting_for_impl_task;
-
- GList *devices;
-
- GList *pending_updates;
-
- GList *pending_callbacks;
- guint callback_source_id;
-};
-
-G_DEFINE_TYPE (MetaKms, meta_kms, G_TYPE_OBJECT)
-
-static void
-meta_kms_add_pending_update (MetaKms *kms,
- MetaKmsUpdate *update)
-{
- kms->pending_updates = g_list_prepend (kms->pending_updates, update);
-}
-
-MetaKmsUpdate *
-meta_kms_ensure_pending_update (MetaKms *kms,
- MetaKmsDevice *device)
-{
- MetaKmsUpdate *update;
-
- update = meta_kms_get_pending_update (kms, device);
- if (update)
- return update;
-
- update = meta_kms_update_new (device);
- meta_kms_add_pending_update (kms, update);
-
- return update;
-}
-
-MetaKmsUpdate *
-meta_kms_get_pending_update (MetaKms *kms,
- MetaKmsDevice *device)
-{
- GList *l;
-
- for (l = kms->pending_updates; l; l = l->next)
- {
- MetaKmsUpdate *update = l->data;
-
- if (meta_kms_update_get_device (update) == device)
- return update;
- }
-
- return NULL;
-}
-
-static MetaKmsUpdate *
-meta_kms_take_pending_update (MetaKms *kms,
- MetaKmsDevice *device)
-{
- GList *l;
-
- for (l = kms->pending_updates; l; l = l->next)
- {
- MetaKmsUpdate *update = l->data;
-
- if (meta_kms_update_get_device (update) == device)
- {
- kms->pending_updates = g_list_delete_link (kms->pending_updates, l);
- return update;
- }
- }
-
- return NULL;
-}
-
-typedef struct
-{
- MetaKmsUpdate *update;
- MetaKmsUpdateFlag flags;
-} PostUpdateData;
-
-static gpointer
-meta_kms_process_update_in_impl (MetaKmsImpl *impl,
- gpointer user_data,
- GError **error)
-{
- PostUpdateData *data = user_data;
- MetaKmsUpdate *update = data->update;
- MetaKmsFeedback *feedback;
-
- feedback = meta_kms_impl_process_update (impl, data->update, data->flags);
- meta_kms_device_predict_states_in_impl (meta_kms_update_get_device (update),
- update);
-
- return feedback;
-}
-
-MetaKmsFeedback *
-meta_kms_post_pending_update_sync (MetaKms *kms,
- MetaKmsDevice *device,
- MetaKmsUpdateFlag flags)
-{
- MetaKmsUpdate *update;
- PostUpdateData data;
- MetaKmsFeedback *feedback;
- GList *result_listeners;
- GList *l;
-
- COGL_TRACE_BEGIN_SCOPED (MetaKmsPostUpdateSync,
- "KMS (post update)");
-
- update = meta_kms_take_pending_update (kms, device);
- if (!update)
- return NULL;
-
- meta_kms_update_lock (update);
-
- data = (PostUpdateData) {
- .update = update,
- .flags = flags,
- };
- feedback = meta_kms_run_impl_task_sync (kms,
- meta_kms_process_update_in_impl,
- &data,
- NULL);
-
- result_listeners = meta_kms_update_take_result_listeners (update);
-
- if (feedback->error &&
- flags & META_KMS_UPDATE_FLAG_PRESERVE_ON_ERROR)
- {
- GList *l;
-
- meta_kms_update_unlock (update);
-
- for (l = feedback->failed_planes; l; l = l->next)
- {
- MetaKmsPlane *plane = l->data;
-
- meta_kms_update_drop_plane_assignment (update, plane);
- }
-
- meta_kms_update_drop_defunct_page_flip_listeners (update);
-
- meta_kms_add_pending_update (kms, update);
- }
- else
- {
- meta_kms_update_free (update);
- }
-
- for (l = result_listeners; l; l = l->next)
- {
- MetaKmsResultListener *listener = l->data;
-
- meta_kms_result_listener_notify (listener, feedback);
- meta_kms_result_listener_free (listener);
- }
- g_list_free (result_listeners);
-
- return feedback;
-}
-
-static gpointer
-meta_kms_discard_pending_page_flips_in_impl (MetaKmsImpl *impl,
- gpointer user_data,
- GError **error)
-{
- meta_kms_impl_discard_pending_page_flips (impl);
- return GINT_TO_POINTER (TRUE);
-}
-
-void
-meta_kms_discard_pending_page_flips (MetaKms *kms)
-{
- meta_kms_run_impl_task_sync (kms,
- meta_kms_discard_pending_page_flips_in_impl,
- NULL,
- NULL);
-}
-
-static gpointer
-meta_kms_notify_modes_set_in_impl (MetaKmsImpl *impl,
- gpointer user_data,
- GError **error)
-{
- meta_kms_impl_notify_modes_set (impl);
- return GINT_TO_POINTER (TRUE);
-}
-
-void
-meta_kms_notify_modes_set (MetaKms *kms)
-{
- meta_kms_run_impl_task_sync (kms,
- meta_kms_notify_modes_set_in_impl,
- NULL,
- NULL);
-}
-
-static void
-meta_kms_callback_data_free (MetaKmsCallbackData *callback_data)
-{
- if (callback_data->user_data_destroy)
- callback_data->user_data_destroy (callback_data->user_data);
- g_free (callback_data);
-}
-
-static int
-flush_callbacks (MetaKms *kms)
-{
- GList *l;
- int callback_count = 0;
-
- meta_assert_not_in_kms_impl (kms);
-
- g_clear_handle_id (&kms->callback_source_id, g_source_remove);
-
- for (l = kms->pending_callbacks; l; l = l->next)
- {
- MetaKmsCallbackData *callback_data = l->data;
-
- callback_data->callback (kms, callback_data->user_data);
- meta_kms_callback_data_free (callback_data);
- callback_count++;
- }
-
- g_list_free (kms->pending_callbacks);
- kms->pending_callbacks = NULL;
-
- return callback_count;
-}
-
-static gboolean
-callback_idle (gpointer user_data)
-{
- MetaKms *kms = user_data;
-
- flush_callbacks (kms);
-
- kms->callback_source_id = 0;
- return G_SOURCE_REMOVE;
-}
-
-void
-meta_kms_queue_callback (MetaKms *kms,
- MetaKmsCallback callback,
- gpointer user_data,
- GDestroyNotify user_data_destroy)
-{
- MetaKmsCallbackData *callback_data;
-
- callback_data = g_new0 (MetaKmsCallbackData, 1);
- *callback_data = (MetaKmsCallbackData) {
- .callback = callback,
- .user_data = user_data,
- .user_data_destroy = user_data_destroy,
- };
- kms->pending_callbacks = g_list_append (kms->pending_callbacks,
- callback_data);
- if (!kms->callback_source_id)
- kms->callback_source_id = g_idle_add (callback_idle, kms);
-}
-
-gpointer
-meta_kms_run_impl_task_sync (MetaKms *kms,
- MetaKmsImplTaskFunc func,
- gpointer user_data,
- GError **error)
-{
- gpointer ret;
-
- kms->in_impl_task = TRUE;
- kms->waiting_for_impl_task = TRUE;
- ret = func (kms->impl, user_data, error);
- kms->waiting_for_impl_task = FALSE;
- kms->in_impl_task = FALSE;
-
- return ret;
-}
-
-static gboolean
-simple_impl_source_dispatch (GSource *source,
- GSourceFunc callback,
- gpointer user_data)
-{
- MetaKmsSimpleImplSource *simple_impl_source =
- (MetaKmsSimpleImplSource *) source;
- MetaKms *kms = simple_impl_source->kms;
- gboolean ret;
-
- kms->in_impl_task = TRUE;
- ret = callback (user_data);
- kms->in_impl_task = FALSE;
-
- return ret;
-}
-
-static GSourceFuncs simple_impl_source_funcs = {
- .dispatch = simple_impl_source_dispatch,
-};
-
-GSource *
-meta_kms_add_source_in_impl (MetaKms *kms,
- GSourceFunc func,
- gpointer user_data,
- GDestroyNotify user_data_destroy)
-{
- GSource *source;
- MetaKmsSimpleImplSource *simple_impl_source;
-
- meta_assert_in_kms_impl (kms);
-
- source = g_source_new (&simple_impl_source_funcs,
- sizeof (MetaKmsSimpleImplSource));
- simple_impl_source = (MetaKmsSimpleImplSource *) source;
- simple_impl_source->kms = kms;
-
- g_source_set_callback (source, func, user_data, user_data_destroy);
- g_source_set_ready_time (source, 0);
- g_source_attach (source, g_main_context_get_thread_default ());
-
- return source;
-}
-
-static gboolean
-meta_kms_fd_impl_source_check (GSource *source)
-{
- MetaKmsFdImplSource *fd_impl_source = (MetaKmsFdImplSource *) source;
-
- return g_source_query_unix_fd (source, fd_impl_source->fd_tag) & G_IO_IN;
-}
-
-static gboolean
-meta_kms_fd_impl_source_dispatch (GSource *source,
- GSourceFunc callback,
- gpointer user_data)
-{
- MetaKmsFdImplSource *fd_impl_source = (MetaKmsFdImplSource *) source;
- MetaKms *kms = fd_impl_source->kms;
- gpointer ret;
- GError *error = NULL;
-
- kms->in_impl_task = TRUE;
- ret = fd_impl_source->dispatch (kms->impl,
- fd_impl_source->user_data,
- &error);
- kms->in_impl_task = FALSE;
-
- if (!GPOINTER_TO_INT (ret))
- {
- g_warning ("Failed to dispatch fd source: %s", error->message);
- g_error_free (error);
- }
-
- return G_SOURCE_CONTINUE;
-}
-
-static GSourceFuncs fd_impl_source_funcs = {
- NULL,
- meta_kms_fd_impl_source_check,
- meta_kms_fd_impl_source_dispatch
-};
-
-GSource *
-meta_kms_register_fd_in_impl (MetaKms *kms,
- int fd,
- MetaKmsImplTaskFunc dispatch,
- gpointer user_data)
-{
- GSource *source;
- MetaKmsFdImplSource *fd_impl_source;
-
- meta_assert_in_kms_impl (kms);
-
- source = g_source_new (&fd_impl_source_funcs, sizeof (MetaKmsFdImplSource));
- fd_impl_source = (MetaKmsFdImplSource *) source;
- fd_impl_source->dispatch = dispatch;
- fd_impl_source->user_data = user_data;
- fd_impl_source->kms = kms;
- fd_impl_source->fd_tag = g_source_add_unix_fd (source, fd,
- G_IO_IN | G_IO_ERR);
-
- g_source_attach (source, g_main_context_get_thread_default ());
-
- return source;
-}
-
-gboolean
-meta_kms_in_impl_task (MetaKms *kms)
-{
- return kms->in_impl_task;
-}
-
-gboolean
-meta_kms_is_waiting_for_impl_task (MetaKms *kms)
-{
- return kms->waiting_for_impl_task;
-}
-
-static void
-meta_kms_update_states_in_impl (MetaKms *kms)
-{
- COGL_TRACE_BEGIN_SCOPED (MetaKmsUpdateStates,
- "KMS (update states)");
-
- meta_assert_in_kms_impl (kms);
-
- g_list_foreach (kms->devices,
- (GFunc) meta_kms_device_update_states_in_impl,
- NULL);
-}
-
-static gpointer
-update_states_in_impl (MetaKmsImpl *impl,
- gpointer user_data,
- GError **error)
-{
- MetaKms *kms = meta_kms_impl_get_kms (impl);
-
- meta_kms_update_states_in_impl (kms);
-
- return GINT_TO_POINTER (TRUE);
-}
-
-static gboolean
-meta_kms_update_states_sync (MetaKms *kms,
- GError **error)
-{
- gpointer ret;
-
- ret = meta_kms_run_impl_task_sync (kms, update_states_in_impl, NULL, error);
- return GPOINTER_TO_INT (ret);
-}
-
-static void
-handle_hotplug_event (MetaKms *kms)
-{
- g_autoptr (GError) error = NULL;
-
- if (!meta_kms_update_states_sync (kms, &error))
- g_warning ("Updating KMS state failed: %s", error->message);
-
- g_signal_emit (kms, signals[RESOURCES_CHANGED], 0);
-}
-
-void
-meta_kms_resume (MetaKms *kms)
-{
- handle_hotplug_event (kms);
-}
-
-static void
-on_udev_hotplug (MetaUdev *udev,
- MetaKms *kms)
-{
- handle_hotplug_event (kms);
-}
-
-static void
-on_udev_device_removed (MetaUdev *udev,
- GUdevDevice *device,
- MetaKms *kms)
-{
- handle_hotplug_event (kms);
-}
-
-MetaBackend *
-meta_kms_get_backend (MetaKms *kms)
-{
- return kms->backend;
-}
-
-GList *
-meta_kms_get_devices (MetaKms *kms)
-{
- return kms->devices;
-}
-
-MetaKmsDevice *
-meta_kms_create_device (MetaKms *kms,
- const char *path,
- MetaKmsDeviceFlag flags,
- GError **error)
-{
- MetaKmsDevice *device;
-
- if (kms->flags & META_KMS_FLAG_NO_MODE_SETTING)
- flags |= META_KMS_DEVICE_FLAG_NO_MODE_SETTING;
-
- device = meta_kms_device_new (kms, path, flags, error);
- if (!device)
- return NULL;
-
- kms->devices = g_list_append (kms->devices, device);
-
- return device;
-}
-
-MetaKms *
-meta_kms_new (MetaBackend *backend,
- MetaKmsFlags flags,
- GError **error)
-{
- MetaBackendNative *backend_native = META_BACKEND_NATIVE (backend);
- MetaUdev *udev = meta_backend_native_get_udev (backend_native);
- MetaKms *kms;
-
- kms = g_object_new (META_TYPE_KMS, NULL);
- kms->flags = flags;
- kms->backend = backend;
- kms->impl = meta_kms_impl_new (kms);
- if (!kms->impl)
- {
- g_object_unref (kms);
- return NULL;
- }
-
- if (!(flags & META_KMS_FLAG_NO_MODE_SETTING))
- {
- kms->hotplug_handler_id =
- g_signal_connect (udev, "hotplug", G_CALLBACK (on_udev_hotplug), kms);
- }
-
- kms->removed_handler_id =
- g_signal_connect (udev, "device-removed",
- G_CALLBACK (on_udev_device_removed), kms);
-
- return kms;
-}
-
-static gpointer
-prepare_shutdown_in_impl (MetaKmsImpl *impl,
- gpointer user_data,
- GError **error)
-{
- meta_kms_impl_prepare_shutdown (impl);
- return GINT_TO_POINTER (TRUE);
-}
-
-void
-meta_kms_prepare_shutdown (MetaKms *kms)
-{
- meta_kms_run_impl_task_sync (kms, prepare_shutdown_in_impl, NULL, NULL);
- flush_callbacks (kms);
-}
-
-static void
-meta_kms_finalize (GObject *object)
-{
- MetaKms *kms = META_KMS (object);
- MetaBackendNative *backend_native = META_BACKEND_NATIVE (kms->backend);
- MetaUdev *udev = meta_backend_native_get_udev (backend_native);
- GList *l;
-
- for (l = kms->pending_callbacks; l; l = l->next)
- meta_kms_callback_data_free (l->data);
- g_list_free (kms->pending_callbacks);
-
- g_clear_handle_id (&kms->callback_source_id, g_source_remove);
-
- g_list_free_full (kms->devices, g_object_unref);
-
- g_clear_signal_handler (&kms->hotplug_handler_id, udev);
- g_clear_signal_handler (&kms->removed_handler_id, udev);
-
- G_OBJECT_CLASS (meta_kms_parent_class)->finalize (object);
-}
-
-static void
-meta_kms_init (MetaKms *kms)
-{
-}
-
-static void
-meta_kms_class_init (MetaKmsClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- object_class->finalize = meta_kms_finalize;
-
- signals[RESOURCES_CHANGED] =
- g_signal_new ("resources-changed",
- G_TYPE_FROM_CLASS (klass),
- G_SIGNAL_RUN_LAST,
- 0,
- NULL, NULL, NULL,
- G_TYPE_NONE, 0);
-}
diff --git a/src/backends/native/meta-kms.h b/src/backends/native/meta-kms.h
deleted file mode 100644
index 9eae80e3f..000000000
--- a/src/backends/native/meta-kms.h
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Copyright (C) 2018 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-
-#ifndef META_KMS_H
-#define META_KMS_H
-
-#include <glib-object.h>
-
-#include "backends/meta-backend-private.h"
-#include "backends/native/meta-kms-types.h"
-
-typedef enum _MetaKmsFlags
-{
- META_KMS_FLAG_NONE = 0,
- META_KMS_FLAG_NO_MODE_SETTING = 1 << 0,
-} MetaKmsFlags;
-
-typedef enum _MetaKmsUpdateFlag
-{
- META_KMS_UPDATE_FLAG_NONE = 0,
- META_KMS_UPDATE_FLAG_PRESERVE_ON_ERROR = 1 << 0,
-} MetaKmsUpdateFlag;
-
-#define META_TYPE_KMS (meta_kms_get_type ())
-G_DECLARE_FINAL_TYPE (MetaKms, meta_kms, META, KMS, GObject)
-
-MetaKmsUpdate * meta_kms_ensure_pending_update (MetaKms *kms,
- MetaKmsDevice *device);
-
-MetaKmsUpdate * meta_kms_get_pending_update (MetaKms *kms,
- MetaKmsDevice *device);
-
-MetaKmsFeedback * meta_kms_post_pending_update_sync (MetaKms *kms,
- MetaKmsDevice *device,
- MetaKmsUpdateFlag flags);
-
-void meta_kms_discard_pending_page_flips (MetaKms *kms);
-
-void meta_kms_notify_modes_set (MetaKms *kms);
-
-MetaBackend * meta_kms_get_backend (MetaKms *kms);
-
-GList * meta_kms_get_devices (MetaKms *kms);
-
-void meta_kms_resume (MetaKms *kms);
-
-MetaKmsDevice * meta_kms_create_device (MetaKms *kms,
- const char *path,
- MetaKmsDeviceFlag flags,
- GError **error);
-
-void meta_kms_prepare_shutdown (MetaKms *kms);
-
-MetaKms * meta_kms_new (MetaBackend *backend,
- MetaKmsFlags flags,
- GError **error);
-
-#endif /* META_KMS_H */
diff --git a/src/backends/native/meta-launcher.c b/src/backends/native/meta-launcher.c
deleted file mode 100644
index 4a63d2feb..000000000
--- a/src/backends/native/meta-launcher.c
+++ /dev/null
@@ -1,410 +0,0 @@
-/*
- * Copyright (C) 2013 Red Hat, Inc.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-
-#include "config.h"
-
-#include "backends/native/meta-launcher.h"
-
-#include <gio/gunixfdlist.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/sysmacros.h>
-#include <malloc.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <systemd/sd-login.h>
-#include <gudev/gudev.h>
-
-#include "backends/meta-backend-private.h"
-#include "backends/native/dbus-utils.h"
-#include "backends/native/meta-backend-native.h"
-#include "backends/native/meta-clutter-backend-native.h"
-#include "backends/native/meta-cursor-renderer-native.h"
-#include "backends/native/meta-input-thread.h"
-#include "backends/native/meta-renderer-native.h"
-#include "clutter/clutter.h"
-
-#include "meta-dbus-login1.h"
-
-struct _MetaLauncher
-{
- MetaDbusLogin1Session *session_proxy;
- MetaDbusLogin1Seat *seat_proxy;
- char *seat_id;
-
- gboolean session_active;
-};
-
-const char *
-meta_launcher_get_seat_id (MetaLauncher *launcher)
-{
- return launcher->seat_id;
-}
-
-static gboolean
-find_systemd_session (gchar **session_id,
- GError **error)
-{
- const gchar * const graphical_session_types[] = { "wayland", "x11", "mir", NULL };
- const gchar * const active_states[] = { "active", "online", NULL };
- g_autofree gchar *class = NULL;
- g_autofree gchar *local_session_id = NULL;
- g_autofree gchar *type = NULL;
- g_autofree gchar *state = NULL;
- g_auto (GStrv) sessions = NULL;
- int n_sessions;
- int saved_errno;
-
- g_assert (session_id != NULL);
- g_assert (error == NULL || *error == NULL);
-
- /* if we are in a logind session, we can trust that value, so use it. This
- * happens for example when you run mutter directly from a VT but when
- * systemd starts us we will not be in a logind session. */
- saved_errno = sd_pid_get_session (0, &local_session_id);
- if (saved_errno < 0)
- {
- if (saved_errno != -ENODATA)
- {
- g_set_error (error,
- G_IO_ERROR,
- G_IO_ERROR_NOT_FOUND,
- "Failed to get session by pid for user %d (%s)",
- getuid (),
- g_strerror (-saved_errno));
- return FALSE;
- }
- }
- else
- {
- *session_id = g_steal_pointer (&local_session_id);
- return TRUE;
- }
-
- saved_errno = sd_uid_get_display (getuid (), &local_session_id);
- if (saved_errno < 0)
- {
- /* no session, maybe there's a greeter session */
- if (saved_errno == -ENODATA)
- {
- n_sessions = sd_uid_get_sessions (getuid (), 1, &sessions);
- if (n_sessions < 0)
- {
- g_set_error (error,
- G_IO_ERROR,
- G_IO_ERROR_NOT_FOUND,
- "Failed to get all sessions for user %d (%m)",
- getuid ());
- return FALSE;
- }
-
- if (n_sessions == 0)
- {
- g_set_error (error,
- G_IO_ERROR,
- G_IO_ERROR_NOT_FOUND,
- "User %d has no sessions",
- getuid ());
- return FALSE;
- }
-
- for (int i = 0; i < n_sessions; ++i)
- {
- saved_errno = sd_session_get_class (sessions[i], &class);
- if (saved_errno < 0)
- {
- g_warning ("Couldn't get class for session '%d': %s",
- i,
- g_strerror (-saved_errno));
- continue;
- }
-
- if (g_strcmp0 (class, "greeter") == 0)
- {
- local_session_id = g_strdup (sessions[i]);
- break;
- }
- }
-
- if (!local_session_id)
- {
- g_set_error (error,
- G_IO_ERROR,
- G_IO_ERROR_NOT_FOUND,
- "Couldn't find a session or a greeter session for user %d",
- getuid ());
- return FALSE;
- }
- }
- else
- {
- g_set_error (error,
- G_IO_ERROR,
- G_IO_ERROR_NOT_FOUND,
- "Couldn't get display for user %d: %s",
- getuid (),
- g_strerror (-saved_errno));
- return FALSE;
- }
- }
-
- /* sd_uid_get_display will return any session if there is no graphical
- * one, so let's check it really is graphical. */
- saved_errno = sd_session_get_type (local_session_id, &type);
- if (saved_errno < 0)
- {
- g_set_error (error,
- G_IO_ERROR,
- G_IO_ERROR_NOT_FOUND,
- "Couldn't get type for session '%s': %s",
- local_session_id,
- g_strerror (-saved_errno));
- return FALSE;
- }
-
- if (!g_strv_contains (graphical_session_types, type))
- {
- g_set_error (error,
- G_IO_ERROR,
- G_IO_ERROR_NOT_FOUND,
- "Session '%s' is not a graphical session (type: '%s')",
- local_session_id,
- type);
- return FALSE;
- }
-
- /* and display sessions can be 'closing' if they are logged out but
- * some processes are lingering; we shouldn't consider these */
- saved_errno = sd_session_get_state (local_session_id, &state);
- if (saved_errno < 0)
- {
- g_set_error (error,
- G_IO_ERROR,
- G_IO_ERROR_NOT_FOUND,
- "Couldn't get state for session '%s': %s",
- local_session_id,
- g_strerror (-saved_errno));
- return FALSE;
- }
-
- if (!g_strv_contains (active_states, state))
- {
- g_set_error (error,
- G_IO_ERROR,
- G_IO_ERROR_NOT_FOUND,
- "Session '%s' is not active",
- local_session_id);
- return FALSE;
- }
-
- *session_id = g_steal_pointer (&local_session_id);
-
- return TRUE;
-}
-
-static MetaDbusLogin1Session *
-get_session_proxy (GCancellable *cancellable,
- GError **error)
-{
- g_autofree char *proxy_path = NULL;
- g_autofree char *session_id = NULL;
- g_autoptr (GError) local_error = NULL;
- GDBusProxyFlags flags;
- MetaDbusLogin1Session *session_proxy;
-
- if (!find_systemd_session (&session_id, &local_error))
- {
- g_propagate_prefixed_error (error,
- g_steal_pointer (&local_error),
- "Could not get session ID: ");
- return NULL;
- }
-
- proxy_path = get_escaped_dbus_path ("/org/freedesktop/login1/session", session_id);
-
- flags = G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START;
- session_proxy =
- meta_dbus_login1_session_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
- flags,
- "org.freedesktop.login1",
- proxy_path,
- cancellable, error);
- if (!session_proxy)
- g_prefix_error(error, "Could not get session proxy: ");
-
- return session_proxy;
-}
-
-static MetaDbusLogin1Seat *
-get_seat_proxy (gchar *seat_id,
- GCancellable *cancellable,
- GError **error)
-{
- g_autofree char *seat_proxy_path = get_escaped_dbus_path ("/org/freedesktop/login1/seat", seat_id);
- GDBusProxyFlags flags;
- MetaDbusLogin1Seat *seat;
-
- flags = G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START;
- seat =
- meta_dbus_login1_seat_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
- flags,
- "org.freedesktop.login1",
- seat_proxy_path,
- cancellable, error);
- if (!seat)
- g_prefix_error(error, "Could not get seat proxy: ");
-
- return seat;
-}
-
-static void
-sync_active (MetaLauncher *self)
-{
- MetaBackend *backend = meta_get_backend ();
- MetaBackendNative *backend_native = META_BACKEND_NATIVE (backend);
- MetaDbusLogin1Session *session_proxy = self->session_proxy;
- gboolean active;
-
- active = meta_dbus_login1_session_get_active (session_proxy);
- if (active == self->session_active)
- return;
-
- self->session_active = active;
-
- if (active)
- meta_backend_native_resume (backend_native);
- else
- meta_backend_native_pause (backend_native);
-}
-
-static void
-on_active_changed (MetaDbusLogin1Session *session,
- GParamSpec *pspec,
- gpointer user_data)
-{
- MetaLauncher *self = user_data;
- sync_active (self);
-}
-
-static gchar *
-get_seat_id (GError **error)
-{
- g_autoptr (GError) local_error = NULL;
- g_autofree char *session_id = NULL;
- char *seat_id = NULL;
- int r;
-
- if (!find_systemd_session (&session_id, &local_error))
- {
- g_propagate_prefixed_error (error,
- g_steal_pointer (&local_error),
- "Could not get session ID: ");
- return NULL;
- }
-
- r = sd_session_get_seat (session_id, &seat_id);
- if (r < 0)
- {
- g_set_error (error,
- G_IO_ERROR,
- G_IO_ERROR_NOT_FOUND,
- "Could not get seat for session: %s", g_strerror (-r));
- return NULL;
- }
-
- return seat_id;
-}
-
-MetaDbusLogin1Session *
-meta_launcher_get_session_proxy (MetaLauncher *launcher)
-{
- return launcher->session_proxy;
-}
-
-MetaLauncher *
-meta_launcher_new (GError **error)
-{
- MetaLauncher *self = NULL;
- g_autoptr (MetaDbusLogin1Session) session_proxy = NULL;
- g_autoptr (MetaDbusLogin1Seat) seat_proxy = NULL;
- g_autofree char *seat_id = NULL;
- gboolean have_control = FALSE;
-
- session_proxy = get_session_proxy (NULL, error);
- if (!session_proxy)
- goto fail;
-
- if (!meta_dbus_login1_session_call_take_control_sync (session_proxy,
- FALSE,
- NULL,
- error))
- {
- g_prefix_error (error, "Could not take control: ");
- goto fail;
- }
-
- have_control = TRUE;
-
- seat_id = get_seat_id (error);
- if (!seat_id)
- goto fail;
-
- seat_proxy = get_seat_proxy (seat_id, NULL, error);
- if (!seat_proxy)
- goto fail;
-
- self = g_new0 (MetaLauncher, 1);
- self->session_proxy = g_object_ref (session_proxy);
- self->seat_proxy = g_object_ref (seat_proxy);
- self->seat_id = g_steal_pointer (&seat_id);
- self->session_active = TRUE;
-
- g_signal_connect (self->session_proxy, "notify::active", G_CALLBACK (on_active_changed), self);
-
- return self;
-
- fail:
- if (have_control)
- {
- meta_dbus_login1_session_call_release_control_sync (session_proxy,
- NULL, NULL);
- }
- return NULL;
-}
-
-void
-meta_launcher_free (MetaLauncher *self)
-{
- g_free (self->seat_id);
- g_object_unref (self->seat_proxy);
- g_object_unref (self->session_proxy);
- g_free (self);
-}
-
-gboolean
-meta_launcher_activate_vt (MetaLauncher *launcher,
- signed char vt,
- GError **error)
-{
- return meta_dbus_login1_seat_call_switch_to_sync (launcher->seat_proxy, vt,
- NULL, error);
-}
diff --git a/src/backends/native/meta-launcher.h b/src/backends/native/meta-launcher.h
deleted file mode 100644
index 267b68337..000000000
--- a/src/backends/native/meta-launcher.h
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright (C) 2013 Red Hat, Inc.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-
-#ifndef META_LAUNCHER_H
-#define META_LAUNCHER_H
-
-#include <glib-object.h>
-
-typedef struct _MetaLauncher MetaLauncher;
-typedef struct _MetaDbusLogin1Session MetaDbusLogin1Session;
-
-MetaLauncher *meta_launcher_new (GError **error);
-void meta_launcher_free (MetaLauncher *self);
-
-gboolean meta_launcher_activate_vt (MetaLauncher *self,
- signed char vt,
- GError **error);
-
-const char * meta_launcher_get_seat_id (MetaLauncher *launcher);
-
-MetaDbusLogin1Session * meta_launcher_get_session_proxy (MetaLauncher *launcher);
-
-
-#endif /* META_LAUNCHER_H */
diff --git a/src/backends/native/meta-monitor-manager-native.c b/src/backends/native/meta-monitor-manager-native.c
deleted file mode 100644
index fd5e7784f..000000000
--- a/src/backends/native/meta-monitor-manager-native.c
+++ /dev/null
@@ -1,825 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2013 Red Hat Inc.
- * Copyright (C) 2018 DisplayLink (UK) Ltd.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Author: Giovanni Campagna <gcampagn@redhat.com>
- */
-
-/**
- * SECTION:meta-monitor-manager-native
- * @title: MetaMonitorManagerNative
- * @short_description: A subclass of #MetaMonitorManager using Linux DRM
- *
- * #MetaMonitorManagerNative is a subclass of #MetaMonitorManager which
- * implements its functionality "natively": it uses the appropriate
- * functions of the Linux DRM kernel module and using a udev client.
- *
- * See also #MetaMonitorManagerXrandr for an implementation using XRandR.
- */
-
-#include "config.h"
-
-#include "backends/native/meta-monitor-manager-native.h"
-
-#include <drm.h>
-#include <errno.h>
-#include <gudev/gudev.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/ioctl.h>
-#include <sys/mman.h>
-#include <unistd.h>
-
-#include "backends/meta-backend-private.h"
-#include "backends/meta-crtc.h"
-#include "backends/meta-monitor-config-manager.h"
-#include "backends/meta-output.h"
-#include "backends/native/meta-backend-native.h"
-#include "backends/native/meta-crtc-kms.h"
-#include "backends/native/meta-gpu-kms.h"
-#include "backends/native/meta-kms-update.h"
-#include "backends/native/meta-kms.h"
-#include "backends/native/meta-launcher.h"
-#include "backends/native/meta-output-kms.h"
-#include "backends/native/meta-renderer-native.h"
-#include "backends/native/meta-virtual-monitor-native.h"
-#include "clutter/clutter.h"
-#include "meta/main.h"
-#include "meta/meta-x11-errors.h"
-
-enum
-{
- PROP_0,
-
- PROP_NEED_OUTPUTS,
-
- N_PROPS
-};
-
-static GParamSpec *obj_props[N_PROPS];
-
-struct _MetaMonitorManagerNative
-{
- MetaMonitorManager parent_instance;
-
- gulong kms_resources_changed_handler_id;
-
- GHashTable *crtc_gamma_cache;
-
- gboolean needs_outputs;
-};
-
-struct _MetaMonitorManagerNativeClass
-{
- MetaMonitorManagerClass parent_class;
-};
-
-#define VIRTUAL_OUTPUT_ID_BIT (((uint64_t) 1) << 63)
-
-static void
-initable_iface_init (GInitableIface *initable_iface);
-
-G_DEFINE_TYPE_WITH_CODE (MetaMonitorManagerNative, meta_monitor_manager_native,
- META_TYPE_MONITOR_MANAGER,
- G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE,
- initable_iface_init))
-
-static GBytes *
-meta_monitor_manager_native_read_edid (MetaMonitorManager *manager,
- MetaOutput *output)
-{
- return meta_output_native_read_edid (META_OUTPUT_NATIVE (output));
-}
-
-static void
-meta_monitor_manager_native_read_current_state (MetaMonitorManager *manager)
-{
- MetaMonitorManagerClass *parent_class =
- META_MONITOR_MANAGER_CLASS (meta_monitor_manager_native_parent_class);
- MetaPowerSave power_save_mode;
-
- power_save_mode = meta_monitor_manager_get_power_save_mode (manager);
- if (power_save_mode != META_POWER_SAVE_ON)
- meta_monitor_manager_power_save_mode_changed (manager,
- META_POWER_SAVE_ON);
-
- parent_class->read_current_state (manager);
-}
-
-uint64_t
-meta_power_save_to_dpms_state (MetaPowerSave power_save)
-{
- switch (power_save)
- {
- case META_POWER_SAVE_ON:
- return DRM_MODE_DPMS_ON;
- case META_POWER_SAVE_STANDBY:
- return DRM_MODE_DPMS_STANDBY;
- case META_POWER_SAVE_SUSPEND:
- return DRM_MODE_DPMS_SUSPEND;
- case META_POWER_SAVE_OFF:
- return DRM_MODE_DPMS_OFF;
- case META_POWER_SAVE_UNSUPPORTED:
- return DRM_MODE_DPMS_ON;
- }
-
- g_warn_if_reached ();
- return DRM_MODE_DPMS_ON;
-}
-
-static void
-meta_monitor_manager_native_set_power_save_mode (MetaMonitorManager *manager,
- MetaPowerSave mode)
-{
- MetaBackend *backend = meta_monitor_manager_get_backend (manager);
- MetaBackendNative *backend_native = META_BACKEND_NATIVE (backend);
- MetaKms *kms = meta_backend_native_get_kms (backend_native);
- GList *l;
-
- for (l = meta_backend_get_gpus (backend); l; l = l->next)
- {
- MetaGpuKms *gpu_kms = l->data;
-
- switch (mode)
- {
- case META_POWER_SAVE_ON:
- case META_POWER_SAVE_UNSUPPORTED:
- {
- g_list_foreach (meta_gpu_get_crtcs (META_GPU (gpu_kms)),
- (GFunc) meta_crtc_kms_invalidate_gamma,
- NULL);
- break;
- }
- case META_POWER_SAVE_STANDBY:
- case META_POWER_SAVE_SUSPEND:
- case META_POWER_SAVE_OFF:
- {
- MetaKmsDevice *kms_device = meta_gpu_kms_get_kms_device (gpu_kms);
- MetaKmsUpdate *kms_update;
- MetaKmsUpdateFlag flags;
- g_autoptr (MetaKmsFeedback) kms_feedback = NULL;
-
- kms_update = meta_kms_ensure_pending_update (kms, kms_device);
- meta_kms_update_set_power_save (kms_update);
-
- flags = META_KMS_UPDATE_FLAG_NONE;
- kms_feedback = meta_kms_post_pending_update_sync (kms,
- kms_device,
- flags);
- if (meta_kms_feedback_get_result (kms_feedback) !=
- META_KMS_FEEDBACK_PASSED)
- {
- g_warning ("Failed to enter power saving mode: %s",
- meta_kms_feedback_get_error (kms_feedback)->message);
- }
- break;
- }
- }
- }
-}
-
-static void
-meta_monitor_manager_native_ensure_initial_config (MetaMonitorManager *manager)
-{
- MetaMonitorsConfig *config;
-
- config = meta_monitor_manager_ensure_configured (manager);
-
- meta_monitor_manager_update_logical_state (manager, config);
-}
-
-static void
-apply_crtc_assignments (MetaMonitorManager *manager,
- MetaCrtcAssignment **crtcs,
- unsigned int n_crtcs,
- MetaOutputAssignment **outputs,
- unsigned int n_outputs)
-{
- MetaBackend *backend = meta_monitor_manager_get_backend (manager);
- g_autoptr (GList) to_configure_outputs = NULL;
- g_autoptr (GList) to_configure_crtcs = NULL;
- unsigned i;
- GList *gpus;
- GList *l;
-
- gpus = meta_backend_get_gpus (backend);
- for (l = gpus; l; l = l->next)
- {
- MetaGpu *gpu = l->data;
- GList *crtcs;
- GList *outputs;
-
- outputs = g_list_copy (meta_gpu_get_outputs (gpu));
- to_configure_outputs = g_list_concat (to_configure_outputs, outputs);
-
- crtcs = g_list_copy (meta_gpu_get_crtcs (gpu));
- to_configure_crtcs = g_list_concat (to_configure_crtcs, crtcs);
- }
-
- for (l = meta_monitor_manager_get_virtual_monitors (manager); l; l = l->next)
- {
- MetaVirtualMonitor *virtual_monitor = l->data;
- MetaOutput *output = meta_virtual_monitor_get_output (virtual_monitor);
- MetaCrtc *crtc = meta_virtual_monitor_get_crtc (virtual_monitor);
-
- to_configure_outputs = g_list_append (to_configure_outputs, output);
- to_configure_crtcs = g_list_append (to_configure_crtcs, crtc);
- }
-
- for (i = 0; i < n_crtcs; i++)
- {
- MetaCrtcAssignment *crtc_assignment = crtcs[i];
- MetaCrtc *crtc = crtc_assignment->crtc;
-
- to_configure_crtcs = g_list_remove (to_configure_crtcs, crtc);
-
- if (crtc_assignment->mode == NULL)
- {
- meta_crtc_unset_config (crtc);
- }
- else
- {
- unsigned int j;
-
- meta_crtc_set_config (crtc,
- &crtc_assignment->layout,
- crtc_assignment->mode,
- crtc_assignment->transform);
-
- for (j = 0; j < crtc_assignment->outputs->len; j++)
- {
- MetaOutput *output = g_ptr_array_index (crtc_assignment->outputs,
- j);
- MetaOutputAssignment *output_assignment;
-
- to_configure_outputs = g_list_remove (to_configure_outputs,
- output);
-
- output_assignment = meta_find_output_assignment (outputs,
- n_outputs,
- output);
- meta_output_assign_crtc (output, crtc, output_assignment);
- }
- }
- }
-
- g_list_foreach (to_configure_crtcs,
- (GFunc) meta_crtc_unset_config,
- NULL);
- g_list_foreach (to_configure_outputs,
- (GFunc) meta_output_unassign_crtc,
- NULL);
-}
-
-static void
-update_screen_size (MetaMonitorManager *manager,
- MetaMonitorsConfig *config)
-{
- GList *l;
- int screen_width = 0;
- int screen_height = 0;
-
- for (l = config->logical_monitor_configs; l; l = l->next)
- {
- MetaLogicalMonitorConfig *logical_monitor_config = l->data;
- int right_edge;
- int bottom_edge;
-
- right_edge = (logical_monitor_config->layout.width +
- logical_monitor_config->layout.x);
- if (right_edge > screen_width)
- screen_width = right_edge;
-
- bottom_edge = (logical_monitor_config->layout.height +
- logical_monitor_config->layout.y);
- if (bottom_edge > screen_height)
- screen_height = bottom_edge;
- }
-
- manager->screen_width = screen_width;
- manager->screen_height = screen_height;
-}
-
-static gboolean
-meta_monitor_manager_native_apply_monitors_config (MetaMonitorManager *manager,
- MetaMonitorsConfig *config,
- MetaMonitorsConfigMethod method,
- GError **error)
-{
- GPtrArray *crtc_assignments;
- GPtrArray *output_assignments;
-
- if (!config)
- {
- if (!manager->in_init)
- {
- MetaBackend *backend = meta_get_backend ();
- MetaRenderer *renderer = meta_backend_get_renderer (backend);
-
- meta_renderer_native_reset_modes (META_RENDERER_NATIVE (renderer));
- }
-
- manager->screen_width = META_MONITOR_MANAGER_MIN_SCREEN_WIDTH;
- manager->screen_height = META_MONITOR_MANAGER_MIN_SCREEN_HEIGHT;
- meta_monitor_manager_rebuild (manager, NULL);
- return TRUE;
- }
-
- if (!meta_monitor_config_manager_assign (manager, config,
- &crtc_assignments,
- &output_assignments,
- error))
- return FALSE;
-
- if (method == META_MONITORS_CONFIG_METHOD_VERIFY)
- {
- g_ptr_array_free (crtc_assignments, TRUE);
- g_ptr_array_free (output_assignments, TRUE);
- return TRUE;
- }
-
- apply_crtc_assignments (manager,
- (MetaCrtcAssignment **) crtc_assignments->pdata,
- crtc_assignments->len,
- (MetaOutputAssignment **) output_assignments->pdata,
- output_assignments->len);
-
- g_ptr_array_free (crtc_assignments, TRUE);
- g_ptr_array_free (output_assignments, TRUE);
-
- update_screen_size (manager, config);
- meta_monitor_manager_rebuild (manager, config);
-
- return TRUE;
-}
-
-static void
-meta_monitor_manager_native_get_crtc_gamma (MetaMonitorManager *manager,
- MetaCrtc *crtc,
- gsize *size,
- unsigned short **red,
- unsigned short **green,
- unsigned short **blue)
-{
- MetaKmsCrtc *kms_crtc;
- const MetaKmsCrtcState *crtc_state;
-
- g_return_if_fail (META_IS_CRTC_KMS (crtc));
-
- kms_crtc = meta_crtc_kms_get_kms_crtc (META_CRTC_KMS (crtc));
- crtc_state = meta_kms_crtc_get_current_state (kms_crtc);
-
- *size = crtc_state->gamma.size;
- *red = g_memdup2 (crtc_state->gamma.red, *size * sizeof **red);
- *green = g_memdup2 (crtc_state->gamma.green, *size * sizeof **green);
- *blue = g_memdup2 (crtc_state->gamma.blue, *size * sizeof **blue);
-}
-
-static char *
-generate_gamma_ramp_string (size_t size,
- unsigned short *red,
- unsigned short *green,
- unsigned short *blue)
-{
- GString *string;
- int color;
-
- string = g_string_new ("[");
- for (color = 0; color < 3; color++)
- {
- unsigned short **color_ptr = NULL;
- char color_char;
- size_t i;
-
- switch (color)
- {
- case 0:
- color_ptr = &red;
- color_char = 'r';
- break;
- case 1:
- color_ptr = &green;
- color_char = 'g';
- break;
- case 2:
- color_ptr = &blue;
- color_char = 'b';
- break;
- }
-
- g_assert (color_ptr);
- g_string_append_printf (string, " %c: ", color_char);
- for (i = 0; i < MIN (4, size); i++)
- {
- int j;
-
- if (size > 4)
- {
- if (i == 2)
- g_string_append (string, ",...");
-
- if (i >= 2)
- j = i + (size - 4);
- else
- j = i;
- }
- else
- {
- j = i;
- }
- g_string_append_printf (string, "%s%hu",
- j == 0 ? "" : ",",
- (*color_ptr)[i]);
- }
- }
-
- g_string_append (string, " ]");
-
- return g_string_free (string, FALSE);
-}
-
-MetaKmsCrtcGamma *
-meta_monitor_manager_native_get_cached_crtc_gamma (MetaMonitorManagerNative *manager_native,
- MetaCrtcKms *crtc_kms)
-{
- uint64_t crtc_id;
-
- crtc_id = meta_crtc_get_id (META_CRTC (crtc_kms));
- return g_hash_table_lookup (manager_native->crtc_gamma_cache,
- GUINT_TO_POINTER (crtc_id));
-}
-
-static void
-meta_monitor_manager_native_set_crtc_gamma (MetaMonitorManager *manager,
- MetaCrtc *crtc,
- gsize size,
- unsigned short *red,
- unsigned short *green,
- unsigned short *blue)
-{
- MetaMonitorManagerNative *manager_native =
- META_MONITOR_MANAGER_NATIVE (manager);
- MetaCrtcKms *crtc_kms;
- MetaKmsCrtc *kms_crtc;
- g_autofree char *gamma_ramp_string = NULL;
- MetaBackend *backend = meta_monitor_manager_get_backend (manager);
- ClutterStage *stage = CLUTTER_STAGE (meta_backend_get_stage (backend));
-
- g_return_if_fail (META_IS_CRTC_KMS (crtc));
-
- crtc_kms = META_CRTC_KMS (crtc);
- kms_crtc = meta_crtc_kms_get_kms_crtc (META_CRTC_KMS (crtc));
-
- g_hash_table_replace (manager_native->crtc_gamma_cache,
- GUINT_TO_POINTER (meta_crtc_get_id (crtc)),
- meta_kms_crtc_gamma_new (kms_crtc, size,
- red, green, blue));
-
- gamma_ramp_string = generate_gamma_ramp_string (size, red, green, blue);
- g_debug ("Setting CRTC (%" G_GUINT64_FORMAT ") gamma to %s",
- meta_crtc_get_id (crtc), gamma_ramp_string);
-
- meta_crtc_kms_invalidate_gamma (crtc_kms);
- clutter_stage_schedule_update (stage);
-}
-
-static void
-handle_hotplug_event (MetaMonitorManager *manager)
-{
- meta_monitor_manager_reload (manager);
-}
-
-static void
-on_kms_resources_changed (MetaKms *kms,
- MetaMonitorManager *manager)
-{
- handle_hotplug_event (manager);
-}
-
-static void
-meta_monitor_manager_native_connect_hotplug_handler (MetaMonitorManagerNative *manager_native)
-{
- MetaMonitorManager *manager = META_MONITOR_MANAGER (manager_native);
- MetaBackend *backend = meta_monitor_manager_get_backend (manager);
- MetaBackendNative *backend_native = META_BACKEND_NATIVE (backend);
- MetaKms *kms = meta_backend_native_get_kms (backend_native);
-
- manager_native->kms_resources_changed_handler_id =
- g_signal_connect (kms, "resources-changed",
- G_CALLBACK (on_kms_resources_changed), manager);
-}
-
-static void
-meta_monitor_manager_native_disconnect_hotplug_handler (MetaMonitorManagerNative *manager_native)
-{
- MetaMonitorManager *manager = META_MONITOR_MANAGER (manager_native);
- MetaBackend *backend = meta_monitor_manager_get_backend (manager);
- MetaBackendNative *backend_native = META_BACKEND_NATIVE (backend);
- MetaKms *kms = meta_backend_native_get_kms (backend_native);
-
- g_clear_signal_handler (&manager_native->kms_resources_changed_handler_id, kms);
-}
-
-void
-meta_monitor_manager_native_pause (MetaMonitorManagerNative *manager_native)
-{
- meta_monitor_manager_native_disconnect_hotplug_handler (manager_native);
-}
-
-void
-meta_monitor_manager_native_resume (MetaMonitorManagerNative *manager_native)
-{
- MetaMonitorManager *manager = META_MONITOR_MANAGER (manager_native);
- MetaBackend *backend = meta_monitor_manager_get_backend (manager);
- GList *l;
-
- meta_monitor_manager_native_connect_hotplug_handler (manager_native);
-
- for (l = meta_backend_get_gpus (backend); l; l = l->next)
- {
- MetaGpu *gpu = l->data;
-
- g_list_foreach (meta_gpu_get_crtcs (gpu),
- (GFunc) meta_crtc_kms_invalidate_gamma,
- NULL);
- }
-}
-
-static gboolean
-meta_monitor_manager_native_is_transform_handled (MetaMonitorManager *manager,
- MetaCrtc *crtc,
- MetaMonitorTransform transform)
-{
- return meta_crtc_native_is_transform_handled (META_CRTC_NATIVE (crtc),
- transform);
-}
-
-static float
-meta_monitor_manager_native_calculate_monitor_mode_scale (MetaMonitorManager *manager,
- MetaMonitor *monitor,
- MetaMonitorMode *monitor_mode)
-{
- return meta_monitor_calculate_mode_scale (monitor, monitor_mode);
-}
-
-static float *
-meta_monitor_manager_native_calculate_supported_scales (MetaMonitorManager *manager,
- MetaLogicalMonitorLayoutMode layout_mode,
- MetaMonitor *monitor,
- MetaMonitorMode *monitor_mode,
- int *n_supported_scales)
-{
- MetaMonitorScalesConstraint constraints =
- META_MONITOR_SCALES_CONSTRAINT_NONE;
-
- switch (layout_mode)
- {
- case META_LOGICAL_MONITOR_LAYOUT_MODE_LOGICAL:
- break;
- case META_LOGICAL_MONITOR_LAYOUT_MODE_PHYSICAL:
- constraints |= META_MONITOR_SCALES_CONSTRAINT_NO_FRAC;
- break;
- }
-
- return meta_monitor_calculate_supported_scales (monitor, monitor_mode,
- constraints,
- n_supported_scales);
-}
-
-static MetaMonitorManagerCapability
-meta_monitor_manager_native_get_capabilities (MetaMonitorManager *manager)
-{
- MetaBackend *backend = meta_monitor_manager_get_backend (manager);
- MetaSettings *settings = meta_backend_get_settings (backend);
- MetaMonitorManagerCapability capabilities =
- META_MONITOR_MANAGER_CAPABILITY_NONE;
-
- if (meta_settings_is_experimental_feature_enabled (
- settings,
- META_EXPERIMENTAL_FEATURE_SCALE_MONITOR_FRAMEBUFFER))
- capabilities |= META_MONITOR_MANAGER_CAPABILITY_LAYOUT_MODE;
-
- return capabilities;
-}
-
-static gboolean
-meta_monitor_manager_native_get_max_screen_size (MetaMonitorManager *manager,
- int *max_width,
- int *max_height)
-{
- return FALSE;
-}
-
-static MetaLogicalMonitorLayoutMode
-meta_monitor_manager_native_get_default_layout_mode (MetaMonitorManager *manager)
-{
- MetaBackend *backend = meta_monitor_manager_get_backend (manager);
- MetaSettings *settings = meta_backend_get_settings (backend);
-
- if (meta_settings_is_experimental_feature_enabled (
- settings,
- META_EXPERIMENTAL_FEATURE_SCALE_MONITOR_FRAMEBUFFER))
- return META_LOGICAL_MONITOR_LAYOUT_MODE_LOGICAL;
- else
- return META_LOGICAL_MONITOR_LAYOUT_MODE_PHYSICAL;
-}
-
-static MetaVirtualMonitorNative *
-find_virtual_monitor (MetaMonitorManagerNative *manager_native,
- uint64_t id)
-{
- MetaMonitorManager *manager = META_MONITOR_MANAGER (manager_native);
- GList *l;
-
- for (l = meta_monitor_manager_get_virtual_monitors (manager); l; l = l->next)
- {
- MetaVirtualMonitorNative *virtual_monitor_native = l->data;
-
- if (meta_virtual_monitor_native_get_id (virtual_monitor_native) == id)
- return virtual_monitor_native;
- }
-
- return NULL;
-}
-
-static uint64_t
-allocate_virtual_monitor_id (MetaMonitorManagerNative *manager_native)
-{
- uint64_t id;
-
- id = 0;
-
- while (TRUE)
- {
- if (!find_virtual_monitor (manager_native, id))
- return id;
-
- id++;
- }
-}
-
-static MetaVirtualMonitor *
-meta_monitor_manager_native_create_virtual_monitor (MetaMonitorManager *manager,
- const MetaVirtualMonitorInfo *info,
- GError **error)
-{
- MetaMonitorManagerNative *manager_native =
- META_MONITOR_MANAGER_NATIVE (manager);
- MetaVirtualMonitorNative *virtual_monitor_native;
- uint64_t id;
-
- id = allocate_virtual_monitor_id (manager_native);
- virtual_monitor_native = meta_virtual_monitor_native_new (id, info);
- return META_VIRTUAL_MONITOR (virtual_monitor_native);
-}
-
-static void
-meta_monitor_manager_native_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- MetaMonitorManagerNative *manager_native =
- META_MONITOR_MANAGER_NATIVE (object);
-
- switch (prop_id)
- {
- case PROP_NEED_OUTPUTS:
- manager_native->needs_outputs = g_value_get_boolean (value);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-
-static void
-meta_monitor_manager_native_dispose (GObject *object)
-{
- MetaMonitorManagerNative *manager_native =
- META_MONITOR_MANAGER_NATIVE (object);
-
- g_clear_pointer (&manager_native->crtc_gamma_cache,
- g_hash_table_unref);
-
- G_OBJECT_CLASS (meta_monitor_manager_native_parent_class)->dispose (object);
-}
-
-static gboolean
-meta_monitor_manager_native_initable_init (GInitable *initable,
- GCancellable *cancellable,
- GError **error)
-{
- MetaMonitorManagerNative *manager_native =
- META_MONITOR_MANAGER_NATIVE (initable);
- MetaMonitorManager *manager = META_MONITOR_MANAGER (manager_native);
- MetaBackend *backend = meta_monitor_manager_get_backend (manager);
- gboolean can_have_outputs;
- GList *l;
-
- meta_monitor_manager_native_connect_hotplug_handler (manager_native);
-
- can_have_outputs = FALSE;
- for (l = meta_backend_get_gpus (backend); l; l = l->next)
- {
- MetaGpuKms *gpu_kms = l->data;
-
- if (meta_gpu_kms_can_have_outputs (gpu_kms))
- {
- can_have_outputs = TRUE;
- break;
- }
- }
-
- if (manager_native->needs_outputs && !can_have_outputs)
- {
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND,
- "No GPUs with outputs found");
- return FALSE;
- }
-
- manager_native->crtc_gamma_cache =
- g_hash_table_new_full (NULL, NULL,
- NULL,
- (GDestroyNotify) meta_kms_crtc_gamma_free);
-
- return TRUE;
-}
-
-static void
-initable_iface_init (GInitableIface *initable_iface)
-{
- initable_iface->init = meta_monitor_manager_native_initable_init;
-}
-
-static void
-meta_monitor_manager_native_init (MetaMonitorManagerNative *manager_native)
-{
- manager_native->needs_outputs = TRUE;
-}
-
-static void
-meta_monitor_manager_native_class_init (MetaMonitorManagerNativeClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
- MetaMonitorManagerClass *manager_class = META_MONITOR_MANAGER_CLASS (klass);
-
- object_class->set_property = meta_monitor_manager_native_set_property;
- object_class->dispose = meta_monitor_manager_native_dispose;
-
- manager_class->read_edid =
- meta_monitor_manager_native_read_edid;
- manager_class->read_current_state =
- meta_monitor_manager_native_read_current_state;
- manager_class->ensure_initial_config =
- meta_monitor_manager_native_ensure_initial_config;
- manager_class->apply_monitors_config =
- meta_monitor_manager_native_apply_monitors_config;
- manager_class->set_power_save_mode =
- meta_monitor_manager_native_set_power_save_mode;
- manager_class->get_crtc_gamma =
- meta_monitor_manager_native_get_crtc_gamma;
- manager_class->set_crtc_gamma =
- meta_monitor_manager_native_set_crtc_gamma;
- manager_class->is_transform_handled =
- meta_monitor_manager_native_is_transform_handled;
- manager_class->calculate_monitor_mode_scale =
- meta_monitor_manager_native_calculate_monitor_mode_scale;
- manager_class->calculate_supported_scales =
- meta_monitor_manager_native_calculate_supported_scales;
- manager_class->get_capabilities =
- meta_monitor_manager_native_get_capabilities;
- manager_class->get_max_screen_size =
- meta_monitor_manager_native_get_max_screen_size;
- manager_class->get_default_layout_mode =
- meta_monitor_manager_native_get_default_layout_mode;
- manager_class->create_virtual_monitor =
- meta_monitor_manager_native_create_virtual_monitor;
-
- obj_props[PROP_NEED_OUTPUTS] =
- g_param_spec_boolean ("needs-outputs",
- "needs-outputs",
- "Whether any outputs are needed for operation",
- TRUE,
- G_PARAM_WRITABLE |
- G_PARAM_CONSTRUCT_ONLY |
- G_PARAM_STATIC_STRINGS);
- g_object_class_install_properties (object_class, N_PROPS, obj_props);
-}
diff --git a/src/backends/native/meta-monitor-manager-native.h b/src/backends/native/meta-monitor-manager-native.h
deleted file mode 100644
index 60f899734..000000000
--- a/src/backends/native/meta-monitor-manager-native.h
+++ /dev/null
@@ -1,49 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2001 Havoc Pennington
- * Copyright (C) 2003 Rob Adams
- * Copyright (C) 2004-2006 Elijah Newren
- * Copyright (C) 2013 Red Hat Inc.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef META_MONITOR_MANAGER_NATIVE_H
-#define META_MONITOR_MANAGER_NATIVE_H
-
-#include <xf86drm.h>
-#include <xf86drmMode.h>
-
-#include "backends/meta-monitor-manager-private.h"
-#include "backends/native/meta-crtc-kms.h"
-#include "backends/native/meta-kms-crtc.h"
-
-typedef struct _MetaGpuKms MetaGpuKms;
-
-#define META_TYPE_MONITOR_MANAGER_NATIVE (meta_monitor_manager_native_get_type ())
-G_DECLARE_FINAL_TYPE (MetaMonitorManagerNative, meta_monitor_manager_native,
- META, MONITOR_MANAGER_NATIVE,
- MetaMonitorManager)
-
-void meta_monitor_manager_native_pause (MetaMonitorManagerNative *manager_native);
-
-void meta_monitor_manager_native_resume (MetaMonitorManagerNative *manager_native);
-
-uint64_t meta_power_save_to_dpms_state (MetaPowerSave power_save);
-
-MetaKmsCrtcGamma * meta_monitor_manager_native_get_cached_crtc_gamma (MetaMonitorManagerNative *manager_native,
- MetaCrtcKms *crtc_kms);
-
-#endif /* META_MONITOR_MANAGER_NATIVE_H */
diff --git a/src/backends/native/meta-onscreen-native.c b/src/backends/native/meta-onscreen-native.c
deleted file mode 100644
index 77e5309e1..000000000
--- a/src/backends/native/meta-onscreen-native.c
+++ /dev/null
@@ -1,2137 +0,0 @@
-/*
- * Copyright (C) 2011 Intel Corporation.
- * Copyright (C) 2016-2020 Red Hat
- * Copyright (c) 2018,2019 DisplayLink (UK) Ltd.
- *
- * Permission is hereby granted, free of charge, to any person
- * obtaining a copy of this software and associated documentation
- * files (the "Software"), to deal in the Software without
- * restriction, including without limitation the rights to use, copy,
- * modify, merge, publish, distribute, sublicense, and/or sell copies
- * of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be
- * included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
- * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
- * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- *
- */
-
-#include "config.h"
-
-#include "backends/native/meta-onscreen-native.h"
-
-#include <drm_fourcc.h>
-
-#include "backends/meta-egl-ext.h"
-#include "backends/native/meta-cogl-utils.h"
-#include "backends/native/meta-crtc-kms.h"
-#include "backends/native/meta-device-pool.h"
-#include "backends/native/meta-drm-buffer-dumb.h"
-#include "backends/native/meta-drm-buffer-gbm.h"
-#include "backends/native/meta-drm-buffer-import.h"
-#include "backends/native/meta-drm-buffer.h"
-#include "backends/native/meta-kms-device.h"
-#include "backends/native/meta-kms-utils.h"
-#include "backends/native/meta-kms.h"
-#include "backends/native/meta-output-kms.h"
-#include "backends/native/meta-renderer-native-gles3.h"
-#include "backends/native/meta-renderer-native-private.h"
-
-typedef enum _MetaSharedFramebufferImportStatus
-{
- /* Not tried importing yet. */
- META_SHARED_FRAMEBUFFER_IMPORT_STATUS_NONE,
- /* Tried before and failed. */
- META_SHARED_FRAMEBUFFER_IMPORT_STATUS_FAILED,
- /* Tried before and succeeded. */
- META_SHARED_FRAMEBUFFER_IMPORT_STATUS_OK
-} MetaSharedFramebufferImportStatus;
-
-typedef struct _MetaOnscreenNativeSecondaryGpuState
-{
- MetaGpuKms *gpu_kms;
- MetaRendererNativeGpuData *renderer_gpu_data;
-
- EGLSurface egl_surface;
-
- struct {
- struct gbm_surface *surface;
- MetaDrmBuffer *current_fb;
- MetaDrmBuffer *next_fb;
- } gbm;
-
- struct {
- MetaDrmBufferDumb *current_dumb_fb;
- MetaDrmBufferDumb *dumb_fbs[2];
- } cpu;
-
- gboolean noted_primary_gpu_copy_ok;
- gboolean noted_primary_gpu_copy_failed;
- MetaSharedFramebufferImportStatus import_status;
-} MetaOnscreenNativeSecondaryGpuState;
-
-struct _MetaOnscreenNative
-{
- CoglOnscreenEgl parent;
-
- MetaRendererNative *renderer_native;
- MetaGpuKms *render_gpu;
- MetaOutput *output;
- MetaCrtc *crtc;
-
- MetaOnscreenNativeSecondaryGpuState *secondary_gpu_state;
-
- struct {
- struct gbm_surface *surface;
- MetaDrmBuffer *current_fb;
- MetaDrmBuffer *next_fb;
- } gbm;
-
-#ifdef HAVE_EGL_DEVICE
- struct {
- EGLStreamKHR stream;
-
- MetaDrmBufferDumb *dumb_fb;
- } egl;
-#endif
-
- MetaRendererView *view;
-};
-
-G_DEFINE_TYPE (MetaOnscreenNative, meta_onscreen_native,
- COGL_TYPE_ONSCREEN_EGL)
-
-static gboolean
-init_secondary_gpu_state (MetaRendererNative *renderer_native,
- CoglOnscreen *onscreen,
- GError **error);
-
-static void
-swap_secondary_drm_fb (CoglOnscreen *onscreen)
-{
- MetaOnscreenNative *onscreen_native = META_ONSCREEN_NATIVE (onscreen);
- MetaOnscreenNativeSecondaryGpuState *secondary_gpu_state;
-
- secondary_gpu_state = onscreen_native->secondary_gpu_state;
- if (!secondary_gpu_state)
- return;
-
- g_set_object (&secondary_gpu_state->gbm.current_fb,
- secondary_gpu_state->gbm.next_fb);
- g_clear_object (&secondary_gpu_state->gbm.next_fb);
-}
-
-static void
-free_current_secondary_bo (CoglOnscreen *onscreen)
-{
- MetaOnscreenNative *onscreen_native = META_ONSCREEN_NATIVE (onscreen);
- MetaOnscreenNativeSecondaryGpuState *secondary_gpu_state;
-
- secondary_gpu_state = onscreen_native->secondary_gpu_state;
- if (!secondary_gpu_state)
- return;
-
- g_clear_object (&secondary_gpu_state->gbm.current_fb);
-}
-
-static void
-free_current_bo (CoglOnscreen *onscreen)
-{
- MetaOnscreenNative *onscreen_native = META_ONSCREEN_NATIVE (onscreen);
-
- g_clear_object (&onscreen_native->gbm.current_fb);
- free_current_secondary_bo (onscreen);
-}
-
-static void
-meta_onscreen_native_swap_drm_fb (CoglOnscreen *onscreen)
-{
- MetaOnscreenNative *onscreen_native = META_ONSCREEN_NATIVE (onscreen);
-
- if (!onscreen_native->gbm.next_fb)
- return;
-
- free_current_bo (onscreen);
-
- g_set_object (&onscreen_native->gbm.current_fb, onscreen_native->gbm.next_fb);
- g_clear_object (&onscreen_native->gbm.next_fb);
-
- swap_secondary_drm_fb (onscreen);
-}
-
-static void
-maybe_update_frame_info (MetaCrtc *crtc,
- CoglFrameInfo *frame_info,
- int64_t time_us,
- CoglFrameInfoFlag flags,
- unsigned int sequence)
-{
- const MetaCrtcConfig *crtc_config;
- const MetaCrtcModeInfo *crtc_mode_info;
- float refresh_rate;
-
- g_return_if_fail (crtc);
-
- crtc_config = meta_crtc_get_config (crtc);
- if (!crtc_config)
- return;
-
- crtc_mode_info = meta_crtc_mode_get_info (crtc_config->mode);
- refresh_rate = crtc_mode_info->refresh_rate;
- if (refresh_rate >= frame_info->refresh_rate)
- {
- frame_info->presentation_time_us = time_us;
- frame_info->refresh_rate = refresh_rate;
- frame_info->flags |= flags;
- frame_info->sequence = sequence;
- }
-}
-
-static void
-meta_onscreen_native_notify_frame_complete (CoglOnscreen *onscreen)
-{
- CoglFrameInfo *info;
-
- info = cogl_onscreen_pop_head_frame_info (onscreen);
-
- g_assert (!cogl_onscreen_peek_head_frame_info (onscreen));
-
- _cogl_onscreen_notify_frame_sync (onscreen, info);
- _cogl_onscreen_notify_complete (onscreen, info);
- cogl_object_unref (info);
-}
-
-static void
-notify_view_crtc_presented (MetaRendererView *view,
- MetaKmsCrtc *kms_crtc,
- int64_t time_us,
- CoglFrameInfoFlag flags,
- unsigned int sequence)
-{
- ClutterStageView *stage_view = CLUTTER_STAGE_VIEW (view);
- CoglFramebuffer *framebuffer =
- clutter_stage_view_get_onscreen (stage_view);
- CoglOnscreen *onscreen = COGL_ONSCREEN (framebuffer);
- CoglFrameInfo *frame_info;
- MetaCrtc *crtc;
-
- frame_info = cogl_onscreen_peek_head_frame_info (onscreen);
-
- crtc = META_CRTC (meta_crtc_kms_from_kms_crtc (kms_crtc));
- maybe_update_frame_info (crtc, frame_info, time_us, flags, sequence);
-
- meta_onscreen_native_notify_frame_complete (onscreen);
- meta_onscreen_native_swap_drm_fb (onscreen);
-}
-
-static int64_t
-timeval_to_microseconds (const struct timeval *tv)
-{
- return ((int64_t) tv->tv_sec) * G_USEC_PER_SEC + tv->tv_usec;
-}
-
-static void
-page_flip_feedback_flipped (MetaKmsCrtc *kms_crtc,
- unsigned int sequence,
- unsigned int tv_sec,
- unsigned int tv_usec,
- gpointer user_data)
-{
- MetaRendererView *view = user_data;
- struct timeval page_flip_time;
- MetaKmsDevice *kms_device;
- int64_t presentation_time_us;
- CoglFrameInfoFlag flags = COGL_FRAME_INFO_FLAG_VSYNC;
-
- page_flip_time = (struct timeval) {
- .tv_sec = tv_sec,
- .tv_usec = tv_usec,
- };
-
- kms_device = meta_kms_crtc_get_device (kms_crtc);
- if (meta_kms_device_uses_monotonic_clock (kms_device))
- {
- presentation_time_us = timeval_to_microseconds (&page_flip_time);
- flags |= COGL_FRAME_INFO_FLAG_HW_CLOCK;
- }
- else
- {
- /*
- * Other parts of the code assume MONOTONIC timestamps. So, if the device
- * timestamp isn't MONOTONIC, don't use it.
- */
- presentation_time_us = g_get_monotonic_time ();
- }
-
- notify_view_crtc_presented (view, kms_crtc,
- presentation_time_us,
- flags,
- sequence);
-}
-
-static void
-page_flip_feedback_ready (MetaKmsCrtc *kms_crtc,
- gpointer user_data)
-{
- MetaRendererView *view = user_data;
- CoglFramebuffer *framebuffer =
- clutter_stage_view_get_onscreen (CLUTTER_STAGE_VIEW (view));
- CoglOnscreen *onscreen = COGL_ONSCREEN (framebuffer);
- CoglFrameInfo *frame_info;
-
- frame_info = cogl_onscreen_peek_head_frame_info (onscreen);
- frame_info->flags |= COGL_FRAME_INFO_FLAG_SYMBOLIC;
-
- meta_onscreen_native_notify_frame_complete (onscreen);
-}
-
-static void
-page_flip_feedback_mode_set_fallback (MetaKmsCrtc *kms_crtc,
- gpointer user_data)
-{
- MetaRendererView *view = user_data;
- int64_t now_us;
-
- /*
- * We ended up not page flipping, thus we don't have a presentation time to
- * use. Lets use the next best thing: the current time.
- */
-
- now_us = g_get_monotonic_time ();
-
- notify_view_crtc_presented (view,
- kms_crtc,
- now_us,
- COGL_FRAME_INFO_FLAG_NONE,
- 0);
-}
-
-static void
-page_flip_feedback_discarded (MetaKmsCrtc *kms_crtc,
- gpointer user_data,
- const GError *error)
-{
- MetaRendererView *view = user_data;
- CoglFramebuffer *framebuffer =
- clutter_stage_view_get_onscreen (CLUTTER_STAGE_VIEW (view));
- CoglOnscreen *onscreen = COGL_ONSCREEN (framebuffer);
- CoglFrameInfo *frame_info;
-
- /*
- * Page flipping failed, but we want to fail gracefully, so to avoid freezing
- * the frame clock, emit a symbolic flip.
- */
-
- if (error &&
- !g_error_matches (error,
- G_IO_ERROR,
- G_IO_ERROR_PERMISSION_DENIED))
- g_warning ("Page flip discarded: %s", error->message);
-
- frame_info = cogl_onscreen_peek_head_frame_info (onscreen);
- frame_info->flags |= COGL_FRAME_INFO_FLAG_SYMBOLIC;
-
- meta_onscreen_native_notify_frame_complete (onscreen);
- meta_onscreen_native_swap_drm_fb (onscreen);
-}
-
-static const MetaKmsPageFlipListenerVtable page_flip_listener_vtable = {
- .flipped = page_flip_feedback_flipped,
- .ready = page_flip_feedback_ready,
- .mode_set_fallback = page_flip_feedback_mode_set_fallback,
- .discarded = page_flip_feedback_discarded,
-};
-
-static MetaEgl *
-meta_onscreen_native_get_egl (MetaOnscreenNative *onscreen_native)
-{
- MetaRendererNative *renderer_native = onscreen_native->renderer_native;
-
- return meta_renderer_native_get_egl (renderer_native);
-}
-
-#ifdef HAVE_EGL_DEVICE
-static int
-custom_egl_stream_page_flip (gpointer custom_page_flip_data,
- gpointer user_data)
-{
- CoglOnscreen *onscreen = custom_page_flip_data;
- MetaOnscreenNative *onscreen_native = META_ONSCREEN_NATIVE (onscreen);
- MetaRendererView *view = user_data;
- MetaEgl *egl = meta_onscreen_native_get_egl (onscreen_native);
- MetaRendererNativeGpuData *renderer_gpu_data;
- EGLDisplay *egl_display;
- EGLAttrib *acquire_attribs;
- g_autoptr (GError) error = NULL;
-
- acquire_attribs = (EGLAttrib[]) {
- EGL_DRM_FLIP_EVENT_DATA_NV,
- (EGLAttrib) view,
- EGL_NONE
- };
-
- renderer_gpu_data =
- meta_renderer_native_get_gpu_data (onscreen_native->renderer_native,
- onscreen_native->render_gpu);
-
- egl_display = renderer_gpu_data->egl_display;
- if (!meta_egl_stream_consumer_acquire_attrib (egl,
- egl_display,
- onscreen_native->egl.stream,
- acquire_attribs,
- &error))
- {
- if (g_error_matches (error, META_EGL_ERROR, EGL_RESOURCE_BUSY_EXT))
- return -EBUSY;
- else
- return -EINVAL;
- }
-
- return 0;
-}
-#endif /* HAVE_EGL_DEVICE */
-
-void
-meta_onscreen_native_dummy_power_save_page_flip (CoglOnscreen *onscreen)
-{
- CoglFrameInfo *frame_info;
-
- meta_onscreen_native_swap_drm_fb (onscreen);
-
- frame_info = cogl_onscreen_peek_tail_frame_info (onscreen);
- frame_info->flags |= COGL_FRAME_INFO_FLAG_SYMBOLIC;
- meta_onscreen_native_notify_frame_complete (onscreen);
-}
-
-static void
-meta_onscreen_native_flip_crtc (CoglOnscreen *onscreen,
- MetaRendererView *view,
- MetaCrtc *crtc,
- MetaKmsPageFlipListenerFlag flags)
-{
- MetaOnscreenNative *onscreen_native = META_ONSCREEN_NATIVE (onscreen);
- MetaRendererNative *renderer_native = onscreen_native->renderer_native;
- MetaGpuKms *render_gpu = onscreen_native->render_gpu;
- MetaCrtcKms *crtc_kms = META_CRTC_KMS (crtc);
- MetaKmsCrtc *kms_crtc = meta_crtc_kms_get_kms_crtc (crtc_kms);
- MetaRendererNativeGpuData *renderer_gpu_data;
- MetaGpuKms *gpu_kms;
- MetaKmsDevice *kms_device;
- MetaKms *kms;
- MetaKmsUpdate *kms_update;
- MetaOnscreenNativeSecondaryGpuState *secondary_gpu_state = NULL;
- MetaDrmBuffer *buffer;
-
- COGL_TRACE_BEGIN_SCOPED (MetaOnscreenNativeFlipCrtcs,
- "Onscreen (flip CRTCs)");
-
- gpu_kms = META_GPU_KMS (meta_crtc_get_gpu (crtc));
- kms_device = meta_gpu_kms_get_kms_device (gpu_kms);
- kms = meta_kms_device_get_kms (kms_device);
- kms_update = meta_kms_ensure_pending_update (kms, kms_device);
-
- g_assert (meta_gpu_kms_is_crtc_active (gpu_kms, crtc));
-
- renderer_gpu_data = meta_renderer_native_get_gpu_data (renderer_native,
- render_gpu);
- switch (renderer_gpu_data->mode)
- {
- case META_RENDERER_NATIVE_MODE_GBM:
- if (gpu_kms == render_gpu)
- {
- buffer = onscreen_native->gbm.next_fb;
- }
- else
- {
- secondary_gpu_state = onscreen_native->secondary_gpu_state;
- buffer = secondary_gpu_state->gbm.next_fb;
- }
-
- meta_crtc_kms_assign_primary_plane (crtc_kms, buffer, kms_update);
-
- break;
- case META_RENDERER_NATIVE_MODE_SURFACELESS:
- g_assert_not_reached ();
- break;
-#ifdef HAVE_EGL_DEVICE
- case META_RENDERER_NATIVE_MODE_EGL_DEVICE:
- meta_kms_update_set_custom_page_flip (kms_update,
- custom_egl_stream_page_flip,
- onscreen_native);
- break;
-#endif
- }
-
- meta_kms_update_add_page_flip_listener (kms_update,
- kms_crtc,
- &page_flip_listener_vtable,
- flags,
- g_object_ref (view),
- g_object_unref);
-}
-
-static void
-meta_onscreen_native_set_crtc_mode (CoglOnscreen *onscreen,
- MetaRendererNativeGpuData *renderer_gpu_data)
-{
- MetaOnscreenNative *onscreen_native = META_ONSCREEN_NATIVE (onscreen);
- MetaCrtcKms *crtc_kms = META_CRTC_KMS (onscreen_native->crtc);
- MetaKmsCrtc *kms_crtc = meta_crtc_kms_get_kms_crtc (crtc_kms);
- MetaKmsDevice *kms_device = meta_kms_crtc_get_device (kms_crtc);
- MetaKms *kms = meta_kms_device_get_kms (kms_device);
- MetaKmsUpdate *kms_update;
-
- COGL_TRACE_BEGIN_SCOPED (MetaOnscreenNativeSetCrtcModes,
- "Onscreen (set CRTC modes)");
-
- kms_update = meta_kms_ensure_pending_update (kms, kms_device);
-
- switch (renderer_gpu_data->mode)
- {
- case META_RENDERER_NATIVE_MODE_GBM:
- break;
- case META_RENDERER_NATIVE_MODE_SURFACELESS:
- g_assert_not_reached ();
- break;
-#ifdef HAVE_EGL_DEVICE
- case META_RENDERER_NATIVE_MODE_EGL_DEVICE:
- {
- MetaDrmBuffer *buffer;
-
- buffer = META_DRM_BUFFER (onscreen_native->egl.dumb_fb);
- meta_crtc_kms_assign_primary_plane (crtc_kms, buffer, kms_update);
- break;
- }
-#endif
- }
-
- meta_crtc_kms_set_mode (crtc_kms, kms_update);
- meta_output_kms_set_underscan (META_OUTPUT_KMS (onscreen_native->output),
- kms_update);
-}
-
-static void
-secondary_gpu_release_dumb (MetaOnscreenNativeSecondaryGpuState *secondary_gpu_state)
-{
- unsigned i;
-
- for (i = 0; i < G_N_ELEMENTS (secondary_gpu_state->cpu.dumb_fbs); i++)
- g_clear_object (&secondary_gpu_state->cpu.dumb_fbs[i]);
-}
-
-static void
-secondary_gpu_state_free (MetaOnscreenNativeSecondaryGpuState *secondary_gpu_state)
-{
- MetaGpu *gpu = META_GPU (secondary_gpu_state->gpu_kms);
- MetaBackend *backend = meta_gpu_get_backend (gpu);
- MetaEgl *egl = meta_backend_get_egl (backend);
-
- if (secondary_gpu_state->egl_surface != EGL_NO_SURFACE)
- {
- MetaRendererNativeGpuData *renderer_gpu_data;
-
- renderer_gpu_data = secondary_gpu_state->renderer_gpu_data;
- meta_egl_destroy_surface (egl,
- renderer_gpu_data->egl_display,
- secondary_gpu_state->egl_surface,
- NULL);
- }
-
- g_clear_object (&secondary_gpu_state->gbm.current_fb);
- g_clear_object (&secondary_gpu_state->gbm.next_fb);
- g_clear_pointer (&secondary_gpu_state->gbm.surface, gbm_surface_destroy);
-
- secondary_gpu_release_dumb (secondary_gpu_state);
-
- g_free (secondary_gpu_state);
-}
-
-static gboolean
-import_shared_framebuffer (CoglOnscreen *onscreen,
- MetaOnscreenNativeSecondaryGpuState *secondary_gpu_state)
-{
- MetaOnscreenNative *onscreen_native = META_ONSCREEN_NATIVE (onscreen);
- MetaGpuKms *gpu_kms;
- MetaDeviceFile *device_file;
- struct gbm_device *gbm_device;
- MetaDrmBufferGbm *buffer_gbm;
- MetaDrmBufferImport *buffer_import;
- g_autoptr (GError) error = NULL;
-
- buffer_gbm = META_DRM_BUFFER_GBM (onscreen_native->gbm.next_fb);
-
- gpu_kms = secondary_gpu_state->gpu_kms;
- device_file = secondary_gpu_state->renderer_gpu_data->device_file;
- gbm_device = meta_gbm_device_from_gpu (gpu_kms);
- buffer_import = meta_drm_buffer_import_new (device_file,
- gbm_device,
- buffer_gbm,
- &error);
- if (!buffer_import)
- {
- meta_topic (META_DEBUG_KMS,
- "Zero-copy disabled for %s, "
- "meta_drm_buffer_import_new failed: %s",
- meta_device_file_get_path (device_file),
- error->message);
-
- g_warn_if_fail (secondary_gpu_state->import_status ==
- META_SHARED_FRAMEBUFFER_IMPORT_STATUS_NONE);
-
- /*
- * Fall back. If META_SHARED_FRAMEBUFFER_IMPORT_STATUS_NONE is
- * in effect, we have COPY_MODE_PRIMARY prepared already, so we
- * simply retry with that path. Import status cannot be FAILED,
- * because we should not retry if failed once.
- *
- * If import status is OK, that is unexpected and we do not
- * have the fallback path prepared which means this output cannot
- * work anymore.
- */
- secondary_gpu_state->renderer_gpu_data->secondary.copy_mode =
- META_SHARED_FRAMEBUFFER_COPY_MODE_PRIMARY;
-
- secondary_gpu_state->import_status =
- META_SHARED_FRAMEBUFFER_IMPORT_STATUS_FAILED;
- return FALSE;
- }
-
- /*
- * next_fb may already contain a fallback buffer, so clear it only
- * when we are sure to succeed.
- */
- g_clear_object (&secondary_gpu_state->gbm.next_fb);
- secondary_gpu_state->gbm.next_fb = META_DRM_BUFFER (buffer_import);
-
- if (secondary_gpu_state->import_status ==
- META_SHARED_FRAMEBUFFER_IMPORT_STATUS_NONE)
- {
- /*
- * Clean up the cpu-copy part of
- * init_secondary_gpu_state_cpu_copy_mode ()
- */
- secondary_gpu_release_dumb (secondary_gpu_state);
-
- meta_topic (META_DEBUG_KMS,
- "Using zero-copy for %s succeeded once.",
- meta_device_file_get_path (device_file));
- }
-
- secondary_gpu_state->import_status =
- META_SHARED_FRAMEBUFFER_IMPORT_STATUS_OK;
- return TRUE;
-}
-
-static void
-copy_shared_framebuffer_gpu (CoglOnscreen *onscreen,
- MetaOnscreenNativeSecondaryGpuState *secondary_gpu_state,
- MetaRendererNativeGpuData *renderer_gpu_data,
- gboolean *egl_context_changed)
-{
- MetaOnscreenNative *onscreen_native = META_ONSCREEN_NATIVE (onscreen);
- MetaRendererNative *renderer_native = renderer_gpu_data->renderer_native;
- MetaEgl *egl = meta_renderer_native_get_egl (renderer_native);
- MetaGles3 *gles3 = meta_renderer_native_get_gles3 (renderer_native);
- GError *error = NULL;
- gboolean use_modifiers;
- MetaDeviceFile *device_file;
- MetaDrmBufferGbm *buffer_gbm;
- struct gbm_bo *bo;
-
- COGL_TRACE_BEGIN_SCOPED (CopySharedFramebufferSecondaryGpu,
- "FB Copy (secondary GPU)");
-
- g_warn_if_fail (secondary_gpu_state->gbm.next_fb == NULL);
- g_clear_object (&secondary_gpu_state->gbm.next_fb);
-
- if (!meta_egl_make_current (egl,
- renderer_gpu_data->egl_display,
- secondary_gpu_state->egl_surface,
- secondary_gpu_state->egl_surface,
- renderer_gpu_data->secondary.egl_context,
- &error))
- {
- g_warning ("Failed to make current: %s", error->message);
- g_error_free (error);
- return;
- }
-
- *egl_context_changed = TRUE;
-
-
- buffer_gbm = META_DRM_BUFFER_GBM (onscreen_native->gbm.next_fb);
- bo = meta_drm_buffer_gbm_get_bo (buffer_gbm);
- if (!meta_renderer_native_gles3_blit_shared_bo (egl,
- gles3,
- renderer_gpu_data->egl_display,
- renderer_gpu_data->secondary.egl_context,
- secondary_gpu_state->egl_surface,
- bo,
- &error))
- {
- g_warning ("Failed to blit shared framebuffer: %s", error->message);
- g_error_free (error);
- return;
- }
-
- if (!meta_egl_swap_buffers (egl,
- renderer_gpu_data->egl_display,
- secondary_gpu_state->egl_surface,
- &error))
- {
- g_warning ("Failed to swap buffers: %s", error->message);
- g_error_free (error);
- return;
- }
-
- use_modifiers = meta_renderer_native_use_modifiers (renderer_native);
- device_file = secondary_gpu_state->renderer_gpu_data->device_file;
- buffer_gbm =
- meta_drm_buffer_gbm_new_lock_front (device_file,
- secondary_gpu_state->gbm.surface,
- use_modifiers,
- &error);
- if (!buffer_gbm)
- {
- g_warning ("meta_drm_buffer_gbm_new_lock_front failed: %s",
- error->message);
- g_error_free (error);
- return;
- }
-
- secondary_gpu_state->gbm.next_fb = META_DRM_BUFFER (buffer_gbm);
-}
-
-static MetaDrmBufferDumb *
-secondary_gpu_get_next_dumb_buffer (MetaOnscreenNativeSecondaryGpuState *secondary_gpu_state)
-{
- MetaDrmBufferDumb *current_dumb_fb;
-
- current_dumb_fb = secondary_gpu_state->cpu.current_dumb_fb;
- if (current_dumb_fb == secondary_gpu_state->cpu.dumb_fbs[0])
- return secondary_gpu_state->cpu.dumb_fbs[1];
- else
- return secondary_gpu_state->cpu.dumb_fbs[0];
-}
-
-static gboolean
-copy_shared_framebuffer_primary_gpu (CoglOnscreen *onscreen,
- MetaOnscreenNativeSecondaryGpuState *secondary_gpu_state)
-{
- CoglFramebuffer *framebuffer = COGL_FRAMEBUFFER (onscreen);
- MetaOnscreenNative *onscreen_native = META_ONSCREEN_NATIVE (onscreen);
- MetaRendererNative *renderer_native = onscreen_native->renderer_native;
- MetaGpuKms *primary_gpu;
- MetaRendererNativeGpuData *primary_gpu_data;
- MetaDrmBufferDumb *buffer_dumb;
- MetaDrmBuffer *buffer;
- int width, height, stride;
- uint32_t drm_format;
- CoglFramebuffer *dmabuf_fb;
- int dmabuf_fd;
- g_autoptr (GError) error = NULL;
- CoglPixelFormat cogl_format;
- int ret;
-
- COGL_TRACE_BEGIN_SCOPED (CopySharedFramebufferPrimaryGpu,
- "FB Copy (primary GPU)");
-
- primary_gpu = meta_renderer_native_get_primary_gpu (renderer_native);
- primary_gpu_data =
- meta_renderer_native_get_gpu_data (renderer_native, primary_gpu);
- if (!primary_gpu_data->secondary.has_EGL_EXT_image_dma_buf_import_modifiers)
- return FALSE;
-
- buffer_dumb = secondary_gpu_get_next_dumb_buffer (secondary_gpu_state);
- buffer = META_DRM_BUFFER (buffer_dumb);
-
- width = meta_drm_buffer_get_width (buffer);
- height = meta_drm_buffer_get_height (buffer);
- stride = meta_drm_buffer_get_stride (buffer);
- drm_format = meta_drm_buffer_get_format (buffer);
-
- g_assert (cogl_framebuffer_get_width (framebuffer) == width);
- g_assert (cogl_framebuffer_get_height (framebuffer) == height);
-
- ret = meta_cogl_pixel_format_from_drm_format (drm_format,
- &cogl_format,
- NULL);
- g_assert (ret);
-
- dmabuf_fd = meta_drm_buffer_dumb_ensure_dmabuf_fd (buffer_dumb, &error);
- if (!dmabuf_fd)
- {
- meta_topic (META_DEBUG_KMS,
- "Failed to create DMA buffer: %s", error->message);
- return FALSE;
- }
-
- dmabuf_fb =
- meta_renderer_native_create_dma_buf_framebuffer (renderer_native,
- dmabuf_fd,
- width,
- height,
- stride,
- 0, DRM_FORMAT_MOD_LINEAR,
- drm_format,
- &error);
-
- if (error)
- {
- meta_topic (META_DEBUG_KMS,
- "Failed to create DMA buffer for blitting: %s",
- error->message);
- return FALSE;
- }
-
- if (!cogl_blit_framebuffer (framebuffer, COGL_FRAMEBUFFER (dmabuf_fb),
- 0, 0, 0, 0,
- width, height,
- &error))
- {
- g_object_unref (dmabuf_fb);
- return FALSE;
- }
-
- g_object_unref (dmabuf_fb);
-
- g_set_object (&secondary_gpu_state->gbm.next_fb, buffer);
- secondary_gpu_state->cpu.current_dumb_fb = buffer_dumb;
-
- return TRUE;
-}
-
-static void
-copy_shared_framebuffer_cpu (CoglOnscreen *onscreen,
- MetaOnscreenNativeSecondaryGpuState *secondary_gpu_state,
- MetaRendererNativeGpuData *renderer_gpu_data)
-{
- CoglFramebuffer *framebuffer = COGL_FRAMEBUFFER (onscreen);
- CoglContext *cogl_context = cogl_framebuffer_get_context (framebuffer);
- MetaDrmBufferDumb *buffer_dumb;
- MetaDrmBuffer *buffer;
- int width, height, stride;
- uint32_t drm_format;
- void *buffer_data;
- CoglBitmap *dumb_bitmap;
- CoglPixelFormat cogl_format;
- gboolean ret;
-
- COGL_TRACE_BEGIN_SCOPED (CopySharedFramebufferCpu,
- "FB Copy (CPU)");
-
- buffer_dumb = secondary_gpu_get_next_dumb_buffer (secondary_gpu_state);
- buffer = META_DRM_BUFFER (buffer_dumb);
-
- width = meta_drm_buffer_get_width (buffer);
- height = meta_drm_buffer_get_height (buffer);
- stride = meta_drm_buffer_get_stride (buffer);
- drm_format = meta_drm_buffer_get_format (buffer);
- buffer_data = meta_drm_buffer_dumb_get_data (buffer_dumb);
-
- g_assert (cogl_framebuffer_get_width (framebuffer) == width);
- g_assert (cogl_framebuffer_get_height (framebuffer) == height);
-
- ret = meta_cogl_pixel_format_from_drm_format (drm_format,
- &cogl_format,
- NULL);
- g_assert (ret);
-
- dumb_bitmap = cogl_bitmap_new_for_data (cogl_context,
- width,
- height,
- cogl_format,
- stride,
- buffer_data);
-
- if (!cogl_framebuffer_read_pixels_into_bitmap (framebuffer,
- 0 /* x */,
- 0 /* y */,
- COGL_READ_PIXELS_COLOR_BUFFER,
- dumb_bitmap))
- g_warning ("Failed to CPU-copy to a secondary GPU output");
-
- cogl_object_unref (dumb_bitmap);
-
- g_clear_object (&secondary_gpu_state->gbm.next_fb);
- secondary_gpu_state->gbm.next_fb = buffer;
- secondary_gpu_state->cpu.current_dumb_fb = buffer_dumb;
-}
-
-static void
-update_secondary_gpu_state_pre_swap_buffers (CoglOnscreen *onscreen)
-{
- MetaOnscreenNative *onscreen_native = META_ONSCREEN_NATIVE (onscreen);
- MetaOnscreenNativeSecondaryGpuState *secondary_gpu_state;
-
- COGL_TRACE_BEGIN_SCOPED (MetaRendererNativeGpuStatePreSwapBuffers,
- "Onscreen (secondary gpu pre-swap-buffers)");
-
- secondary_gpu_state = onscreen_native->secondary_gpu_state;
- if (secondary_gpu_state)
- {
- MetaRendererNativeGpuData *renderer_gpu_data;
- MetaDeviceFile *device_file;
-
- renderer_gpu_data = secondary_gpu_state->renderer_gpu_data;
- device_file = renderer_gpu_data->device_file;
- switch (renderer_gpu_data->secondary.copy_mode)
- {
- case META_SHARED_FRAMEBUFFER_COPY_MODE_SECONDARY_GPU:
- /* Done after eglSwapBuffers. */
- break;
- case META_SHARED_FRAMEBUFFER_COPY_MODE_ZERO:
- /* Done after eglSwapBuffers. */
- if (secondary_gpu_state->import_status ==
- META_SHARED_FRAMEBUFFER_IMPORT_STATUS_OK)
- break;
- /* prepare fallback */
- G_GNUC_FALLTHROUGH;
- case META_SHARED_FRAMEBUFFER_COPY_MODE_PRIMARY:
- if (!copy_shared_framebuffer_primary_gpu (onscreen,
- secondary_gpu_state))
- {
- if (!secondary_gpu_state->noted_primary_gpu_copy_failed)
- {
- meta_topic (META_DEBUG_KMS,
- "Using primary GPU to copy for %s failed once.",
- meta_device_file_get_path (device_file));
- secondary_gpu_state->noted_primary_gpu_copy_failed = TRUE;
- }
-
- copy_shared_framebuffer_cpu (onscreen,
- secondary_gpu_state,
- renderer_gpu_data);
- }
- else if (!secondary_gpu_state->noted_primary_gpu_copy_ok)
- {
- meta_topic (META_DEBUG_KMS,
- "Using primary GPU to copy for %s succeeded once.",
- meta_device_file_get_path (device_file));
- secondary_gpu_state->noted_primary_gpu_copy_ok = TRUE;
- }
- break;
- }
- }
-}
-
-static void
-update_secondary_gpu_state_post_swap_buffers (CoglOnscreen *onscreen,
- gboolean *egl_context_changed)
-{
- MetaOnscreenNative *onscreen_native = META_ONSCREEN_NATIVE (onscreen);
- MetaRendererNative *renderer_native = onscreen_native->renderer_native;
- MetaOnscreenNativeSecondaryGpuState *secondary_gpu_state;
-
- COGL_TRACE_BEGIN_SCOPED (MetaRendererNativeGpuStatePostSwapBuffers,
- "Onscreen (secondary gpu post-swap-buffers)");
-
- secondary_gpu_state = onscreen_native->secondary_gpu_state;
- if (secondary_gpu_state)
- {
- MetaRendererNativeGpuData *renderer_gpu_data;
-
- renderer_gpu_data =
- meta_renderer_native_get_gpu_data (renderer_native,
- secondary_gpu_state->gpu_kms);
-retry:
- switch (renderer_gpu_data->secondary.copy_mode)
- {
- case META_SHARED_FRAMEBUFFER_COPY_MODE_ZERO:
- if (!import_shared_framebuffer (onscreen,
- secondary_gpu_state))
- goto retry;
- break;
- case META_SHARED_FRAMEBUFFER_COPY_MODE_SECONDARY_GPU:
- copy_shared_framebuffer_gpu (onscreen,
- secondary_gpu_state,
- renderer_gpu_data,
- egl_context_changed);
- break;
- case META_SHARED_FRAMEBUFFER_COPY_MODE_PRIMARY:
- /* Done before eglSwapBuffers. */
- break;
- }
- }
-}
-
-static void
-ensure_crtc_modes (CoglOnscreen *onscreen)
-{
- MetaOnscreenNative *onscreen_native = META_ONSCREEN_NATIVE (onscreen);
- CoglFramebuffer *framebuffer = COGL_FRAMEBUFFER (onscreen);
- CoglContext *cogl_context = cogl_framebuffer_get_context (framebuffer);
- CoglRenderer *cogl_renderer = cogl_context->display->renderer;
- CoglRendererEGL *cogl_renderer_egl = cogl_renderer->winsys;
- MetaRendererNativeGpuData *renderer_gpu_data = cogl_renderer_egl->platform;
- MetaRendererNative *renderer_native = renderer_gpu_data->renderer_native;
-
- if (meta_renderer_native_pop_pending_mode_set (renderer_native,
- onscreen_native->view))
- meta_onscreen_native_set_crtc_mode (onscreen, renderer_gpu_data);
-}
-
-static void
-meta_onscreen_native_swap_buffers_with_damage (CoglOnscreen *onscreen,
- const int *rectangles,
- int n_rectangles,
- CoglFrameInfo *frame_info,
- gpointer user_data)
-{
- CoglFramebuffer *framebuffer = COGL_FRAMEBUFFER (onscreen);
- CoglContext *cogl_context = cogl_framebuffer_get_context (framebuffer);
- CoglDisplay *cogl_display = cogl_context_get_display (cogl_context);
- CoglRenderer *cogl_renderer = cogl_context->display->renderer;
- CoglRendererEGL *cogl_renderer_egl = cogl_renderer->winsys;
- MetaRendererNativeGpuData *renderer_gpu_data = cogl_renderer_egl->platform;
- MetaRendererNative *renderer_native = renderer_gpu_data->renderer_native;
- MetaRenderer *renderer = META_RENDERER (renderer_native);
- MetaBackend *backend = meta_renderer_get_backend (renderer);
- MetaBackendNative *backend_native = META_BACKEND_NATIVE (backend);
- MetaMonitorManager *monitor_manager =
- meta_backend_get_monitor_manager (backend);
- MetaKms *kms = meta_backend_native_get_kms (backend_native);
- MetaOnscreenNative *onscreen_native = META_ONSCREEN_NATIVE (onscreen);
- MetaGpuKms *render_gpu = onscreen_native->render_gpu;
- MetaDeviceFile *render_device_file;
- ClutterFrame *frame = user_data;
- CoglOnscreenClass *parent_class;
- gboolean egl_context_changed = FALSE;
- gboolean use_modifiers;
- MetaPowerSave power_save_mode;
- g_autoptr (GError) error = NULL;
- MetaDrmBufferGbm *buffer_gbm;
- MetaKmsCrtc *kms_crtc;
- MetaKmsDevice *kms_device;
- MetaKmsUpdateFlag flags;
- g_autoptr (MetaKmsFeedback) kms_feedback = NULL;
- const GError *feedback_error;
-
- COGL_TRACE_BEGIN_SCOPED (MetaRendererNativeSwapBuffers,
- "Onscreen (swap-buffers)");
-
- update_secondary_gpu_state_pre_swap_buffers (onscreen);
-
- parent_class = COGL_ONSCREEN_CLASS (meta_onscreen_native_parent_class);
- parent_class->swap_buffers_with_damage (onscreen,
- rectangles,
- n_rectangles,
- frame_info,
- user_data);
-
- renderer_gpu_data = meta_renderer_native_get_gpu_data (renderer_native,
- render_gpu);
- render_device_file = renderer_gpu_data->device_file;
- switch (renderer_gpu_data->mode)
- {
- case META_RENDERER_NATIVE_MODE_GBM:
- g_warn_if_fail (onscreen_native->gbm.next_fb == NULL);
- g_clear_object (&onscreen_native->gbm.next_fb);
-
- use_modifiers = meta_renderer_native_use_modifiers (renderer_native);
- buffer_gbm =
- meta_drm_buffer_gbm_new_lock_front (render_device_file,
- onscreen_native->gbm.surface,
- use_modifiers,
- &error);
- if (!buffer_gbm)
- {
- g_warning ("Failed to lock front buffer on %s: %s",
- meta_device_file_get_path (render_device_file),
- error->message);
- return;
- }
-
- onscreen_native->gbm.next_fb = META_DRM_BUFFER (buffer_gbm);
-
- break;
- case META_RENDERER_NATIVE_MODE_SURFACELESS:
- g_assert_not_reached ();
- break;
-#ifdef HAVE_EGL_DEVICE
- case META_RENDERER_NATIVE_MODE_EGL_DEVICE:
- break;
-#endif
- }
-
- update_secondary_gpu_state_post_swap_buffers (onscreen, &egl_context_changed);
-
- /*
- * If we changed EGL context, cogl will have the wrong idea about what is
- * current, making it fail to set it when it needs to. Avoid that by making
- * EGL_NO_CONTEXT current now, making cogl eventually set the correct
- * context.
- */
- if (egl_context_changed)
- _cogl_winsys_egl_ensure_current (cogl_display);
-
- power_save_mode = meta_monitor_manager_get_power_save_mode (monitor_manager);
- if (power_save_mode == META_POWER_SAVE_ON)
- {
- ensure_crtc_modes (onscreen);
- meta_onscreen_native_flip_crtc (onscreen,
- onscreen_native->view,
- onscreen_native->crtc,
- META_KMS_PAGE_FLIP_LISTENER_FLAG_NONE);
- }
- else
- {
- meta_renderer_native_queue_power_save_page_flip (renderer_native,
- onscreen);
- clutter_frame_set_result (frame,
- CLUTTER_FRAME_RESULT_PENDING_PRESENTED);
- return;
- }
-
- COGL_TRACE_BEGIN_SCOPED (MetaRendererNativePostKmsUpdate,
- "Onscreen (post pending update)");
- kms_crtc = meta_crtc_kms_get_kms_crtc (META_CRTC_KMS (onscreen_native->crtc));
- kms_device = meta_kms_crtc_get_device (kms_crtc);
-
- switch (renderer_gpu_data->mode)
- {
- case META_RENDERER_NATIVE_MODE_GBM:
- if (meta_renderer_native_has_pending_mode_sets (renderer_native))
- {
- meta_topic (META_DEBUG_KMS,
- "Postponing primary plane composite update for CRTC %u (%s)",
- meta_kms_crtc_get_id (kms_crtc),
- meta_kms_device_get_path (kms_device));
-
- clutter_frame_set_result (frame,
- CLUTTER_FRAME_RESULT_PENDING_PRESENTED);
- return;
- }
- else if (meta_renderer_native_has_pending_mode_set (renderer_native))
- {
- meta_topic (META_DEBUG_KMS, "Posting global mode set updates on %s",
- meta_kms_device_get_path (kms_device));
-
- meta_renderer_native_notify_mode_sets_reset (renderer_native);
- meta_renderer_native_post_mode_set_updates (renderer_native);
- clutter_frame_set_result (frame,
- CLUTTER_FRAME_RESULT_PENDING_PRESENTED);
- return;
- }
- break;
- case META_RENDERER_NATIVE_MODE_SURFACELESS:
- g_assert_not_reached ();
- break;
-#ifdef HAVE_EGL_DEVICE
- case META_RENDERER_NATIVE_MODE_EGL_DEVICE:
- if (meta_renderer_native_has_pending_mode_set (renderer_native))
- {
- meta_renderer_native_notify_mode_sets_reset (renderer_native);
- meta_renderer_native_post_mode_set_updates (renderer_native);
- clutter_frame_set_result (frame,
- CLUTTER_FRAME_RESULT_PENDING_PRESENTED);
- return;
- }
- break;
-#endif
- }
-
- meta_topic (META_DEBUG_KMS,
- "Posting primary plane composite update for CRTC %u (%s)",
- meta_kms_crtc_get_id (kms_crtc),
- meta_kms_device_get_path (kms_device));
-
- flags = META_KMS_UPDATE_FLAG_NONE;
- kms_feedback = meta_kms_post_pending_update_sync (kms, kms_device, flags);
-
- switch (meta_kms_feedback_get_result (kms_feedback))
- {
- case META_KMS_FEEDBACK_PASSED:
- clutter_frame_set_result (frame,
- CLUTTER_FRAME_RESULT_PENDING_PRESENTED);
- break;
- case META_KMS_FEEDBACK_FAILED:
- clutter_frame_set_result (frame,
- CLUTTER_FRAME_RESULT_PENDING_PRESENTED);
-
- feedback_error = meta_kms_feedback_get_error (kms_feedback);
- if (!g_error_matches (feedback_error,
- G_IO_ERROR,
- G_IO_ERROR_PERMISSION_DENIED))
- g_warning ("Failed to post KMS update: %s", feedback_error->message);
- break;
- }
-}
-
-gboolean
-meta_onscreen_native_is_buffer_scanout_compatible (CoglOnscreen *onscreen,
- uint32_t drm_format,
- uint64_t drm_modifier,
- uint32_t stride)
-{
- MetaOnscreenNative *onscreen_native = META_ONSCREEN_NATIVE (onscreen);
- const MetaCrtcConfig *crtc_config;
- MetaDrmBuffer *fb;
- struct gbm_bo *gbm_bo;
-
- crtc_config = meta_crtc_get_config (onscreen_native->crtc);
- if (crtc_config->transform != META_MONITOR_TRANSFORM_NORMAL)
- return FALSE;
-
- if (onscreen_native->secondary_gpu_state)
- return FALSE;
-
- if (!onscreen_native->gbm.surface)
- return FALSE;
-
- fb = onscreen_native->gbm.current_fb ? onscreen_native->gbm.current_fb
- : onscreen_native->gbm.next_fb;
- if (!fb)
- return FALSE;
-
- if (!META_IS_DRM_BUFFER_GBM (fb))
- return FALSE;
-
- gbm_bo = meta_drm_buffer_gbm_get_bo (META_DRM_BUFFER_GBM (fb));
-
- if (gbm_bo_get_format (gbm_bo) != drm_format)
- return FALSE;
-
- if (gbm_bo_get_modifier (gbm_bo) != drm_modifier)
- return FALSE;
-
- if (gbm_bo_get_stride (gbm_bo) != stride)
- return FALSE;
-
- return TRUE;
-}
-
-static gboolean
-meta_onscreen_native_direct_scanout (CoglOnscreen *onscreen,
- CoglScanout *scanout,
- CoglFrameInfo *frame_info,
- gpointer user_data,
- GError **error)
-{
- MetaOnscreenNative *onscreen_native = META_ONSCREEN_NATIVE (onscreen);
- MetaGpuKms *render_gpu = onscreen_native->render_gpu;
- CoglFramebuffer *framebuffer = COGL_FRAMEBUFFER (onscreen);
- CoglContext *cogl_context = cogl_framebuffer_get_context (framebuffer);
- CoglRenderer *cogl_renderer = cogl_context->display->renderer;
- CoglRendererEGL *cogl_renderer_egl = cogl_renderer->winsys;
- MetaRendererNativeGpuData *renderer_gpu_data = cogl_renderer_egl->platform;
- MetaRendererNative *renderer_native = renderer_gpu_data->renderer_native;
- MetaRenderer *renderer = META_RENDERER (renderer_native);
- MetaBackend *backend = meta_renderer_get_backend (renderer);
- MetaBackendNative *backend_native = META_BACKEND_NATIVE (backend);
- MetaKms *kms = meta_backend_native_get_kms (backend_native);
- MetaMonitorManager *monitor_manager =
- meta_backend_get_monitor_manager (backend);
- MetaPowerSave power_save_mode;
- ClutterFrame *frame = user_data;
- MetaDrmBuffer *scanout_buffer;
- GError *fill_timings_error = NULL;
- MetaKmsCrtc *kms_crtc;
- MetaKmsDevice *kms_device;
- MetaKmsUpdateFlag flags;
- g_autoptr (MetaKmsFeedback) kms_feedback = NULL;
- const GError *feedback_error;
-
- power_save_mode = meta_monitor_manager_get_power_save_mode (monitor_manager);
- if (power_save_mode != META_POWER_SAVE_ON)
- {
- g_set_error_literal (error,
- COGL_SCANOUT_ERROR,
- COGL_SCANOUT_ERROR_INHIBITED,
- "Direct scanout is inhibited during power saving mode");
- return FALSE;
- }
-
- if (meta_renderer_native_has_pending_mode_set (renderer_native))
- {
- g_set_error_literal (error,
- COGL_SCANOUT_ERROR,
- COGL_SCANOUT_ERROR_INHIBITED,
- "Direct scanout is inhibited when a mode set is pending");
- return FALSE;
- }
-
- renderer_gpu_data = meta_renderer_native_get_gpu_data (renderer_native,
- render_gpu);
-
- g_warn_if_fail (renderer_gpu_data->mode == META_RENDERER_NATIVE_MODE_GBM);
- g_warn_if_fail (!onscreen_native->gbm.next_fb);
-
- g_set_object (&onscreen_native->gbm.next_fb, META_DRM_BUFFER (scanout));
-
- /* Try to get a measurement of GPU rendering time on the scanout buffer.
- *
- * The successful operation here adds ~0.4 ms to a ~0.1 ms total frame clock
- * dispatch duration when displaying an unredirected client, thus
- * unfortunately bringing it more in line with duration of the regular
- * non-unredirected frame clock dispatch. However, measuring GPU rendering
- * time is important for computing accurate max render time without
- * underestimating. Also this operation should be optimizable by caching
- * EGLImage for each buffer instead of re-creating it every time it's needed.
- * This should also help all other cases which convert the buffer to a
- * EGLImage.
- */
- if (META_IS_DRM_BUFFER (scanout))
- {
- scanout_buffer = META_DRM_BUFFER (scanout);
- if (meta_drm_buffer_supports_fill_timings (scanout_buffer))
- {
- if (!meta_drm_buffer_fill_timings (scanout_buffer, frame_info,
- &fill_timings_error))
- {
- g_warning ("Failed to fill timings for a scanout buffer: %s",
- fill_timings_error->message);
- g_error_free (fill_timings_error);
- }
- }
- }
-
- ensure_crtc_modes (onscreen);
- meta_onscreen_native_flip_crtc (onscreen,
- onscreen_native->view,
- onscreen_native->crtc,
- META_KMS_PAGE_FLIP_LISTENER_FLAG_DROP_ON_ERROR);
-
- kms_crtc = meta_crtc_kms_get_kms_crtc (META_CRTC_KMS (onscreen_native->crtc));
- kms_device = meta_kms_crtc_get_device (kms_crtc);
-
- meta_topic (META_DEBUG_KMS,
- "Posting direct scanout update for CRTC %u (%s)",
- meta_kms_crtc_get_id (kms_crtc),
- meta_kms_device_get_path (kms_device));
-
- flags = META_KMS_UPDATE_FLAG_PRESERVE_ON_ERROR;
- kms_feedback = meta_kms_post_pending_update_sync (kms, kms_device, flags);
- switch (meta_kms_feedback_get_result (kms_feedback))
- {
- case META_KMS_FEEDBACK_PASSED:
- clutter_frame_set_result (frame,
- CLUTTER_FRAME_RESULT_PENDING_PRESENTED);
- break;
- case META_KMS_FEEDBACK_FAILED:
- feedback_error = meta_kms_feedback_get_error (kms_feedback);
-
- if (g_error_matches (feedback_error,
- G_IO_ERROR, G_IO_ERROR_PERMISSION_DENIED))
- break;
-
- g_clear_object (&onscreen_native->gbm.next_fb);
- g_propagate_error (error, g_error_copy (feedback_error));
- return FALSE;
- }
-
- return TRUE;
-}
-
-static void
-add_onscreen_frame_info (MetaCrtc *crtc)
-{
- MetaGpu *gpu = meta_crtc_get_gpu (crtc);
- MetaBackend *backend = meta_gpu_get_backend (gpu);
- ClutterStage *stage = CLUTTER_STAGE (meta_backend_get_stage (backend));
- ClutterStageWindow *stage_window = _clutter_stage_get_window (stage);
- MetaRenderer *renderer = meta_backend_get_renderer (backend);
- MetaRendererView *view = meta_renderer_get_view_for_crtc (renderer, crtc);
-
- meta_stage_impl_add_onscreen_frame_info (META_STAGE_IMPL (stage_window),
- CLUTTER_STAGE_VIEW (view));
-}
-
-void
-meta_onscreen_native_finish_frame (CoglOnscreen *onscreen,
- ClutterFrame *frame)
-{
- MetaOnscreenNative *onscreen_native = META_ONSCREEN_NATIVE (onscreen);
- MetaCrtc *crtc = onscreen_native->crtc;
- MetaKmsCrtc *kms_crtc = meta_crtc_kms_get_kms_crtc (META_CRTC_KMS (crtc));
- MetaKmsDevice *kms_device = meta_kms_crtc_get_device (kms_crtc);;
- MetaKms *kms = meta_kms_device_get_kms (kms_device);
- MetaKmsUpdateFlag flags;
- MetaKmsUpdate *kms_update;
- g_autoptr (MetaKmsFeedback) kms_feedback = NULL;
- const GError *error;
-
- kms_update = meta_kms_get_pending_update (kms, kms_device);
- if (!kms_update)
- {
- clutter_frame_set_result (frame, CLUTTER_FRAME_RESULT_IDLE);
- return;
- }
-
- meta_kms_update_add_page_flip_listener (kms_update,
- kms_crtc,
- &page_flip_listener_vtable,
- META_KMS_PAGE_FLIP_LISTENER_FLAG_NONE,
- g_object_ref (onscreen_native->view),
- g_object_unref);
-
- flags = META_KMS_UPDATE_FLAG_NONE;
- kms_feedback = meta_kms_post_pending_update_sync (kms,
- kms_device,
- flags);
- switch (meta_kms_feedback_get_result (kms_feedback))
- {
- case META_KMS_FEEDBACK_PASSED:
- add_onscreen_frame_info (crtc);
- clutter_frame_set_result (frame,
- CLUTTER_FRAME_RESULT_PENDING_PRESENTED);
- break;
- case META_KMS_FEEDBACK_FAILED:
- add_onscreen_frame_info (crtc);
- clutter_frame_set_result (frame,
- CLUTTER_FRAME_RESULT_PENDING_PRESENTED);
-
- error = meta_kms_feedback_get_error (kms_feedback);
- if (!g_error_matches (error,
- G_IO_ERROR,
- G_IO_ERROR_PERMISSION_DENIED))
- g_warning ("Failed to post KMS update: %s", error->message);
- break;
- }
-}
-
-static gboolean
-should_surface_be_sharable (CoglOnscreen *onscreen)
-{
- MetaOnscreenNative *onscreen_native = META_ONSCREEN_NATIVE (onscreen);
-
- if (META_GPU_KMS (meta_crtc_get_gpu (onscreen_native->crtc)) ==
- onscreen_native->render_gpu)
- return FALSE;
- else
- return TRUE;
-}
-
-static uint32_t
-get_gbm_format_from_egl (MetaEgl *egl,
- EGLDisplay egl_display,
- EGLConfig egl_config)
-{
- uint32_t gbm_format;
- EGLint native_visual_id;
-
- if (meta_egl_get_config_attrib (egl,
- egl_display,
- egl_config,
- EGL_NATIVE_VISUAL_ID,
- &native_visual_id,
- NULL))
- gbm_format = (uint32_t) native_visual_id;
- else
- g_assert_not_reached ();
-
- return gbm_format;
-}
-
-static GArray *
-get_supported_kms_modifiers (MetaCrtcKms *crtc_kms,
- uint32_t format)
-{
- GArray *modifiers;
- GArray *crtc_mods;
- unsigned int i;
-
- crtc_mods = meta_crtc_kms_get_modifiers (crtc_kms, format);
- if (!crtc_mods)
- return NULL;
-
- modifiers = g_array_new (FALSE, FALSE, sizeof (uint64_t));
-
- /*
- * For each modifier from base_crtc, check if it's available on all other
- * CRTCs.
- */
- for (i = 0; i < crtc_mods->len; i++)
- {
- uint64_t modifier = g_array_index (crtc_mods, uint64_t, i);
-
- g_array_append_val (modifiers, modifier);
- }
-
- if (modifiers->len == 0)
- {
- g_array_free (modifiers, TRUE);
- return NULL;
- }
-
- return modifiers;
-}
-
-static GArray *
-get_supported_egl_modifiers (CoglOnscreen *onscreen,
- MetaCrtcKms *crtc_kms,
- uint32_t format)
-{
- MetaOnscreenNative *onscreen_native = META_ONSCREEN_NATIVE (onscreen);
- MetaRendererNative *renderer_native = onscreen_native->renderer_native;
- MetaEgl *egl = meta_onscreen_native_get_egl (onscreen_native);
- MetaGpu *gpu;
- MetaRendererNativeGpuData *renderer_gpu_data;
- EGLint num_modifiers;
- GArray *modifiers;
- GError *error = NULL;
- gboolean ret;
-
- gpu = meta_crtc_get_gpu (META_CRTC (crtc_kms));
- renderer_gpu_data = meta_renderer_native_get_gpu_data (renderer_native,
- META_GPU_KMS (gpu));
-
- if (!meta_egl_has_extensions (egl, renderer_gpu_data->egl_display, NULL,
- "EGL_EXT_image_dma_buf_import_modifiers",
- NULL))
- return NULL;
-
- ret = meta_egl_query_dma_buf_modifiers (egl, renderer_gpu_data->egl_display,
- format, 0, NULL, NULL,
- &num_modifiers, NULL);
- if (!ret || num_modifiers == 0)
- return NULL;
-
- modifiers = g_array_sized_new (FALSE, FALSE, sizeof (uint64_t),
- num_modifiers);
- ret = meta_egl_query_dma_buf_modifiers (egl, renderer_gpu_data->egl_display,
- format, num_modifiers,
- (EGLuint64KHR *) modifiers->data, NULL,
- &num_modifiers, &error);
-
- if (!ret)
- {
- g_warning ("Failed to query DMABUF modifiers: %s", error->message);
- g_error_free (error);
- g_array_free (modifiers, TRUE);
- return NULL;
- }
-
- return modifiers;
-}
-
-static GArray *
-get_supported_modifiers (CoglOnscreen *onscreen,
- uint32_t format)
-{
- MetaOnscreenNative *onscreen_native = META_ONSCREEN_NATIVE (onscreen);
- MetaCrtcKms *crtc_kms = META_CRTC_KMS (onscreen_native->crtc);
- MetaGpu *gpu;
- g_autoptr (GArray) modifiers = NULL;
-
- gpu = meta_crtc_get_gpu (META_CRTC (crtc_kms));
- if (gpu == META_GPU (onscreen_native->render_gpu))
- modifiers = get_supported_kms_modifiers (crtc_kms, format);
- else
- modifiers = get_supported_egl_modifiers (onscreen, crtc_kms, format);
-
- return g_steal_pointer (&modifiers);
-}
-
-static GArray *
-get_supported_kms_formats (CoglOnscreen *onscreen)
-{
- MetaOnscreenNative *onscreen_native = META_ONSCREEN_NATIVE (onscreen);
- MetaCrtcKms *crtc_kms = META_CRTC_KMS (onscreen_native->crtc);
-
- return meta_crtc_kms_copy_drm_format_list (crtc_kms);
-}
-
-static gboolean
-create_surfaces_gbm (CoglOnscreen *onscreen,
- int width,
- int height,
- struct gbm_surface **gbm_surface,
- EGLSurface *egl_surface,
- GError **error)
-{
- MetaOnscreenNative *onscreen_native = META_ONSCREEN_NATIVE (onscreen);
- MetaRendererNative *renderer_native = onscreen_native->renderer_native;
- MetaEgl *egl = meta_onscreen_native_get_egl (onscreen_native);
- CoglFramebuffer *framebuffer = COGL_FRAMEBUFFER (onscreen);
- CoglContext *cogl_context = cogl_framebuffer_get_context (framebuffer);
- CoglDisplay *cogl_display = cogl_context->display;
- CoglDisplayEGL *cogl_display_egl = cogl_display->winsys;
- CoglRenderer *cogl_renderer = cogl_display->renderer;
- CoglRendererEGL *cogl_renderer_egl = cogl_renderer->winsys;
- MetaRendererNativeGpuData *renderer_gpu_data = cogl_renderer_egl->platform;
- struct gbm_surface *new_gbm_surface = NULL;
- EGLNativeWindowType egl_native_window;
- EGLSurface new_egl_surface;
- uint32_t format;
- GArray *modifiers;
-
- renderer_gpu_data =
- meta_renderer_native_get_gpu_data (renderer_native,
- onscreen_native->render_gpu);
-
- format = get_gbm_format_from_egl (egl,
- cogl_renderer_egl->edpy,
- cogl_display_egl->egl_config);
-
- if (meta_renderer_native_use_modifiers (renderer_native))
- modifiers = get_supported_modifiers (onscreen, format);
- else
- modifiers = NULL;
-
- if (modifiers)
- {
- new_gbm_surface =
- gbm_surface_create_with_modifiers (renderer_gpu_data->gbm.device,
- width, height, format,
- (uint64_t *) modifiers->data,
- modifiers->len);
- g_array_free (modifiers, TRUE);
- }
-
- if (!new_gbm_surface)
- {
- uint32_t flags = GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING;
-
- if (should_surface_be_sharable (onscreen))
- flags |= GBM_BO_USE_LINEAR;
-
- new_gbm_surface = gbm_surface_create (renderer_gpu_data->gbm.device,
- width, height,
- format,
- flags);
- }
-
- if (!new_gbm_surface)
- {
- g_set_error (error, COGL_WINSYS_ERROR,
- COGL_WINSYS_ERROR_CREATE_ONSCREEN,
- "Failed to allocate surface");
- return FALSE;
- }
-
- egl_native_window = (EGLNativeWindowType) new_gbm_surface;
- new_egl_surface =
- meta_egl_create_window_surface (egl,
- cogl_renderer_egl->edpy,
- cogl_display_egl->egl_config,
- egl_native_window,
- NULL,
- error);
- if (new_egl_surface == EGL_NO_SURFACE)
- {
- gbm_surface_destroy (new_gbm_surface);
- return FALSE;
- }
-
- *gbm_surface = new_gbm_surface;
- *egl_surface = new_egl_surface;
-
- return TRUE;
-}
-
-#ifdef HAVE_EGL_DEVICE
-static gboolean
-create_surfaces_egl_device (CoglOnscreen *onscreen,
- int width,
- int height,
- EGLStreamKHR *out_egl_stream,
- EGLSurface *out_egl_surface,
- GError **error)
-{
- CoglFramebuffer *framebuffer = COGL_FRAMEBUFFER (onscreen);
- MetaOnscreenNative *onscreen_native = META_ONSCREEN_NATIVE (onscreen);
- CoglContext *cogl_context = cogl_framebuffer_get_context (framebuffer);
- CoglDisplay *cogl_display = cogl_context->display;
- CoglDisplayEGL *cogl_display_egl = cogl_display->winsys;
- CoglRenderer *cogl_renderer = cogl_display->renderer;
- CoglRendererEGL *cogl_renderer_egl = cogl_renderer->winsys;
- MetaRendererNativeGpuData *renderer_gpu_data = cogl_renderer_egl->platform;
- MetaEgl *egl =
- meta_renderer_native_get_egl (renderer_gpu_data->renderer_native);
- EGLDisplay egl_display = renderer_gpu_data->egl_display;
- EGLConfig egl_config;
- EGLStreamKHR egl_stream;
- EGLSurface egl_surface;
- EGLint num_layers;
- EGLOutputLayerEXT output_layer;
- EGLAttrib output_attribs[3];
- EGLint stream_attribs[] = {
- EGL_STREAM_FIFO_LENGTH_KHR, 0,
- EGL_CONSUMER_AUTO_ACQUIRE_EXT, EGL_FALSE,
- EGL_NONE
- };
- EGLint stream_producer_attribs[] = {
- EGL_WIDTH, width,
- EGL_HEIGHT, height,
- EGL_NONE
- };
-
- egl_stream = meta_egl_create_stream (egl, egl_display, stream_attribs, error);
- if (egl_stream == EGL_NO_STREAM_KHR)
- return FALSE;
-
- output_attribs[0] = EGL_DRM_CRTC_EXT;
- output_attribs[1] = meta_crtc_get_id (onscreen_native->crtc);
- output_attribs[2] = EGL_NONE;
-
- if (!meta_egl_get_output_layers (egl, egl_display,
- output_attribs,
- &output_layer, 1, &num_layers,
- error))
- {
- meta_egl_destroy_stream (egl, egl_display, egl_stream, NULL);
- return FALSE;
- }
-
- if (num_layers < 1)
- {
- meta_egl_destroy_stream (egl, egl_display, egl_stream, NULL);
- g_set_error (error, G_IO_ERROR,
- G_IO_ERROR_FAILED,
- "Unable to find output layers.");
- return FALSE;
- }
-
- if (!meta_egl_stream_consumer_output (egl, egl_display,
- egl_stream, output_layer,
- error))
- {
- meta_egl_destroy_stream (egl, egl_display, egl_stream, NULL);
- return FALSE;
- }
-
- egl_config = cogl_display_egl->egl_config;
- egl_surface = meta_egl_create_stream_producer_surface (egl,
- egl_display,
- egl_config,
- egl_stream,
- stream_producer_attribs,
- error);
- if (egl_surface == EGL_NO_SURFACE)
- {
- meta_egl_destroy_stream (egl, egl_display, egl_stream, NULL);
- return FALSE;
- }
-
- *out_egl_stream = egl_stream;
- *out_egl_surface = egl_surface;
-
- return TRUE;
-}
-#endif /* HAVE_EGL_DEVICE */
-
-void
-meta_onscreen_native_set_view (CoglOnscreen *onscreen,
- MetaRendererView *view)
-{
- MetaOnscreenNative *onscreen_native = META_ONSCREEN_NATIVE (onscreen);
- onscreen_native->view = view;
-}
-
-static gboolean
-meta_onscreen_native_allocate (CoglFramebuffer *framebuffer,
- GError **error)
-{
- CoglOnscreen *onscreen = COGL_ONSCREEN (framebuffer);
- MetaOnscreenNative *onscreen_native = META_ONSCREEN_NATIVE (onscreen);
- CoglOnscreenEgl *onscreen_egl = COGL_ONSCREEN_EGL (onscreen);
- MetaRendererNativeGpuData *renderer_gpu_data;
- struct gbm_surface *gbm_surface;
- EGLSurface egl_surface;
- int width;
- int height;
-#ifdef HAVE_EGL_DEVICE
- MetaDeviceFile *render_device_file;
- EGLStreamKHR egl_stream;
-#endif
- CoglFramebufferClass *parent_class;
-
- if (META_GPU_KMS (meta_crtc_get_gpu (onscreen_native->crtc)) !=
- onscreen_native->render_gpu)
- {
- if (!init_secondary_gpu_state (onscreen_native->renderer_native,
- onscreen, error))
- return FALSE;
- }
-
- width = cogl_framebuffer_get_width (framebuffer);
- height = cogl_framebuffer_get_height (framebuffer);
-
- renderer_gpu_data =
- meta_renderer_native_get_gpu_data (onscreen_native->renderer_native,
- onscreen_native->render_gpu);
- switch (renderer_gpu_data->mode)
- {
- case META_RENDERER_NATIVE_MODE_GBM:
- if (!create_surfaces_gbm (onscreen,
- width, height,
- &gbm_surface,
- &egl_surface,
- error))
- return FALSE;
-
- onscreen_native->gbm.surface = gbm_surface;
- cogl_onscreen_egl_set_egl_surface (onscreen_egl, egl_surface);
- break;
- case META_RENDERER_NATIVE_MODE_SURFACELESS:
- g_assert_not_reached ();
- break;
-#ifdef HAVE_EGL_DEVICE
- case META_RENDERER_NATIVE_MODE_EGL_DEVICE:
- render_device_file = renderer_gpu_data->device_file;
- onscreen_native->egl.dumb_fb =
- meta_drm_buffer_dumb_new (render_device_file,
- width, height,
- DRM_FORMAT_XRGB8888,
- error);
- if (!onscreen_native->egl.dumb_fb)
- return FALSE;
-
- if (!create_surfaces_egl_device (onscreen,
- width, height,
- &egl_stream,
- &egl_surface,
- error))
- return FALSE;
-
- onscreen_native->egl.stream = egl_stream;
- cogl_onscreen_egl_set_egl_surface (onscreen_egl, egl_surface);
- break;
-#endif /* HAVE_EGL_DEVICE */
- }
-
- parent_class = COGL_FRAMEBUFFER_CLASS (meta_onscreen_native_parent_class);
- return parent_class->allocate (framebuffer, error);
-}
-
-static gboolean
-init_secondary_gpu_state_gpu_copy_mode (MetaRendererNative *renderer_native,
- CoglOnscreen *onscreen,
- MetaRendererNativeGpuData *renderer_gpu_data,
- GError **error)
-{
- CoglFramebuffer *framebuffer = COGL_FRAMEBUFFER (onscreen);
- MetaOnscreenNative *onscreen_native = META_ONSCREEN_NATIVE (onscreen);
- MetaEgl *egl = meta_onscreen_native_get_egl (onscreen_native);
- int width, height;
- EGLNativeWindowType egl_native_window;
- struct gbm_surface *gbm_surface;
- EGLSurface egl_surface;
- MetaOnscreenNativeSecondaryGpuState *secondary_gpu_state;
- MetaGpuKms *gpu_kms;
- uint32_t format;
-
- width = cogl_framebuffer_get_width (framebuffer);
- height = cogl_framebuffer_get_height (framebuffer);
- format = get_gbm_format_from_egl (egl,
- renderer_gpu_data->egl_display,
- renderer_gpu_data->secondary.egl_config);
-
- gbm_surface = gbm_surface_create (renderer_gpu_data->gbm.device,
- width, height,
- format,
- GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING);
- if (!gbm_surface)
- {
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- "Failed to create gbm_surface: %s", strerror (errno));
- return FALSE;
- }
-
- egl_native_window = (EGLNativeWindowType) gbm_surface;
- egl_surface =
- meta_egl_create_window_surface (egl,
- renderer_gpu_data->egl_display,
- renderer_gpu_data->secondary.egl_config,
- egl_native_window,
- NULL,
- error);
- if (egl_surface == EGL_NO_SURFACE)
- {
- gbm_surface_destroy (gbm_surface);
- return FALSE;
- }
-
- secondary_gpu_state = g_new0 (MetaOnscreenNativeSecondaryGpuState, 1);
-
- gpu_kms = META_GPU_KMS (meta_crtc_get_gpu (onscreen_native->crtc));
- secondary_gpu_state->gpu_kms = gpu_kms;
- secondary_gpu_state->renderer_gpu_data = renderer_gpu_data;
- secondary_gpu_state->gbm.surface = gbm_surface;
- secondary_gpu_state->egl_surface = egl_surface;
-
- onscreen_native->secondary_gpu_state = secondary_gpu_state;
-
- return TRUE;
-}
-
-static uint32_t
-pick_secondary_gpu_framebuffer_format_for_cpu (CoglOnscreen *onscreen)
-{
- /*
- * cogl_framebuffer_read_pixels_into_bitmap () supported formats in
- * preference order. Ideally these should depend on the render buffer
- * format copy_shared_framebuffer_cpu () will be reading from but
- * alpha channel ignored.
- */
- static const uint32_t preferred_formats[] =
- {
- /*
- * DRM_FORMAT_XBGR8888 a.k.a GL_RGBA, GL_UNSIGNED_BYTE on
- * little-endian is possibly the most optimized glReadPixels
- * output format. glReadPixels cannot avoid manufacturing an alpha
- * channel if the render buffer does not have one and converting
- * to ABGR8888 may be more optimized than ARGB8888.
- */
- DRM_FORMAT_XBGR8888,
- /* The rest are other fairly commonly used formats in OpenGL. */
- DRM_FORMAT_XRGB8888,
- };
- g_autoptr (GArray) formats = NULL;
- size_t k;
- unsigned int i;
- uint32_t drm_format;
-
- formats = get_supported_kms_formats (onscreen);
-
- /* Check if any of our preferred formats are supported. */
- for (k = 0; k < G_N_ELEMENTS (preferred_formats); k++)
- {
- g_assert (meta_cogl_pixel_format_from_drm_format (preferred_formats[k],
- NULL,
- NULL));
-
- for (i = 0; i < formats->len; i++)
- {
- drm_format = g_array_index (formats, uint32_t, i);
-
- if (drm_format == preferred_formats[k])
- return drm_format;
- }
- }
-
- /*
- * Otherwise just pick an arbitrary format we recognize. The formats
- * list is not in any specific order and we don't know any better
- * either.
- */
- for (i = 0; i < formats->len; i++)
- {
- drm_format = g_array_index (formats, uint32_t, i);
-
- if (meta_cogl_pixel_format_from_drm_format (drm_format, NULL, NULL))
- return drm_format;
- }
-
- return DRM_FORMAT_INVALID;
-}
-
-static gboolean
-init_secondary_gpu_state_cpu_copy_mode (MetaRendererNative *renderer_native,
- CoglOnscreen *onscreen,
- MetaRendererNativeGpuData *renderer_gpu_data,
- GError **error)
-{
- CoglFramebuffer *framebuffer = COGL_FRAMEBUFFER (onscreen);
- MetaOnscreenNative *onscreen_native = META_ONSCREEN_NATIVE (onscreen);
- MetaOnscreenNativeSecondaryGpuState *secondary_gpu_state;
- MetaGpuKms *gpu_kms;
- MetaDeviceFile *device_file;
- int width, height;
- unsigned int i;
- uint32_t drm_format;
- MetaDrmFormatBuf tmp;
-
- drm_format = pick_secondary_gpu_framebuffer_format_for_cpu (onscreen);
- if (drm_format == DRM_FORMAT_INVALID)
- {
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- "Could not find a suitable pixel format in CPU copy mode");
- return FALSE;
- }
-
- width = cogl_framebuffer_get_width (framebuffer);
- height = cogl_framebuffer_get_height (framebuffer);
-
- gpu_kms = META_GPU_KMS (meta_crtc_get_gpu (onscreen_native->crtc));
- device_file = renderer_gpu_data->device_file;
- meta_topic (META_DEBUG_KMS,
- "Secondary GPU %s using DRM format '%s' (0x%x) for a %dx%d output.",
- meta_device_file_get_path (device_file),
- meta_drm_format_to_string (&tmp, drm_format),
- drm_format,
- width, height);
-
- secondary_gpu_state = g_new0 (MetaOnscreenNativeSecondaryGpuState, 1);
- secondary_gpu_state->renderer_gpu_data = renderer_gpu_data;
- secondary_gpu_state->gpu_kms = gpu_kms;
- secondary_gpu_state->egl_surface = EGL_NO_SURFACE;
-
- for (i = 0; i < G_N_ELEMENTS (secondary_gpu_state->cpu.dumb_fbs); i++)
- {
- secondary_gpu_state->cpu.dumb_fbs[i] =
- meta_drm_buffer_dumb_new (device_file,
- width, height,
- drm_format,
- error);
- if (!secondary_gpu_state->cpu.dumb_fbs[i])
- {
- secondary_gpu_state_free (secondary_gpu_state);
- return FALSE;
- }
- }
-
- /*
- * This function initializes everything needed for
- * META_SHARED_FRAMEBUFFER_COPY_MODE_ZERO as well.
- */
- secondary_gpu_state->import_status =
- META_SHARED_FRAMEBUFFER_IMPORT_STATUS_NONE;
-
- onscreen_native->secondary_gpu_state = secondary_gpu_state;
-
- return TRUE;
-}
-
-static gboolean
-init_secondary_gpu_state (MetaRendererNative *renderer_native,
- CoglOnscreen *onscreen,
- GError **error)
-{
- MetaOnscreenNative *onscreen_native = META_ONSCREEN_NATIVE (onscreen);
- MetaGpu *gpu = meta_crtc_get_gpu (onscreen_native->crtc);
- MetaRendererNativeGpuData *renderer_gpu_data;
-
- renderer_gpu_data = meta_renderer_native_get_gpu_data (renderer_native,
- META_GPU_KMS (gpu));
-
- switch (renderer_gpu_data->secondary.copy_mode)
- {
- case META_SHARED_FRAMEBUFFER_COPY_MODE_SECONDARY_GPU:
- if (!init_secondary_gpu_state_gpu_copy_mode (renderer_native,
- onscreen,
- renderer_gpu_data,
- error))
- return FALSE;
- break;
- case META_SHARED_FRAMEBUFFER_COPY_MODE_ZERO:
- /*
- * Initialize also the primary copy mode, so that if zero-copy
- * path fails, which is quite likely, we can simply continue
- * with the primary copy path on the very first frame.
- */
- G_GNUC_FALLTHROUGH;
- case META_SHARED_FRAMEBUFFER_COPY_MODE_PRIMARY:
- if (!init_secondary_gpu_state_cpu_copy_mode (renderer_native,
- onscreen,
- renderer_gpu_data,
- error))
- return FALSE;
- break;
- }
-
- return TRUE;
-}
-
-MetaOnscreenNative *
-meta_onscreen_native_new (MetaRendererNative *renderer_native,
- MetaGpuKms *render_gpu,
- MetaOutput *output,
- MetaCrtc *crtc,
- CoglContext *cogl_context,
- int width,
- int height)
-{
- MetaOnscreenNative *onscreen_native;
- CoglFramebufferDriverConfig driver_config;
-
- driver_config = (CoglFramebufferDriverConfig) {
- .type = COGL_FRAMEBUFFER_DRIVER_TYPE_BACK,
- };
- onscreen_native = g_object_new (META_TYPE_ONSCREEN_NATIVE,
- "context", cogl_context,
- "driver-config", &driver_config,
- "width", width,
- "height", height,
- NULL);
-
- onscreen_native->renderer_native = renderer_native;
- onscreen_native->render_gpu = render_gpu;
- onscreen_native->output = output;
- onscreen_native->crtc = crtc;
-
- return onscreen_native;
-}
-
-static void
-meta_onscreen_native_dispose (GObject *object)
-{
- CoglFramebuffer *framebuffer = COGL_FRAMEBUFFER (object);
- CoglOnscreen *onscreen = COGL_ONSCREEN (framebuffer);
- MetaOnscreenNative *onscreen_native = META_ONSCREEN_NATIVE (onscreen);
- MetaRendererNative *renderer_native = onscreen_native->renderer_native;
- MetaRendererNativeGpuData *renderer_gpu_data;
-
- renderer_gpu_data =
- meta_renderer_native_get_gpu_data (renderer_native,
- onscreen_native->render_gpu);
- switch (renderer_gpu_data->mode)
- {
- case META_RENDERER_NATIVE_MODE_GBM:
- /* flip state takes a reference on the onscreen so there should
- * never be outstanding flips when we reach here. */
- g_warn_if_fail (onscreen_native->gbm.next_fb == NULL);
-
- free_current_bo (onscreen);
- break;
- case META_RENDERER_NATIVE_MODE_SURFACELESS:
- g_assert_not_reached ();
- break;
-#ifdef HAVE_EGL_DEVICE
- case META_RENDERER_NATIVE_MODE_EGL_DEVICE:
- g_clear_object (&onscreen_native->egl.dumb_fb);
-
- if (onscreen_native->egl.stream != EGL_NO_STREAM_KHR)
- {
- MetaEgl *egl = meta_onscreen_native_get_egl (onscreen_native);
- CoglContext *cogl_context = cogl_framebuffer_get_context (framebuffer);
- CoglRenderer *cogl_renderer = cogl_context->display->renderer;
- CoglRendererEGL *cogl_renderer_egl = cogl_renderer->winsys;
-
- meta_egl_destroy_stream (egl,
- cogl_renderer_egl->edpy,
- onscreen_native->egl.stream,
- NULL);
- onscreen_native->egl.stream = EGL_NO_STREAM_KHR;
- }
- break;
-#endif /* HAVE_EGL_DEVICE */
- }
-
- G_OBJECT_CLASS (meta_onscreen_native_parent_class)->dispose (object);
-
- g_clear_pointer (&onscreen_native->gbm.surface, gbm_surface_destroy);
- g_clear_pointer (&onscreen_native->secondary_gpu_state,
- secondary_gpu_state_free);
-}
-
-static void
-meta_onscreen_native_init (MetaOnscreenNative *onscreen_native)
-{
-}
-
-static void
-meta_onscreen_native_class_init (MetaOnscreenNativeClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
- CoglFramebufferClass *framebuffer_class = COGL_FRAMEBUFFER_CLASS (klass);
- CoglOnscreenClass *onscreen_class = COGL_ONSCREEN_CLASS (klass);
-
- object_class->dispose = meta_onscreen_native_dispose;
-
- framebuffer_class->allocate = meta_onscreen_native_allocate;
-
- onscreen_class->swap_buffers_with_damage =
- meta_onscreen_native_swap_buffers_with_damage;
- onscreen_class->direct_scanout = meta_onscreen_native_direct_scanout;
-}
diff --git a/src/backends/native/meta-onscreen-native.h b/src/backends/native/meta-onscreen-native.h
deleted file mode 100644
index 020fc8a14..000000000
--- a/src/backends/native/meta-onscreen-native.h
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Copyright (C) 2016-2020 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- */
-
-#ifndef META_ONSCREEN_NATIVE_H
-#define META_ONSCREEN_NATIVE_H
-
-#include <glib.h>
-
-#include "backends/meta-backend-types.h"
-#include "backends/native/meta-backend-native-types.h"
-#include "clutter/clutter.h"
-#include "cogl/cogl.h"
-
-#define META_TYPE_ONSCREEN_NATIVE (meta_onscreen_native_get_type ())
-G_DECLARE_FINAL_TYPE (MetaOnscreenNative, meta_onscreen_native,
- META, ONSCREEN_NATIVE,
- CoglOnscreenEgl)
-
-void meta_renderer_native_release_onscreen (CoglOnscreen *onscreen);
-
-void meta_onscreen_native_finish_frame (CoglOnscreen *onscreen,
- ClutterFrame *frame);
-
-void meta_onscreen_native_dummy_power_save_page_flip (CoglOnscreen *onscreen);
-
-gboolean meta_onscreen_native_is_buffer_scanout_compatible (CoglOnscreen *onscreen,
- uint32_t drm_format,
- uint64_t drm_modifier,
- uint32_t stride);
-
-void meta_onscreen_native_set_view (CoglOnscreen *onscreen,
- MetaRendererView *view);
-
-MetaOnscreenNative * meta_onscreen_native_new (MetaRendererNative *renderer_native,
- MetaGpuKms *render_gpu,
- MetaOutput *output,
- MetaCrtc *crtc,
- CoglContext *cogl_context,
- int width,
- int height);
-
-#endif /* META_ONSCREEN_NATIVE_H */
diff --git a/src/backends/native/meta-output-kms.c b/src/backends/native/meta-output-kms.c
deleted file mode 100644
index f35cdf04e..000000000
--- a/src/backends/native/meta-output-kms.c
+++ /dev/null
@@ -1,414 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2013-2017 Red Hat
- * Copyright (C) 2018 DisplayLink (UK) Ltd.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-
-#include "config.h"
-
-#include "backends/native/meta-output-kms.h"
-
-#include <errno.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "backends/meta-crtc.h"
-#include "backends/native/meta-kms-connector.h"
-#include "backends/native/meta-kms-device.h"
-#include "backends/native/meta-kms-mode.h"
-#include "backends/native/meta-kms-update.h"
-#include "backends/native/meta-kms-utils.h"
-#include "backends/native/meta-crtc-kms.h"
-#include "backends/native/meta-crtc-mode-kms.h"
-
-#define SYNC_TOLERANCE 0.01 /* 1 percent */
-
-struct _MetaOutputKms
-{
- MetaOutputNative parent;
-
- MetaKmsConnector *kms_connector;
-};
-
-G_DEFINE_TYPE (MetaOutputKms, meta_output_kms, META_TYPE_OUTPUT_NATIVE)
-
-MetaKmsConnector *
-meta_output_kms_get_kms_connector (MetaOutputKms *output_kms)
-{
- return output_kms->kms_connector;
-}
-
-void
-meta_output_kms_set_underscan (MetaOutputKms *output_kms,
- MetaKmsUpdate *kms_update)
-{
- MetaOutput *output = META_OUTPUT (output_kms);
- const MetaOutputInfo *output_info = meta_output_get_info (output);
-
- if (!output_info->supports_underscanning)
- return;
-
- if (meta_output_is_underscanning (output))
- {
- MetaCrtc *crtc;
- const MetaCrtcConfig *crtc_config;
- const MetaCrtcModeInfo *crtc_mode_info;
- uint64_t hborder, vborder;
-
- crtc = meta_output_get_assigned_crtc (output);
- crtc_config = meta_crtc_get_config (crtc);
- crtc_mode_info = meta_crtc_mode_get_info (crtc_config->mode);
-
- hborder = MIN (128, (uint64_t) round (crtc_mode_info->width * 0.05));
- vborder = MIN (128, (uint64_t) round (crtc_mode_info->height * 0.05));
-
- g_debug ("Setting underscan of connector %s to %" G_GUINT64_FORMAT " x %" G_GUINT64_FORMAT,
- meta_kms_connector_get_name (output_kms->kms_connector),
- hborder, vborder);
-
- meta_kms_update_set_underscanning (kms_update,
- output_kms->kms_connector,
- hborder, vborder);
- }
- else
- {
- g_debug ("Unsetting underscan of connector %s",
- meta_kms_connector_get_name (output_kms->kms_connector));
-
- meta_kms_update_unset_underscanning (kms_update,
- output_kms->kms_connector);
- }
-}
-
-uint32_t
-meta_output_kms_get_connector_id (MetaOutputKms *output_kms)
-{
- return meta_kms_connector_get_id (output_kms->kms_connector);
-}
-
-gboolean
-meta_output_kms_can_clone (MetaOutputKms *output_kms,
- MetaOutputKms *other_output_kms)
-{
- return meta_kms_connector_can_clone (output_kms->kms_connector,
- other_output_kms->kms_connector);
-}
-
-static GBytes *
-meta_output_kms_read_edid (MetaOutputNative *output_native)
-{
- MetaOutputKms *output_kms = META_OUTPUT_KMS (output_native);
- const MetaKmsConnectorState *connector_state;
- GBytes *edid_data;
-
- connector_state =
- meta_kms_connector_get_current_state (output_kms->kms_connector);
- edid_data = connector_state->edid_data;
- if (!edid_data)
- return NULL;
-
- return g_bytes_new_from_bytes (edid_data, 0, g_bytes_get_size (edid_data));
-}
-
-static void
-add_common_modes (MetaOutputInfo *output_info,
- MetaGpuKms *gpu_kms)
-{
- MetaCrtcMode *crtc_mode;
- GPtrArray *array;
- float refresh_rate;
- unsigned i;
- unsigned max_hdisplay = 0;
- unsigned max_vdisplay = 0;
- float max_refresh_rate = 0.0;
- float max_bandwidth = 0.0;
- MetaKmsDevice *kms_device;
- MetaKmsModeFlag flag_filter;
- GList *l;
-
- for (i = 0; i < output_info->n_modes; i++)
- {
- MetaCrtcMode *crtc_mode = output_info->modes[i];
- MetaCrtcModeKms *crtc_mode_kms = META_CRTC_MODE_KMS (crtc_mode);
- MetaKmsMode *kms_mode = meta_crtc_mode_kms_get_kms_mode (crtc_mode_kms);
- const drmModeModeInfo *drm_mode = meta_kms_mode_get_drm_mode (kms_mode);
- float bandwidth;
-
- refresh_rate = meta_calculate_drm_mode_refresh_rate (drm_mode);
- bandwidth = refresh_rate * drm_mode->hdisplay * drm_mode->vdisplay;
- max_hdisplay = MAX (max_hdisplay, drm_mode->hdisplay);
- max_vdisplay = MAX (max_vdisplay, drm_mode->vdisplay);
- max_refresh_rate = MAX (max_refresh_rate, refresh_rate);
- max_bandwidth = MAX (max_bandwidth, bandwidth);
- }
-
- max_refresh_rate = MAX (max_refresh_rate, 60.0);
- max_refresh_rate *= (1 + SYNC_TOLERANCE);
-
- kms_device = meta_gpu_kms_get_kms_device (gpu_kms);
-
- array = g_ptr_array_new ();
-
- if (max_hdisplay > max_vdisplay)
- flag_filter = META_KMS_MODE_FLAG_FALLBACK_LANDSCAPE;
- else
- flag_filter = META_KMS_MODE_FLAG_FALLBACK_PORTRAIT;
-
- for (l = meta_kms_device_get_fallback_modes (kms_device); l; l = l->next)
- {
- MetaKmsMode *fallback_mode = l->data;
- const drmModeModeInfo *drm_mode;
- float bandwidth;
-
- if (!(meta_kms_mode_get_flags (fallback_mode) & flag_filter))
- continue;
-
- drm_mode = meta_kms_mode_get_drm_mode (fallback_mode);
- refresh_rate = meta_calculate_drm_mode_refresh_rate (drm_mode);
- bandwidth = refresh_rate * drm_mode->hdisplay * drm_mode->vdisplay;
- if (drm_mode->hdisplay > max_hdisplay ||
- drm_mode->vdisplay > max_vdisplay ||
- refresh_rate > max_refresh_rate ||
- bandwidth > max_bandwidth)
- continue;
-
- crtc_mode = meta_gpu_kms_get_mode_from_kms_mode (gpu_kms, fallback_mode);
- g_ptr_array_add (array, crtc_mode);
- }
-
- output_info->modes = g_renew (MetaCrtcMode *, output_info->modes,
- output_info->n_modes + array->len);
- memcpy (output_info->modes + output_info->n_modes, array->pdata,
- array->len * sizeof (MetaCrtcMode *));
- output_info->n_modes += array->len;
-
- g_ptr_array_free (array, TRUE);
-}
-
-static int
-compare_modes (const void *one,
- const void *two)
-{
- MetaCrtcMode *crtc_mode_one = *(MetaCrtcMode **) one;
- MetaCrtcMode *crtc_mode_two = *(MetaCrtcMode **) two;
- const MetaCrtcModeInfo *crtc_mode_info_one =
- meta_crtc_mode_get_info (crtc_mode_one);
- const MetaCrtcModeInfo *crtc_mode_info_two =
- meta_crtc_mode_get_info (crtc_mode_two);
-
- if (crtc_mode_info_one->width != crtc_mode_info_two->width)
- return crtc_mode_info_one->width > crtc_mode_info_two->width ? -1 : 1;
- if (crtc_mode_info_one->height != crtc_mode_info_two->height)
- return crtc_mode_info_one->height > crtc_mode_info_two->height ? -1 : 1;
- if (crtc_mode_info_one->refresh_rate != crtc_mode_info_two->refresh_rate)
- return (crtc_mode_info_one->refresh_rate > crtc_mode_info_two->refresh_rate
- ? -1 : 1);
-
- return g_strcmp0 (meta_crtc_mode_get_name (crtc_mode_one),
- meta_crtc_mode_get_name (crtc_mode_two));
-}
-
-static gboolean
-init_output_modes (MetaOutputInfo *output_info,
- MetaGpuKms *gpu_kms,
- MetaKmsConnector *kms_connector,
- GError **error)
-{
- const MetaKmsConnectorState *connector_state;
- GList *l;
- int i;
-
- connector_state = meta_kms_connector_get_current_state (kms_connector);
-
- output_info->preferred_mode = NULL;
-
- output_info->n_modes = g_list_length (connector_state->modes);
- output_info->modes = g_new0 (MetaCrtcMode *, output_info->n_modes);
- for (l = connector_state->modes, i = 0; l; l = l->next, i++)
- {
- MetaKmsMode *kms_mode = l->data;
- const drmModeModeInfo *drm_mode = meta_kms_mode_get_drm_mode (kms_mode);
- MetaCrtcMode *crtc_mode;
-
- crtc_mode = meta_gpu_kms_get_mode_from_kms_mode (gpu_kms, kms_mode);
- output_info->modes[i] = crtc_mode;
- if (drm_mode->type & DRM_MODE_TYPE_PREFERRED)
- output_info->preferred_mode = output_info->modes[i];
- }
-
- if (connector_state->has_scaling)
- {
- meta_topic (META_DEBUG_KMS, "Adding common modes to connector %u on %s",
- meta_kms_connector_get_id (kms_connector),
- meta_gpu_kms_get_file_path (gpu_kms));
- add_common_modes (output_info, gpu_kms);
- }
-
- if (!output_info->modes)
- {
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- "No modes available");
- return FALSE;
- }
-
- qsort (output_info->modes, output_info->n_modes,
- sizeof (MetaCrtcMode *), compare_modes);
-
- if (!output_info->preferred_mode)
- output_info->preferred_mode = output_info->modes[0];
-
- return TRUE;
-}
-
-static MetaConnectorType
-meta_kms_connector_type_from_drm (uint32_t drm_connector_type)
-{
- g_warn_if_fail (drm_connector_type < META_CONNECTOR_TYPE_META);
-
- return (MetaConnectorType) drm_connector_type;
-}
-
-MetaOutputKms *
-meta_output_kms_new (MetaGpuKms *gpu_kms,
- MetaKmsConnector *kms_connector,
- MetaOutput *old_output,
- GError **error)
-{
- MetaGpu *gpu = META_GPU (gpu_kms);
- uint32_t connector_id;
- uint32_t gpu_id;
- g_autoptr (MetaOutputInfo) output_info = NULL;
- MetaOutput *output;
- MetaOutputKms *output_kms;
- uint32_t drm_connector_type;
- const MetaKmsConnectorState *connector_state;
- GArray *crtcs;
- GList *l;
-
- gpu_id = meta_gpu_kms_get_id (gpu_kms);
- connector_id = meta_kms_connector_get_id (kms_connector);
-
- output_info = meta_output_info_new ();
- output_info->name = g_strdup (meta_kms_connector_get_name (kms_connector));
-
- connector_state = meta_kms_connector_get_current_state (kms_connector);
-
- output_info->panel_orientation_transform =
- connector_state->panel_orientation_transform;
- if (meta_monitor_transform_is_rotated (output_info->panel_orientation_transform))
- {
- output_info->width_mm = connector_state->height_mm;
- output_info->height_mm = connector_state->width_mm;
- }
- else
- {
- output_info->width_mm = connector_state->width_mm;
- output_info->height_mm = connector_state->height_mm;
- }
-
- if (!init_output_modes (output_info, gpu_kms, kms_connector, error))
- return NULL;
-
- crtcs = g_array_new (FALSE, FALSE, sizeof (MetaCrtc *));
-
- for (l = meta_gpu_get_crtcs (gpu); l; l = l->next)
- {
- MetaCrtcKms *crtc_kms = META_CRTC_KMS (l->data);
- MetaKmsCrtc *kms_crtc = meta_crtc_kms_get_kms_crtc (crtc_kms);
- uint32_t crtc_idx;
-
- crtc_idx = meta_kms_crtc_get_idx (kms_crtc);
- if (connector_state->common_possible_crtcs & (1 << crtc_idx))
- g_array_append_val (crtcs, crtc_kms);
- }
-
- output_info->n_possible_crtcs = crtcs->len;
- output_info->possible_crtcs = (MetaCrtc **) g_array_free (crtcs, FALSE);
-
- output_info->suggested_x = connector_state->suggested_x;
- output_info->suggested_y = connector_state->suggested_y;
- output_info->hotplug_mode_update = connector_state->hotplug_mode_update;
- output_info->supports_underscanning =
- meta_kms_connector_is_underscanning_supported (kms_connector);
-
- meta_output_info_parse_edid (output_info, connector_state->edid_data);
-
- drm_connector_type = meta_kms_connector_get_connector_type (kms_connector);
- output_info->connector_type =
- meta_kms_connector_type_from_drm (drm_connector_type);
-
- output_info->tile_info = connector_state->tile_info;
-
- output = g_object_new (META_TYPE_OUTPUT_KMS,
- "id", ((uint64_t) gpu_id << 32) | connector_id,
- "gpu", gpu,
- "info", output_info,
- NULL);
- output_kms = META_OUTPUT_KMS (output);
- output_kms->kms_connector = kms_connector;
-
- if (connector_state->current_crtc_id)
- {
- for (l = meta_gpu_get_crtcs (gpu); l; l = l->next)
- {
- MetaCrtc *crtc = l->data;
-
- if (meta_crtc_get_id (crtc) == connector_state->current_crtc_id)
- {
- MetaOutputAssignment output_assignment;
-
- if (old_output)
- {
- output_assignment = (MetaOutputAssignment) {
- .is_primary = meta_output_is_primary (old_output),
- .is_presentation = meta_output_is_presentation (old_output),
- };
- }
- else
- {
- output_assignment = (MetaOutputAssignment) {
- .is_primary = FALSE,
- .is_presentation = FALSE,
- };
- }
- meta_output_assign_crtc (output, crtc, &output_assignment);
- break;
- }
- }
- }
- else
- {
- meta_output_unassign_crtc (output);
- }
-
- return output_kms;
-}
-
-static void
-meta_output_kms_init (MetaOutputKms *output_kms)
-{
-}
-
-static void
-meta_output_kms_class_init (MetaOutputKmsClass *klass)
-{
- MetaOutputNativeClass *output_native_class = META_OUTPUT_NATIVE_CLASS (klass);
-
- output_native_class->read_edid = meta_output_kms_read_edid;
-}
diff --git a/src/backends/native/meta-output-kms.h b/src/backends/native/meta-output-kms.h
deleted file mode 100644
index 52acc6032..000000000
--- a/src/backends/native/meta-output-kms.h
+++ /dev/null
@@ -1,55 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2017 Red Hat
- * Copyright (C) 2018 DisplayLink (UK) Ltd.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-
-#ifndef META_OUTPUT_KMS_H
-#define META_OUTPUT_KMS_H
-
-#include "backends/meta-output.h"
-#include "backends/native/meta-gpu-kms.h"
-#include "backends/native/meta-kms-types.h"
-#include "backends/native/meta-output-native.h"
-
-#define META_TYPE_OUTPUT_KMS (meta_output_kms_get_type ())
-G_DECLARE_FINAL_TYPE (MetaOutputKms, meta_output_kms,
- META, OUTPUT_KMS,
- MetaOutputNative)
-
-void meta_output_kms_set_power_save_mode (MetaOutputKms *output_kms,
- uint64_t dpms_state,
- MetaKmsUpdate *kms_update);
-
-void meta_output_kms_set_underscan (MetaOutputKms *output_kms,
- MetaKmsUpdate *kms_update);
-
-gboolean meta_output_kms_can_clone (MetaOutputKms *output_kms,
- MetaOutputKms *other_output_kms);
-
-MetaKmsConnector * meta_output_kms_get_kms_connector (MetaOutputKms *output_kms);
-
-uint32_t meta_output_kms_get_connector_id (MetaOutputKms *output_kms);
-
-MetaOutputKms * meta_output_kms_new (MetaGpuKms *gpu_kms,
- MetaKmsConnector *kms_connector,
- MetaOutput *old_output,
- GError **error);
-
-#endif /* META_OUTPUT_KMS_H */
diff --git a/src/backends/native/meta-output-native.c b/src/backends/native/meta-output-native.c
deleted file mode 100644
index f21b2ebc6..000000000
--- a/src/backends/native/meta-output-native.c
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright (C) 2020 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-
-#include "config.h"
-
-#include "backends/native/meta-output-native.h"
-
-G_DEFINE_ABSTRACT_TYPE (MetaOutputNative, meta_output_native,
- META_TYPE_OUTPUT)
-
-GBytes *
-meta_output_native_read_edid (MetaOutputNative *output_native)
-{
- MetaOutputNativeClass *klass = META_OUTPUT_NATIVE_GET_CLASS (output_native);
-
- return klass->read_edid (output_native);
-}
-
-static void
-meta_output_native_init (MetaOutputNative *output_native)
-{
-}
-
-static void
-meta_output_native_class_init (MetaOutputNativeClass *klass)
-{
-}
diff --git a/src/backends/native/meta-output-native.h b/src/backends/native/meta-output-native.h
deleted file mode 100644
index f0475ae3b..000000000
--- a/src/backends/native/meta-output-native.h
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Copyright (C) 2020 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-
-#ifndef META_OUTPUT_NATIVE_H
-#define META_OUTPUT_NATIVE_H
-
-#include "backends/meta-output.h"
-
-#define META_TYPE_OUTPUT_NATIVE (meta_output_native_get_type ())
-G_DECLARE_DERIVABLE_TYPE (MetaOutputNative, meta_output_native,
- META, OUTPUT_NATIVE,
- MetaOutput)
-
-struct _MetaOutputNativeClass
-{
- MetaOutputClass parent_class;
-
- GBytes * (* read_edid) (MetaOutputNative *output_native);
-};
-
-GBytes * meta_output_native_read_edid (MetaOutputNative *output_native);
-
-#endif /* META_OUTPUT_NATIVE_H */
diff --git a/src/backends/native/meta-output-virtual.c b/src/backends/native/meta-output-virtual.c
deleted file mode 100644
index 12efb3338..000000000
--- a/src/backends/native/meta-output-virtual.c
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * Copyright (C) 2021 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-
-#include "config.h"
-
-#include "backends/native/meta-output-virtual.h"
-
-#include "backends/native/meta-crtc-mode-virtual.h"
-#include "backends/native/meta-crtc-virtual.h"
-#include "backends/meta-virtual-monitor.h"
-
-struct _MetaOutputVirtual
-{
- MetaOutputNative parent;
-};
-
-#define META_OUTPUT_VIRTUAL_ID_BIT (((uint64_t) 1) << 63)
-
-G_DEFINE_TYPE (MetaOutputVirtual, meta_output_virtual, META_TYPE_OUTPUT_NATIVE)
-
-MetaOutputVirtual *
-meta_output_virtual_new (uint64_t id,
- const MetaVirtualMonitorInfo *info,
- MetaCrtcVirtual *crtc_virtual,
- MetaCrtcModeVirtual *crtc_mode_virtual)
-{
- g_autoptr (MetaOutputInfo) output_info = NULL;
-
- output_info = meta_output_info_new ();
- output_info->name = g_strdup_printf ("Meta-%" G_GUINT64_FORMAT, id);
-
- output_info->n_possible_crtcs = 1;
- output_info->possible_crtcs = g_new0 (MetaCrtc *, 1);
- output_info->possible_crtcs[0] = META_CRTC (crtc_virtual);
-
- output_info->hotplug_mode_update = FALSE;
- output_info->suggested_x = -1;
- output_info->suggested_y = -1;
-
- output_info->connector_type = META_CONNECTOR_TYPE_META;
- output_info->vendor = g_strdup (info->vendor);
- output_info->product = g_strdup (info->product);
- output_info->serial = g_strdup (info->serial);
-
- output_info->n_modes = 1;
- output_info->modes = g_new0 (MetaCrtcMode *, 1);
- output_info->modes[0] = META_CRTC_MODE (crtc_mode_virtual);
- output_info->preferred_mode = output_info->modes[0];
-
- return g_object_new (META_TYPE_OUTPUT_VIRTUAL,
- "id", META_OUTPUT_VIRTUAL_ID_BIT | id,
- "info", output_info,
- NULL);
-}
-
-static void
-meta_output_virtual_init (MetaOutputVirtual *output_virtual)
-{
-}
-
-static void
-meta_output_virtual_class_init (MetaOutputVirtualClass *klass)
-{
-}
diff --git a/src/backends/native/meta-output-virtual.h b/src/backends/native/meta-output-virtual.h
deleted file mode 100644
index b04579f0d..000000000
--- a/src/backends/native/meta-output-virtual.h
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright (C) 2021 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-
-#ifndef META_OUTPUT_VIRTUAL_H
-#define META_OUTPUT_VIRTUAL_H
-
-#include "backends/native/meta-backend-native-types.h"
-#include "backends/native/meta-output-native.h"
-
-#define META_TYPE_OUTPUT_VIRTUAL (meta_output_virtual_get_type ())
-G_DECLARE_FINAL_TYPE (MetaOutputVirtual, meta_output_virtual,
- META, OUTPUT_VIRTUAL,
- MetaOutputNative)
-
-MetaOutputVirtual * meta_output_virtual_new (uint64_t id,
- const MetaVirtualMonitorInfo *info,
- MetaCrtcVirtual *crtc_virtual,
- MetaCrtcModeVirtual *crtc_mode_virtual);
-
-#endif /* META_OUTPUT_VIRTUAL_H */
diff --git a/src/backends/native/meta-pointer-constraint-native.c b/src/backends/native/meta-pointer-constraint-native.c
deleted file mode 100644
index 6a1c066ad..000000000
--- a/src/backends/native/meta-pointer-constraint-native.c
+++ /dev/null
@@ -1,694 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2015-2020 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Written by:
- * Jonas Ådahl <jadahl@gmail.com>
- */
-
-#include "config.h"
-
-#include <glib-object.h>
-#include <wayland-server.h>
-
-#include "core/meta-border.h"
-#include "meta-pointer-constraint-native.h"
-
-struct _MetaPointerConstraintImplNative
-{
- MetaPointerConstraintImpl parent;
- MetaPointerConstraint *constraint;
- cairo_region_t *region;
-};
-
-G_DEFINE_TYPE (MetaPointerConstraintImplNative,
- meta_pointer_constraint_impl_native,
- META_TYPE_POINTER_CONSTRAINT_IMPL);
-
-typedef struct _MetaBox
-{
- int x1;
- int y1;
- int x2;
- int y2;
-} MetaBox;
-
-static MetaBorder *
-add_border (GArray *borders,
- float x1,
- float y1,
- float x2,
- float y2,
- MetaBorderMotionDirection blocking_directions)
-{
- MetaBorder border;
-
- border = (MetaBorder) {
- .line = (MetaLine2) {
- .a = (MetaVector2) {
- .x = x1,
- .y = y1,
- },
- .b = (MetaVector2) {
- .x = x2,
- .y = y2,
- },
- },
- .blocking_directions = blocking_directions,
- };
-
- g_array_append_val (borders, border);
-
- return &g_array_index (borders, MetaBorder, borders->len - 1);
-}
-
-static gint
-compare_lines_x (gconstpointer a,
- gconstpointer b)
-{
- const MetaBorder *border_a = a;
- const MetaBorder *border_b = b;
-
- if (border_a->line.a.x == border_b->line.a.x)
- return border_a->line.b.x < border_b->line.b.x;
- else
- return border_a->line.a.x > border_b->line.a.x;
-}
-
-static void
-add_non_overlapping_edges (MetaBox *boxes,
- unsigned int band_above_start,
- unsigned int band_below_start,
- unsigned int band_below_end,
- GArray *borders)
-{
- unsigned int i;
- GArray *band_merge;
- MetaBorder *border;
- MetaBorder *prev_border;
- MetaBorder *new_border;
-
- band_merge = g_array_new (FALSE, FALSE, sizeof *border);
-
- /* Add bottom band of previous row, and top band of current row, and
- * sort them so lower left x coordinate comes first. If there are two
- * borders with the same left x coordinate, the wider one comes first.
- */
- for (i = band_above_start; i < band_below_start; i++)
- {
- MetaBox *box = &boxes[i];
- add_border (band_merge, box->x1, box->y2, box->x2, box->y2,
- META_BORDER_MOTION_DIRECTION_POSITIVE_Y);
- }
- for (i = band_below_start; i < band_below_end; i++)
- {
- MetaBox *box= &boxes[i];
- add_border (band_merge, box->x1, box->y1, box->x2, box->y1,
- META_BORDER_MOTION_DIRECTION_NEGATIVE_Y);
- }
- g_array_sort (band_merge, compare_lines_x);
-
- /* Combine the two combined bands so that any overlapping border is
- * eliminated. */
- prev_border = NULL;
- for (i = 0; i < band_merge->len; i++)
- {
- border = &g_array_index (band_merge, MetaBorder, i);
-
- g_assert (border->line.a.y == border->line.b.y);
- g_assert (!prev_border ||
- prev_border->line.a.y == border->line.a.y);
- g_assert (!prev_border ||
- (prev_border->line.a.x != border->line.a.x ||
- prev_border->line.b.x != border->line.b.x));
- g_assert (!prev_border ||
- prev_border->line.a.x <= border->line.a.x);
-
- if (prev_border &&
- prev_border->line.a.x == border->line.a.x)
- {
- /*
- * ------------ +
- * ------- =
- * [ ]-----
- */
- prev_border->line.a.x = border->line.b.x;
- }
- else if (prev_border &&
- prev_border->line.b.x == border->line.b.x)
- {
- /*
- * ------------ +
- * ------ =
- * ------[ ]
- */
- prev_border->line.b.x = border->line.a.x;
- }
- else if (prev_border &&
- prev_border->line.b.x == border->line.a.x)
- {
- /*
- * -------- +
- * ------ =
- * --------------
- */
- prev_border->line.b.x = border->line.b.x;
- }
- else if (prev_border &&
- prev_border->line.b.x >= border->line.a.x)
- {
- /*
- * --------------- +
- * ------ =
- * -----[ ]----
- */
- new_border = add_border (borders,
- border->line.b.x,
- border->line.b.y,
- prev_border->line.b.x,
- prev_border->line.b.y,
- prev_border->blocking_directions);
- prev_border->line.b.x = border->line.a.x;
- prev_border = new_border;
- }
- else
- {
- g_assert (!prev_border ||
- prev_border->line.b.x < border->line.a.x);
- /*
- * First border or non-overlapping.
- *
- * ----- +
- * ----- =
- * ----- -----
- */
- g_array_append_val (borders, *border);
- prev_border = &g_array_index (borders, MetaBorder, borders->len - 1);
- }
- }
-
- g_array_free (band_merge, FALSE);
-}
-
-static void
-add_band_bottom_edges (MetaBox *boxes,
- int band_start,
- int band_end,
- GArray *borders)
-{
- int i;
-
- for (i = band_start; i < band_end; i++)
- {
- add_border (borders,
- boxes[i].x1, boxes[i].y2,
- boxes[i].x2, boxes[i].y2,
- META_BORDER_MOTION_DIRECTION_POSITIVE_Y);
- }
-}
-
-static void
-region_to_outline (cairo_region_t *region,
- GArray *borders)
-{
- MetaBox *boxes;
- int num_boxes;
- int i;
- int top_most, bottom_most;
- int current_roof;
- int prev_top;
- int band_start, prev_band_start;
-
- /*
- * Remove any overlapping lines from the set of rectangles. Note that
- * pixman regions are grouped as rows of rectangles, where rectangles
- * in one row never touch or overlap and are all of the same height.
- *
- * -------- --- -------- ---
- * | | | | | | | |
- * ----------====---- --- ----------- ----- ---
- * | | => | |
- * ----==========--------- ----- ----------
- * | | | |
- * ------------------- -------------------
- *
- */
-
- num_boxes = cairo_region_num_rectangles (region);
- boxes = g_new (MetaBox, num_boxes);
- for (i = 0; i < num_boxes; i++)
- {
- cairo_rectangle_int_t rect;
- cairo_region_get_rectangle (region, i, &rect);
- boxes[i] = (MetaBox) {
- .x1 = rect.x,
- .y1 = rect.y,
- .x2 = rect.x + rect.width,
- .y2 = rect.y + rect.height,
- };
- }
- prev_top = 0;
- top_most = boxes[0].y1;
- current_roof = top_most;
- bottom_most = boxes[num_boxes - 1].y2;
- band_start = 0;
- prev_band_start = 0;
- for (i = 0; i < num_boxes; i++)
- {
- /* Detect if there is a vertical empty space, and add the lower
- * level of the previous band if so was the case. */
- if (i > 0 &&
- boxes[i].y1 != prev_top &&
- boxes[i].y1 != boxes[i - 1].y2)
- {
- current_roof = boxes[i].y1;
- add_band_bottom_edges (boxes,
- band_start,
- i,
- borders);
- }
-
- /* Special case adding the last band, since it won't be handled
- * by the band change detection below. */
- if (boxes[i].y1 != current_roof && i == num_boxes - 1)
- {
- if (boxes[i].y1 != prev_top)
- {
- /* The last band is a single box, so we don't
- * have a prev_band_start to tell us when the
- * previous band started. */
- add_non_overlapping_edges (boxes,
- band_start,
- i,
- i + 1,
- borders);
- }
- else
- {
- add_non_overlapping_edges (boxes,
- prev_band_start,
- band_start,
- i + 1,
- borders);
- }
- }
-
- /* Detect when passing a band and combine the top border of the
- * just passed band with the bottom band of the previous band.
- */
- if (boxes[i].y1 != top_most && boxes[i].y1 != prev_top)
- {
- /* Combine the two passed bands. */
- if (prev_top != current_roof)
- {
- add_non_overlapping_edges (boxes,
- prev_band_start,
- band_start,
- i,
- borders);
- }
-
- prev_band_start = band_start;
- band_start = i;
- }
-
- /* Add the top border if the box is part of the current roof. */
- if (boxes[i].y1 == current_roof)
- {
- add_border (borders,
- boxes[i].x1, boxes[i].y1,
- boxes[i].x2, boxes[i].y1,
- META_BORDER_MOTION_DIRECTION_NEGATIVE_Y);
- }
-
- /* Add the bottom border of the last band. */
- if (boxes[i].y2 == bottom_most)
- {
- add_border (borders,
- boxes[i].x1, boxes[i].y2,
- boxes[i].x2, boxes[i].y2,
- META_BORDER_MOTION_DIRECTION_POSITIVE_Y);
- }
-
- /* Always add the left border. */
- add_border (borders,
- boxes[i].x1, boxes[i].y1,
- boxes[i].x1, boxes[i].y2,
- META_BORDER_MOTION_DIRECTION_NEGATIVE_X);
-
- /* Always add the right border. */
- add_border (borders,
- boxes[i].x2, boxes[i].y1,
- boxes[i].x2, boxes[i].y2,
- META_BORDER_MOTION_DIRECTION_POSITIVE_X);
-
- prev_top = boxes[i].y1;
- }
-
- g_free (boxes);
-}
-
-static MetaBorder *
-get_closest_border (GArray *borders,
- MetaLine2 *motion,
- uint32_t directions)
-{
- MetaBorder *border;
- MetaVector2 intersection;
- MetaVector2 delta;
- float distance_2;
- MetaBorder *closest_border = NULL;
- float closest_distance_2 = DBL_MAX;
- unsigned int i;
-
- for (i = 0; i < borders->len; i++)
- {
- border = &g_array_index (borders, MetaBorder, i);
-
- if (!meta_border_is_blocking_directions (border, directions))
- continue;
-
- if (!meta_line2_intersects_with (&border->line, motion, &intersection))
- continue;
-
- delta = meta_vector2_subtract (intersection, motion->a);
- distance_2 = delta.x*delta.x + delta.y*delta.y;
- if (distance_2 < closest_distance_2)
- {
- closest_border = border;
- closest_distance_2 = distance_2;
- }
- }
-
- return closest_border;
-}
-
-static void
-clamp_to_border (MetaBorder *border,
- MetaLine2 *motion,
- uint32_t *motion_dir)
-{
- /*
- * When clamping either rightward or downward motions, the motion needs to be
- * clamped so that the destination coordinate does not end up on the border
- * (see weston_pointer_clamp_event_to_region). Do this by clamping such
- * motions to the border minus the smallest possible wl_fixed_t value.
- *
- * When clamping in either leftward or upward motion, the resulting coordinate
- * needs to be clamped so that it is enough on the inside to avoid the
- * inaccuracies of clutter's stage to actor transformation algorithm (the one
- * used in clutter_actor_transform_stage_point) to make it end up outside the
- * next motion. It also needs to be clamped so that to the wl_fixed_t
- * coordinate may still be right on the border (i.e. at .0). Testing shows
- * that the smallest wl_fixed_t value divided by 10 is small enough to make
- * the wl_fixed_t coordinate .0 and large enough to avoid the inaccuracies of
- * clutters transform algorithm.
- */
- if (meta_border_is_horizontal (border))
- {
- if (*motion_dir & META_BORDER_MOTION_DIRECTION_POSITIVE_Y)
- motion->b.y = border->line.a.y - wl_fixed_to_double (1);
- else
- motion->b.y = border->line.a.y + wl_fixed_to_double (1) / 10;
- *motion_dir &= ~(META_BORDER_MOTION_DIRECTION_POSITIVE_Y |
- META_BORDER_MOTION_DIRECTION_NEGATIVE_Y);
- }
- else
- {
- if (*motion_dir & META_BORDER_MOTION_DIRECTION_POSITIVE_X)
- motion->b.x = border->line.a.x - wl_fixed_to_double (1);
- else
- motion->b.x = border->line.a.x + wl_fixed_to_double (1) / 10;
- *motion_dir &= ~(META_BORDER_MOTION_DIRECTION_POSITIVE_X |
- META_BORDER_MOTION_DIRECTION_NEGATIVE_X);
- }
-}
-
-static uint32_t
-get_motion_directions (MetaLine2 *motion)
-{
- uint32_t directions = 0;
-
- if (motion->a.x < motion->b.x)
- directions |= META_BORDER_MOTION_DIRECTION_POSITIVE_X;
- else if (motion->a.x > motion->b.x)
- directions |= META_BORDER_MOTION_DIRECTION_NEGATIVE_X;
- if (motion->a.y < motion->b.y)
- directions |= META_BORDER_MOTION_DIRECTION_POSITIVE_Y;
- else if (motion->a.y > motion->b.y)
- directions |= META_BORDER_MOTION_DIRECTION_NEGATIVE_Y;
-
- return directions;
-}
-
-static void
-meta_pointer_constraint_impl_native_constraint (MetaPointerConstraintImpl *constraint_impl,
- ClutterInputDevice *device,
- uint32_t time,
- float prev_x,
- float prev_y,
- float *x_inout,
- float *y_inout)
-{
- MetaPointerConstraintImplNative *constraint_impl_native;
- cairo_region_t *region;
- float x, y;
- GArray *borders;
- MetaLine2 motion;
- MetaBorder *closest_border;
- uint32_t directions;
-
- constraint_impl_native = META_POINTER_CONSTRAINT_IMPL_NATIVE (constraint_impl);
-
- region = cairo_region_reference (constraint_impl_native->region);
- x = *x_inout;
- y = *y_inout;
-
- /* For motions in a positive direction on any axis, append the smallest
- * possible value representable in a Wayland absolute coordinate. This is
- * in order to avoid not clamping motion that as a floating point number
- * won't be clamped, but will be rounded up to be outside of the range
- * of wl_fixed_t. */
- if (x > prev_x)
- x += (float) wl_fixed_to_double(1);
- if (y > prev_y)
- y += (float) wl_fixed_to_double(1);
-
- borders = g_array_new (FALSE, FALSE, sizeof (MetaBorder));
-
- /*
- * Generate borders given the confine region we are to use. The borders
- * are defined to be the outer region of the allowed area. This means
- * top/left borders are "within" the allowed area, while bottom/right
- * borders are outside. This needs to be considered when clamping
- * confined motion vectors.
- */
- region_to_outline (region, borders);
- cairo_region_destroy (region);
-
- motion = (MetaLine2) {
- .a = (MetaVector2) {
- .x = prev_x,
- .y = prev_y,
- },
- .b = (MetaVector2) {
- .x = x,
- .y = y,
- },
- };
- directions = get_motion_directions (&motion);
-
- while (directions)
- {
- closest_border = get_closest_border (borders,
- &motion,
- directions);
- if (closest_border)
- clamp_to_border (closest_border, &motion, &directions);
- else
- break;
- }
-
- *x_inout = motion.b.x;
- *y_inout = motion.b.y;
- g_array_free (borders, FALSE);
-}
-
-static float
-point_to_border_distance_2 (MetaBorder *border,
- float x,
- float y)
-{
- float orig_x, orig_y;
- float dx, dy;
-
- if (meta_border_is_horizontal (border))
- {
- if (x < border->line.a.x)
- orig_x = border->line.a.x;
- else if (x > border->line.b.x)
- orig_x = border->line.b.x;
- else
- orig_x = x;
- orig_y = border->line.a.y;
- }
- else
- {
- if (y < border->line.a.y)
- orig_y = border->line.a.y;
- else if (y > border->line.b.y)
- orig_y = border->line.b.y;
- else
- orig_y = y;
- orig_x = border->line.a.x;
- }
-
- dx = fabsf (orig_x - x);
- dy = fabsf (orig_y - y);
- return dx*dx + dy*dy;
-}
-
-static void
-closest_point_behind_border (MetaBorder *border,
- float *sx,
- float *sy)
-{
- switch (border->blocking_directions)
- {
- case META_BORDER_MOTION_DIRECTION_POSITIVE_X:
- case META_BORDER_MOTION_DIRECTION_NEGATIVE_X:
- if (border->blocking_directions == META_BORDER_MOTION_DIRECTION_POSITIVE_X)
- *sx = border->line.a.x - wl_fixed_to_double (1);
- else
- *sx = border->line.a.x + wl_fixed_to_double (1);
- if (*sy < border->line.a.y)
- *sy = border->line.a.y + wl_fixed_to_double (1);
- else if (*sy > border->line.b.y)
- *sy = border->line.b.y - wl_fixed_to_double (1);
- break;
- case META_BORDER_MOTION_DIRECTION_POSITIVE_Y:
- case META_BORDER_MOTION_DIRECTION_NEGATIVE_Y:
- if (border->blocking_directions == META_BORDER_MOTION_DIRECTION_POSITIVE_Y)
- *sy = border->line.a.y - wl_fixed_to_double (1);
- else
- *sy = border->line.a.y + wl_fixed_to_double (1);
- if (*sx < border->line.a.x)
- *sx = border->line.a.x + wl_fixed_to_double (1);
- else if (*sx > (border->line.b.x))
- *sx = border->line.b.x - wl_fixed_to_double (1);
- break;
- }
-}
-
-static void
-meta_pointer_constraint_impl_native_ensure_constrained (MetaPointerConstraintImpl *constraint_impl,
- ClutterInputDevice *device)
-{
- MetaPointerConstraintImplNative *constraint_impl_native;
- graphene_point_t point;
- cairo_region_t *region;
- float x;
- float y;
-
- constraint_impl_native = META_POINTER_CONSTRAINT_IMPL_NATIVE (constraint_impl);
- region = cairo_region_reference (constraint_impl_native->region);
-
- clutter_seat_query_state (clutter_input_device_get_seat (device),
- device, NULL, &point, NULL);
- x = point.x;
- y = point.y;
-
- if (!cairo_region_contains_point (region, (int) x, (int) y))
- {
- GArray *borders;
- float closest_distance_2 = FLT_MAX;
- MetaBorder *closest_border = NULL;
- ClutterSeat *seat;
- unsigned int i;
-
- borders = g_array_new (FALSE, FALSE, sizeof (MetaBorder));
-
- region_to_outline (region, borders);
-
- for (i = 0; i < borders->len; i++)
- {
- MetaBorder *border = &g_array_index (borders, MetaBorder, i);
- float distance_2;
-
- distance_2 = point_to_border_distance_2 (border, x, y);
- if (distance_2 < closest_distance_2)
- {
- closest_border = border;
- closest_distance_2 = distance_2;
- }
- }
-
- closest_point_behind_border (closest_border, &x, &y);
-
- seat = clutter_backend_get_default_seat (clutter_get_default_backend ());
- clutter_seat_warp_pointer (seat, x, y);
- }
-
- cairo_region_destroy (region);
-}
-
-static void
-meta_pointer_constraint_impl_native_finalize (GObject *object)
-{
- MetaPointerConstraintImplNative *constraint_impl_native;
-
- constraint_impl_native = META_POINTER_CONSTRAINT_IMPL_NATIVE (object);
- g_clear_pointer (&constraint_impl_native->region, cairo_region_destroy);
-
- G_OBJECT_CLASS (meta_pointer_constraint_impl_native_parent_class)->finalize (object);
-}
-
-static void
-meta_pointer_constraint_impl_native_init (MetaPointerConstraintImplNative *constraint_impl_native)
-{
-}
-
-static void
-meta_pointer_constraint_impl_native_class_init (MetaPointerConstraintImplNativeClass *klass)
-{
- MetaPointerConstraintImplClass *constraint_impl_class;
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- object_class->finalize = meta_pointer_constraint_impl_native_finalize;
-
- constraint_impl_class = META_POINTER_CONSTRAINT_IMPL_CLASS (klass);
- constraint_impl_class->constrain = meta_pointer_constraint_impl_native_constraint;
- constraint_impl_class->ensure_constrained =
- meta_pointer_constraint_impl_native_ensure_constrained;
-}
-
-
-MetaPointerConstraintImpl *
-meta_pointer_constraint_impl_native_new (MetaPointerConstraint *constraint,
- const cairo_region_t *region)
-{
- MetaPointerConstraintImplNative *constraint_impl;
-
- constraint_impl = g_object_new (META_TYPE_POINTER_CONSTRAINT_IMPL_NATIVE,
- NULL);
- constraint_impl->constraint = constraint;
- constraint_impl->region = cairo_region_copy (region);
-
- return META_POINTER_CONSTRAINT_IMPL (constraint_impl);
-}
diff --git a/src/backends/native/meta-pointer-constraint-native.h b/src/backends/native/meta-pointer-constraint-native.h
deleted file mode 100644
index 83a2e575d..000000000
--- a/src/backends/native/meta-pointer-constraint-native.h
+++ /dev/null
@@ -1,46 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2020 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Written by:
- * Carlos Garnacho <carlosg@gnome.org>
- */
-
-#ifndef META_POINTER_CONSTRAINT_NATIVE_H
-#define META_POINTER_CONSTRAINT_NATIVE_H
-
-#include <glib-object.h>
-
-#include "clutter/clutter.h"
-#include "backends/meta-pointer-constraint.h"
-
-G_BEGIN_DECLS
-
-#define META_TYPE_POINTER_CONSTRAINT_IMPL_NATIVE (meta_pointer_constraint_impl_native_get_type ())
-G_DECLARE_FINAL_TYPE (MetaPointerConstraintImplNative,
- meta_pointer_constraint_impl_native,
- META, POINTER_CONSTRAINT_IMPL_NATIVE,
- MetaPointerConstraintImpl)
-
-MetaPointerConstraintImpl * meta_pointer_constraint_impl_native_new (MetaPointerConstraint *constraint_impl,
- const cairo_region_t *region);
-
-G_END_DECLS
-
-#endif /* META_POINTER_CONSTRAINT_NATIVE_H */
diff --git a/src/backends/native/meta-renderer-native-gles3.c b/src/backends/native/meta-renderer-native-gles3.c
deleted file mode 100644
index c0eb77554..000000000
--- a/src/backends/native/meta-renderer-native-gles3.c
+++ /dev/null
@@ -1,160 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2017 Red Hat
- * Copyright (c) 2018 DisplayLink (UK) Ltd.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- */
-
-#include "config.h"
-
-#define GL_GLEXT_PROTOTYPES
-
-#include "backends/native/meta-renderer-native-gles3.h"
-
-#include <GLES3/gl3.h>
-#include <drm_fourcc.h>
-#include <errno.h>
-#include <gio/gio.h>
-#include <string.h>
-
-#include "backends/meta-egl-ext.h"
-#include "backends/meta-gles3.h"
-#include "backends/meta-gles3-table.h"
-
-/*
- * GL/gl.h being included may conflict with gl3.h on some architectures.
- * Make sure that hasn't happened on any architecture.
- */
-#ifdef GL_VERSION_1_1
-#error "Somehow included OpenGL headers when we shouldn't have"
-#endif
-
-static void
-paint_egl_image (MetaGles3 *gles3,
- EGLImageKHR egl_image,
- int width,
- int height)
-{
- GLuint texture;
- GLuint framebuffer;
-
- meta_gles3_clear_error (gles3);
-
- GLBAS (gles3, glGenFramebuffers, (1, &framebuffer));
- GLBAS (gles3, glBindFramebuffer, (GL_READ_FRAMEBUFFER, framebuffer));
-
- GLBAS (gles3, glActiveTexture, (GL_TEXTURE0));
- GLBAS (gles3, glGenTextures, (1, &texture));
- GLBAS (gles3, glBindTexture, (GL_TEXTURE_2D, texture));
- GLEXT (gles3, glEGLImageTargetTexture2DOES, (GL_TEXTURE_2D, egl_image));
- GLBAS (gles3, glTexParameteri, (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
- GL_NEAREST));
- GLBAS (gles3, glTexParameteri, (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
- GL_NEAREST));
- GLBAS (gles3, glTexParameteri, (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,
- GL_CLAMP_TO_EDGE));
- GLBAS (gles3, glTexParameteri, (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,
- GL_CLAMP_TO_EDGE));
- GLBAS (gles3, glTexParameteri, (GL_TEXTURE_2D, GL_TEXTURE_WRAP_R_OES,
- GL_CLAMP_TO_EDGE));
-
- GLBAS (gles3, glFramebufferTexture2D, (GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
- GL_TEXTURE_2D, texture, 0));
-
- GLBAS (gles3, glBindFramebuffer, (GL_READ_FRAMEBUFFER, framebuffer));
- GLBAS (gles3, glBlitFramebuffer, (0, height, width, 0,
- 0, 0, width, height,
- GL_COLOR_BUFFER_BIT,
- GL_NEAREST));
-
- GLBAS (gles3, glDeleteTextures, (1, &texture));
- GLBAS (gles3, glDeleteFramebuffers, (1, &framebuffer));
-}
-
-gboolean
-meta_renderer_native_gles3_blit_shared_bo (MetaEgl *egl,
- MetaGles3 *gles3,
- EGLDisplay egl_display,
- EGLContext egl_context,
- EGLSurface egl_surface,
- struct gbm_bo *shared_bo,
- GError **error)
-{
- int shared_bo_fd;
- unsigned int width;
- unsigned int height;
- uint32_t i, n_planes;
- uint32_t strides[4] = { 0 };
- uint32_t offsets[4] = { 0 };
- uint64_t modifiers[4] = { 0 };
- int fds[4] = { -1, -1, -1, -1 };
- uint32_t format;
- EGLImageKHR egl_image;
- gboolean use_modifiers;
-
- shared_bo_fd = gbm_bo_get_fd (shared_bo);
- if (shared_bo_fd < 0)
- {
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- "Failed to export gbm_bo: %s", strerror (errno));
- return FALSE;
- }
-
- width = gbm_bo_get_width (shared_bo);
- height = gbm_bo_get_height (shared_bo);
- format = gbm_bo_get_format (shared_bo);
-
- n_planes = gbm_bo_get_plane_count (shared_bo);
- for (i = 0; i < n_planes; i++)
- {
- strides[i] = gbm_bo_get_stride_for_plane (shared_bo, i);
- offsets[i] = gbm_bo_get_offset (shared_bo, i);
- modifiers[i] = gbm_bo_get_modifier (shared_bo);
- fds[i] = shared_bo_fd;
- }
-
- /* Workaround for https://gitlab.gnome.org/GNOME/mutter/issues/18 */
- if (modifiers[0] == DRM_FORMAT_MOD_LINEAR ||
- modifiers[0] == DRM_FORMAT_MOD_INVALID)
- use_modifiers = FALSE;
- else
- use_modifiers = TRUE;
-
- egl_image = meta_egl_create_dmabuf_image (egl,
- egl_display,
- width,
- height,
- format,
- n_planes,
- fds,
- strides,
- offsets,
- use_modifiers ? modifiers : NULL,
- error);
- close (shared_bo_fd);
-
- if (!egl_image)
- return FALSE;
-
- paint_egl_image (gles3, egl_image, width, height);
-
- meta_egl_destroy_image (egl, egl_display, egl_image, NULL);
-
- return TRUE;
-}
diff --git a/src/backends/native/meta-renderer-native-gles3.h b/src/backends/native/meta-renderer-native-gles3.h
deleted file mode 100644
index 4e7324c8d..000000000
--- a/src/backends/native/meta-renderer-native-gles3.h
+++ /dev/null
@@ -1,40 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2017 Red Hat
- * Copyright (c) 2018 DisplayLink (UK) Ltd.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- */
-
-#ifndef META_RENDERER_NATIVE_GLES3_H
-#define META_RENDERER_NATIVE_GLES3_H
-
-#include <gbm.h>
-
-#include "backends/meta-egl.h"
-#include "backends/meta-gles3.h"
-
-gboolean meta_renderer_native_gles3_blit_shared_bo (MetaEgl *egl,
- MetaGles3 *gles3,
- EGLDisplay egl_display,
- EGLContext egl_context,
- EGLSurface egl_surface,
- struct gbm_bo *shared_bo,
- GError **error);
-
-#endif /* META_RENDERER_NATIVE_GLES3_H */
diff --git a/src/backends/native/meta-renderer-native-private.h b/src/backends/native/meta-renderer-native-private.h
deleted file mode 100644
index acadb3fff..000000000
--- a/src/backends/native/meta-renderer-native-private.h
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
- * Copyright (C) 2011 Intel Corporation.
- * Copyright (C) 2016-2020 Red Hat
- * Copyright (c) 2018,2019 DisplayLink (UK) Ltd.
- *
- * Permission is hereby granted, free of charge, to any person
- * obtaining a copy of this software and associated documentation
- * files (the "Software"), to deal in the Software without
- * restriction, including without limitation the rights to use, copy,
- * modify, merge, publish, distribute, sublicense, and/or sell copies
- * of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be
- * included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
- * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
- * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- *
- */
-
-#ifndef META_RENDERER_NATIVE_PRIVATE_H
-#define META_RENDERER_NATIVE_PRIVATE_H
-
-#include "backends/meta-gles3.h"
-#include "backends/native/meta-renderer-native.h"
-
-typedef enum _MetaSharedFramebufferCopyMode
-{
- /* Zero-copy: primary GPU exports, secondary GPU imports as KMS FB */
- META_SHARED_FRAMEBUFFER_COPY_MODE_ZERO,
- /* the secondary GPU will make the copy */
- META_SHARED_FRAMEBUFFER_COPY_MODE_SECONDARY_GPU,
- /*
- * The copy is made in the primary GPU rendering context, either
- * as a CPU copy through Cogl read-pixels or as primary GPU copy
- * using glBlitFramebuffer.
- */
- META_SHARED_FRAMEBUFFER_COPY_MODE_PRIMARY
-} MetaSharedFramebufferCopyMode;
-
-typedef struct _MetaRendererNativeGpuData
-{
- MetaRendererNative *renderer_native;
-
- MetaDeviceFile *device_file;
-
- struct {
- struct gbm_device *device;
- } gbm;
-
-#ifdef HAVE_EGL_DEVICE
- struct {
- EGLDeviceEXT device;
- } egl;
-#endif
-
- MetaRendererNativeMode mode;
-
- EGLDisplay egl_display;
-
- /*
- * Fields used for blitting iGPU framebuffer content onto dGPU framebuffers.
- */
- struct {
- MetaSharedFramebufferCopyMode copy_mode;
- gboolean is_hardware_rendering;
- gboolean has_EGL_EXT_image_dma_buf_import_modifiers;
-
- /* For GPU blit mode */
- EGLContext egl_context;
- EGLConfig egl_config;
- } secondary;
-} MetaRendererNativeGpuData;
-
-MetaEgl * meta_renderer_native_get_egl (MetaRendererNative *renderer_native);
-
-MetaGles3 * meta_renderer_native_get_gles3 (MetaRendererNative *renderer_native);
-
-MetaRendererNativeGpuData * meta_renderer_native_get_gpu_data (MetaRendererNative *renderer_native,
- MetaGpuKms *gpu_kms);
-
-gboolean meta_renderer_native_has_pending_mode_sets (MetaRendererNative *renderer_native);
-
-gboolean meta_renderer_native_has_pending_mode_set (MetaRendererNative *renderer_native);
-
-void meta_renderer_native_notify_mode_sets_reset (MetaRendererNative *renderer_native);
-
-void meta_renderer_native_post_mode_set_updates (MetaRendererNative *renderer_native);
-
-void meta_renderer_native_queue_power_save_page_flip (MetaRendererNative *renderer_native,
- CoglOnscreen *onscreen);
-
-CoglFramebuffer * meta_renderer_native_create_dma_buf_framebuffer (MetaRendererNative *renderer_native,
- int dmabuf_fd,
- uint32_t width,
- uint32_t height,
- uint32_t stride,
- uint32_t offset,
- uint64_t modifier,
- uint32_t drm_format,
- GError **error);
-
-gboolean meta_renderer_native_pop_pending_mode_set (MetaRendererNative *renderer_native,
- MetaRendererView *view);
-
-const CoglWinsysVtable * meta_get_renderer_native_parent_vtable (void);
-
-#endif /* META_RENDERER_NATIVE_PRIVATE_H */
diff --git a/src/backends/native/meta-renderer-native.c b/src/backends/native/meta-renderer-native.c
deleted file mode 100644
index eb6771b80..000000000
--- a/src/backends/native/meta-renderer-native.c
+++ /dev/null
@@ -1,2264 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2011 Intel Corporation.
- * Copyright (C) 2016 Red Hat
- * Copyright (c) 2018,2019 DisplayLink (UK) Ltd.
- *
- * Permission is hereby granted, free of charge, to any person
- * obtaining a copy of this software and associated documentation
- * files (the "Software"), to deal in the Software without
- * restriction, including without limitation the rights to use, copy,
- * modify, merge, publish, distribute, sublicense, and/or sell copies
- * of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be
- * included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
- * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
- * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- *
- * Authors:
- * Rob Bradford <rob@linux.intel.com> (from cogl-winsys-egl-kms.c)
- * Kristian Høgsberg (from eglkms.c)
- * Benjamin Franzke (from eglkms.c)
- * Robert Bragg <robert@linux.intel.com> (from cogl-winsys-egl-kms.c)
- * Neil Roberts <neil@linux.intel.com> (from cogl-winsys-egl-kms.c)
- * Jonas Ådahl <jadahl@redhat.com>
- *
- */
-
-#include "config.h"
-
-#include <drm_fourcc.h>
-#include <errno.h>
-#include <gbm.h>
-#include <gio/gio.h>
-#include <glib-object.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#include "backends/meta-gles3.h"
-#include "backends/meta-logical-monitor.h"
-#include "backends/native/meta-backend-native-private.h"
-#include "backends/native/meta-cogl-utils.h"
-#include "backends/native/meta-crtc-kms.h"
-#include "backends/native/meta-crtc-virtual.h"
-#include "backends/native/meta-device-pool.h"
-#include "backends/native/meta-kms-device.h"
-#include "backends/native/meta-kms.h"
-#include "backends/native/meta-onscreen-native.h"
-#include "backends/native/meta-renderer-native-private.h"
-#include "cogl/cogl.h"
-#include "core/boxes-private.h"
-
-#ifndef EGL_DRM_MASTER_FD_EXT
-#define EGL_DRM_MASTER_FD_EXT 0x333C
-#endif
-
-/* added in libdrm 2.4.95 */
-#ifndef DRM_FORMAT_INVALID
-#define DRM_FORMAT_INVALID 0
-#endif
-
-struct _MetaRendererNative
-{
- MetaRenderer parent;
-
- MetaGpuKms *primary_gpu_kms;
-
- MetaGles3 *gles3;
-
- gboolean use_modifiers;
-
- GHashTable *gpu_datas;
-
- GList *pending_mode_set_views;
- gboolean pending_mode_set;
-
- GList *kept_alive_onscreens;
-
- GList *power_save_page_flip_onscreens;
- guint power_save_page_flip_source_id;
-};
-
-static void
-initable_iface_init (GInitableIface *initable_iface);
-
-G_DEFINE_TYPE_WITH_CODE (MetaRendererNative,
- meta_renderer_native,
- META_TYPE_RENDERER,
- G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE,
- initable_iface_init))
-
-static const CoglWinsysEGLVtable _cogl_winsys_egl_vtable;
-static const CoglWinsysVtable *parent_vtable;
-
-static gboolean
-meta_renderer_native_ensure_gpu_data (MetaRendererNative *renderer_native,
- MetaGpuKms *gpu_kms,
- GError **error);
-
-static void
-meta_renderer_native_queue_modes_reset (MetaRendererNative *renderer_native);
-
-const CoglWinsysVtable *
-meta_get_renderer_native_parent_vtable (void)
-{
- return parent_vtable;
-}
-
-static void
-meta_renderer_native_gpu_data_free (MetaRendererNativeGpuData *renderer_gpu_data)
-{
- MetaRendererNative *renderer_native = renderer_gpu_data->renderer_native;
- MetaEgl *egl = meta_renderer_native_get_egl (renderer_native);
-
- if (renderer_gpu_data->secondary.egl_context != EGL_NO_CONTEXT)
- {
- meta_egl_destroy_context (egl,
- renderer_gpu_data->egl_display,
- renderer_gpu_data->secondary.egl_context,
- NULL);
- }
-
- if (renderer_gpu_data->egl_display != EGL_NO_DISPLAY)
- meta_egl_terminate (egl, renderer_gpu_data->egl_display, NULL);
-
- g_clear_pointer (&renderer_gpu_data->gbm.device, gbm_device_destroy);
- g_clear_pointer (&renderer_gpu_data->device_file, meta_device_file_release);
- g_free (renderer_gpu_data);
-}
-
-MetaRendererNativeGpuData *
-meta_renderer_native_get_gpu_data (MetaRendererNative *renderer_native,
- MetaGpuKms *gpu_kms)
-{
- return g_hash_table_lookup (renderer_native->gpu_datas, gpu_kms);
-}
-
-static MetaRendererNative *
-meta_renderer_native_from_gpu (MetaGpuKms *gpu_kms)
-{
- MetaBackend *backend = meta_gpu_get_backend (META_GPU (gpu_kms));
-
- return META_RENDERER_NATIVE (meta_backend_get_renderer (backend));
-}
-
-struct gbm_device *
-meta_gbm_device_from_gpu (MetaGpuKms *gpu_kms)
-{
- MetaRendererNative *renderer_native = meta_renderer_native_from_gpu (gpu_kms);
- MetaRendererNativeGpuData *renderer_gpu_data;
-
- renderer_gpu_data = meta_renderer_native_get_gpu_data (renderer_native,
- gpu_kms);
-
- return renderer_gpu_data->gbm.device;
-}
-
-MetaGpuKms *
-meta_renderer_native_get_primary_gpu (MetaRendererNative *renderer_native)
-{
- return renderer_native->primary_gpu_kms;
-}
-
-MetaDeviceFile *
-meta_renderer_native_get_primary_device_file (MetaRendererNative *renderer_native)
-{
- MetaGpuKms *gpu_kms = renderer_native->primary_gpu_kms;
- MetaRendererNativeGpuData *renderer_gpu_data;
-
- renderer_gpu_data = meta_renderer_native_get_gpu_data (renderer_native,
- gpu_kms);
- return renderer_gpu_data->device_file;
-}
-
-static MetaRendererNativeGpuData *
-meta_create_renderer_native_gpu_data (void)
-{
- return g_new0 (MetaRendererNativeGpuData, 1);
-}
-
-MetaEgl *
-meta_renderer_native_get_egl (MetaRendererNative *renderer_native)
-{
- MetaRenderer *renderer = META_RENDERER (renderer_native);
-
- return meta_backend_get_egl (meta_renderer_get_backend (renderer));
-}
-
-gboolean
-meta_renderer_native_use_modifiers (MetaRendererNative *renderer_native)
-{
- return renderer_native->use_modifiers;
-}
-
-MetaGles3 *
-meta_renderer_native_get_gles3 (MetaRendererNative *renderer_native)
-{
- return renderer_native->gles3;
-}
-
-gboolean
-meta_renderer_native_has_pending_mode_sets (MetaRendererNative *renderer_native)
-{
- return !!renderer_native->pending_mode_set_views;
-}
-
-gboolean
-meta_renderer_native_has_pending_mode_set (MetaRendererNative *renderer_native)
-{
- return renderer_native->pending_mode_set;
-}
-
-static void
-meta_renderer_native_disconnect (CoglRenderer *cogl_renderer)
-{
- CoglRendererEGL *cogl_renderer_egl = cogl_renderer->winsys;
-
- g_free (cogl_renderer_egl);
-}
-
-static gboolean
-meta_renderer_native_connect (CoglRenderer *cogl_renderer,
- GError **error)
-{
- CoglRendererEGL *cogl_renderer_egl;
- MetaRendererNative *renderer_native = cogl_renderer->custom_winsys_user_data;
- MetaGpuKms *gpu_kms;
- MetaRendererNativeGpuData *renderer_gpu_data;
-
- cogl_renderer->winsys = g_new0 (CoglRendererEGL, 1);
- cogl_renderer_egl = cogl_renderer->winsys;
-
- gpu_kms = meta_renderer_native_get_primary_gpu (renderer_native);
- renderer_gpu_data = meta_renderer_native_get_gpu_data (renderer_native,
- gpu_kms);
-
- cogl_renderer_egl->platform_vtable = &_cogl_winsys_egl_vtable;
- cogl_renderer_egl->platform = renderer_gpu_data;
- cogl_renderer_egl->edpy = renderer_gpu_data->egl_display;
-
- if (!_cogl_winsys_egl_renderer_connect_common (cogl_renderer, error))
- goto fail;
-
- return TRUE;
-
-fail:
- meta_renderer_native_disconnect (cogl_renderer);
-
- return FALSE;
-}
-
-static int
-meta_renderer_native_add_egl_config_attributes (CoglDisplay *cogl_display,
- const CoglFramebufferConfig *config,
- EGLint *attributes)
-{
- CoglRendererEGL *cogl_renderer_egl = cogl_display->renderer->winsys;
- MetaRendererNativeGpuData *renderer_gpu_data = cogl_renderer_egl->platform;
- int i = 0;
-
- switch (renderer_gpu_data->mode)
- {
- case META_RENDERER_NATIVE_MODE_GBM:
- attributes[i++] = EGL_SURFACE_TYPE;
- attributes[i++] = EGL_WINDOW_BIT;
- break;
- case META_RENDERER_NATIVE_MODE_SURFACELESS:
- attributes[i++] = EGL_SURFACE_TYPE;
- attributes[i++] = EGL_PBUFFER_BIT;
- break;
-#ifdef HAVE_EGL_DEVICE
- case META_RENDERER_NATIVE_MODE_EGL_DEVICE:
- attributes[i++] = EGL_SURFACE_TYPE;
- attributes[i++] = EGL_STREAM_BIT_KHR;
- break;
-#endif
- }
-
- return i;
-}
-
-static gboolean
-choose_egl_config_from_gbm_format (MetaEgl *egl,
- EGLDisplay egl_display,
- const EGLint *attributes,
- uint32_t gbm_format,
- EGLConfig *out_config,
- GError **error)
-{
- EGLConfig *egl_configs;
- EGLint n_configs;
- EGLint i;
-
- egl_configs = meta_egl_choose_all_configs (egl, egl_display,
- attributes,
- &n_configs,
- error);
- if (!egl_configs)
- return FALSE;
-
- for (i = 0; i < n_configs; i++)
- {
- EGLint visual_id;
-
- if (!meta_egl_get_config_attrib (egl, egl_display,
- egl_configs[i],
- EGL_NATIVE_VISUAL_ID,
- &visual_id,
- error))
- {
- g_free (egl_configs);
- return FALSE;
- }
-
- if ((uint32_t) visual_id == gbm_format)
- {
- *out_config = egl_configs[i];
- g_free (egl_configs);
- return TRUE;
- }
- }
-
- g_free (egl_configs);
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- "No EGL config matching supported GBM format found");
- return FALSE;
-}
-
-static gboolean
-meta_renderer_native_choose_egl_config (CoglDisplay *cogl_display,
- EGLint *attributes,
- EGLConfig *out_config,
- GError **error)
-{
- CoglRenderer *cogl_renderer = cogl_display->renderer;
- CoglRendererEGL *cogl_renderer_egl = cogl_renderer->winsys;
- MetaBackend *backend = meta_get_backend ();
- MetaEgl *egl = meta_backend_get_egl (backend);
- MetaRendererNativeGpuData *renderer_gpu_data = cogl_renderer_egl->platform;
- EGLDisplay egl_display = cogl_renderer_egl->edpy;
-
- switch (renderer_gpu_data->mode)
- {
- case META_RENDERER_NATIVE_MODE_GBM:
- return choose_egl_config_from_gbm_format (egl,
- egl_display,
- attributes,
- GBM_FORMAT_XRGB8888,
- out_config,
- error);
- case META_RENDERER_NATIVE_MODE_SURFACELESS:
- *out_config = EGL_NO_CONFIG_KHR;
- return TRUE;
-#ifdef HAVE_EGL_DEVICE
- case META_RENDERER_NATIVE_MODE_EGL_DEVICE:
- return meta_egl_choose_first_config (egl,
- egl_display,
- attributes,
- out_config,
- error);
-#endif
- }
-
- return FALSE;
-}
-
-static gboolean
-meta_renderer_native_setup_egl_display (CoglDisplay *cogl_display,
- GError **error)
-{
- CoglDisplayEGL *cogl_display_egl = cogl_display->winsys;
- CoglRendererEGL *cogl_renderer_egl = cogl_display->renderer->winsys;
- MetaRendererNativeGpuData *renderer_gpu_data = cogl_renderer_egl->platform;
- MetaRendererNative *renderer_native = renderer_gpu_data->renderer_native;
-
- cogl_display_egl->platform = renderer_native;
-
- /* Force a full modeset / drmModeSetCrtc on
- * the first swap buffers call.
- */
- meta_renderer_native_queue_modes_reset (renderer_native);
-
- return TRUE;
-}
-
-static void
-meta_renderer_native_destroy_egl_display (CoglDisplay *cogl_display)
-{
-}
-
-static EGLSurface
-create_dummy_pbuffer_surface (EGLDisplay egl_display,
- GError **error)
-{
- MetaBackend *backend = meta_get_backend ();
- MetaEgl *egl = meta_backend_get_egl (backend);
- EGLConfig pbuffer_config;
- static const EGLint pbuffer_config_attribs[] = {
- EGL_SURFACE_TYPE, EGL_PBUFFER_BIT,
- EGL_RED_SIZE, 1,
- EGL_GREEN_SIZE, 1,
- EGL_BLUE_SIZE, 1,
- EGL_ALPHA_SIZE, 0,
- EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
- EGL_NONE
- };
- static const EGLint pbuffer_attribs[] = {
- EGL_WIDTH, 16,
- EGL_HEIGHT, 16,
- EGL_NONE
- };
-
- if (!meta_egl_choose_first_config (egl, egl_display, pbuffer_config_attribs,
- &pbuffer_config, error))
- return EGL_NO_SURFACE;
-
- return meta_egl_create_pbuffer_surface (egl, egl_display,
- pbuffer_config, pbuffer_attribs,
- error);
-}
-
-static gboolean
-meta_renderer_native_egl_context_created (CoglDisplay *cogl_display,
- GError **error)
-{
- CoglDisplayEGL *cogl_display_egl = cogl_display->winsys;
- CoglRenderer *cogl_renderer = cogl_display->renderer;
- CoglRendererEGL *cogl_renderer_egl = cogl_renderer->winsys;
-
- if ((cogl_renderer_egl->private_features &
- COGL_EGL_WINSYS_FEATURE_SURFACELESS_CONTEXT) == 0)
- {
- cogl_display_egl->dummy_surface =
- create_dummy_pbuffer_surface (cogl_renderer_egl->edpy, error);
- if (cogl_display_egl->dummy_surface == EGL_NO_SURFACE)
- return FALSE;
- }
-
- if (!_cogl_winsys_egl_make_current (cogl_display,
- cogl_display_egl->dummy_surface,
- cogl_display_egl->dummy_surface,
- cogl_display_egl->egl_context))
- {
- g_set_error (error, COGL_WINSYS_ERROR,
- COGL_WINSYS_ERROR_CREATE_CONTEXT,
- "Failed to make context current");
- return FALSE;
- }
-
- return TRUE;
-}
-
-static void
-meta_renderer_native_egl_cleanup_context (CoglDisplay *cogl_display)
-{
- CoglDisplayEGL *cogl_display_egl = cogl_display->winsys;
- CoglRenderer *cogl_renderer = cogl_display->renderer;
- CoglRendererEGL *cogl_renderer_egl = cogl_renderer->winsys;
- MetaRendererNativeGpuData *renderer_gpu_data = cogl_renderer_egl->platform;
- MetaRendererNative *renderer_native = renderer_gpu_data->renderer_native;
- MetaEgl *egl = meta_renderer_native_get_egl (renderer_native);
-
- if (cogl_display_egl->dummy_surface != EGL_NO_SURFACE)
- {
- meta_egl_destroy_surface (egl,
- cogl_renderer_egl->edpy,
- cogl_display_egl->dummy_surface,
- NULL);
- cogl_display_egl->dummy_surface = EGL_NO_SURFACE;
- }
-}
-
-static CoglContext *
-cogl_context_from_renderer_native (MetaRendererNative *renderer_native)
-{
- MetaRenderer *renderer = META_RENDERER (renderer_native);
- MetaBackend *backend = meta_renderer_get_backend (renderer);
- ClutterBackend *clutter_backend = meta_backend_get_clutter_backend (backend);
-
- return clutter_backend_get_cogl_context (clutter_backend);
-}
-
-CoglFramebuffer *
-meta_renderer_native_create_dma_buf_framebuffer (MetaRendererNative *renderer_native,
- int dmabuf_fd,
- uint32_t width,
- uint32_t height,
- uint32_t stride,
- uint32_t offset,
- uint64_t modifier,
- uint32_t drm_format,
- GError **error)
-{
- CoglContext *cogl_context =
- cogl_context_from_renderer_native (renderer_native);
- CoglDisplay *cogl_display = cogl_context->display;
- CoglRenderer *cogl_renderer = cogl_display->renderer;
- CoglRendererEGL *cogl_renderer_egl = cogl_renderer->winsys;
- EGLDisplay egl_display = cogl_renderer_egl->edpy;
- MetaEgl *egl = meta_renderer_native_get_egl (renderer_native);
- EGLImageKHR egl_image;
- uint32_t strides[1];
- uint32_t offsets[1];
- uint64_t modifiers[1];
- CoglPixelFormat cogl_format;
- CoglEglImageFlags flags;
- CoglTexture2D *cogl_tex;
- CoglOffscreen *cogl_fbo;
- int ret;
-
- ret = meta_cogl_pixel_format_from_drm_format (drm_format,
- &cogl_format,
- NULL);
- g_assert (ret);
-
- strides[0] = stride;
- offsets[0] = offset;
- modifiers[0] = modifier;
- egl_image = meta_egl_create_dmabuf_image (egl,
- egl_display,
- width,
- height,
- drm_format,
- 1 /* n_planes */,
- &dmabuf_fd,
- strides,
- offsets,
- modifiers,
- error);
- if (egl_image == EGL_NO_IMAGE_KHR)
- return NULL;
-
- flags = COGL_EGL_IMAGE_FLAG_NO_GET_DATA;
- cogl_tex = cogl_egl_texture_2d_new_from_image (cogl_context,
- width,
- height,
- cogl_format,
- egl_image,
- flags,
- error);
-
- meta_egl_destroy_image (egl, egl_display, egl_image, NULL);
-
- if (!cogl_tex)
- return NULL;
-
- cogl_fbo = cogl_offscreen_new_with_texture (COGL_TEXTURE (cogl_tex));
- cogl_object_unref (cogl_tex);
-
- if (!cogl_framebuffer_allocate (COGL_FRAMEBUFFER (cogl_fbo), error))
- {
- g_object_unref (cogl_fbo);
- return NULL;
- }
-
- return COGL_FRAMEBUFFER (cogl_fbo);
-}
-
-static void
-configure_disabled_crtcs (MetaKmsDevice *kms_device)
-{
- MetaKms *kms = meta_kms_device_get_kms (kms_device);
- GList *l;
-
- for (l = meta_kms_device_get_crtcs (kms_device); l; l = l->next)
- {
- MetaKmsCrtc *kms_crtc = l->data;
- MetaCrtcKms *crtc_kms = meta_crtc_kms_from_kms_crtc (kms_crtc);
- MetaKmsUpdate *kms_update;
-
- if (meta_crtc_get_config (META_CRTC (crtc_kms)))
- continue;
-
- if (!meta_kms_crtc_is_active (kms_crtc))
- continue;
-
- kms_update = meta_kms_ensure_pending_update (kms, kms_device);
- meta_kms_update_mode_set (kms_update, kms_crtc, NULL, NULL);
- }
-}
-
-static gboolean
-dummy_power_save_page_flip_cb (gpointer user_data)
-{
- MetaRendererNative *renderer_native = user_data;
-
- g_list_foreach (renderer_native->power_save_page_flip_onscreens,
- (GFunc) meta_onscreen_native_dummy_power_save_page_flip,
- NULL);
- g_clear_list (&renderer_native->power_save_page_flip_onscreens,
- g_object_unref);
- renderer_native->power_save_page_flip_source_id = 0;
-
- return G_SOURCE_REMOVE;
-}
-
-void
-meta_renderer_native_queue_power_save_page_flip (MetaRendererNative *renderer_native,
- CoglOnscreen *onscreen)
-{
- const unsigned int timeout_ms = 100;
-
- if (!renderer_native->power_save_page_flip_source_id)
- {
- renderer_native->power_save_page_flip_source_id =
- g_timeout_add (timeout_ms,
- dummy_power_save_page_flip_cb,
- renderer_native);
- }
-
- renderer_native->power_save_page_flip_onscreens =
- g_list_prepend (renderer_native->power_save_page_flip_onscreens,
- g_object_ref (onscreen));
-}
-
-static void
-clear_kept_alive_onscreens (MetaRendererNative *renderer_native)
-{
- g_clear_list (&renderer_native->kept_alive_onscreens,
- g_object_unref);
-}
-
-static gboolean
-is_gpu_unused (gpointer key,
- gpointer value,
- gpointer user_data)
-{
- GHashTable *used_gpus = user_data;
-
- return !g_hash_table_contains (used_gpus, key);
-}
-
-static void
-free_unused_gpu_datas (MetaRendererNative *renderer_native)
-{
- MetaRenderer *renderer = META_RENDERER (renderer_native);
- g_autoptr (GHashTable) used_gpus = NULL;
- GList *l;
-
- used_gpus = g_hash_table_new (NULL, NULL);
- g_hash_table_add (used_gpus, renderer_native->primary_gpu_kms);
-
- for (l = meta_renderer_get_views (renderer); l; l = l->next)
- {
- MetaRendererView *view = l->data;
- MetaCrtc *crtc = meta_renderer_view_get_crtc (view);
- MetaGpu *gpu;
-
- gpu = meta_crtc_get_gpu (crtc);
- if (!gpu)
- continue;
-
- g_hash_table_add (used_gpus, gpu);
- }
-
- g_hash_table_foreach_remove (renderer_native->gpu_datas,
- is_gpu_unused,
- used_gpus);
-}
-
-void
-meta_renderer_native_post_mode_set_updates (MetaRendererNative *renderer_native)
-{
- MetaRenderer *renderer = META_RENDERER (renderer_native);
- MetaBackend *backend = meta_renderer_get_backend (renderer);
- MetaKms *kms = meta_backend_native_get_kms (META_BACKEND_NATIVE (backend));
- GList *l;
-
- for (l = meta_kms_get_devices (kms); l; l = l->next)
- {
- MetaKmsDevice *kms_device = l->data;
- MetaKmsUpdate *kms_update;
- MetaKmsUpdateFlag flags;
- g_autoptr (MetaKmsFeedback) kms_feedback = NULL;
- const GError *feedback_error;
-
- configure_disabled_crtcs (kms_device);
-
- kms_update = meta_kms_get_pending_update (kms, kms_device);
- if (!kms_update)
- continue;
-
- flags = META_KMS_UPDATE_FLAG_NONE;
- kms_feedback = meta_kms_post_pending_update_sync (kms, kms_device, flags);
-
- switch (meta_kms_feedback_get_result (kms_feedback))
- {
- case META_KMS_FEEDBACK_PASSED:
- break;
- case META_KMS_FEEDBACK_FAILED:
- feedback_error = meta_kms_feedback_get_error (kms_feedback);
- if (!g_error_matches (feedback_error,
- G_IO_ERROR,
- G_IO_ERROR_PERMISSION_DENIED))
- g_warning ("Failed to post KMS update: %s", feedback_error->message);
- break;
- }
- }
-
- clear_kept_alive_onscreens (renderer_native);
-
- meta_kms_notify_modes_set (kms);
-
- free_unused_gpu_datas (renderer_native);
-}
-
-static void
-unset_disabled_crtcs (MetaBackend *backend,
- MetaKms *kms)
-{
- GList *l;
-
- meta_topic (META_DEBUG_KMS, "Disabling all disabled CRTCs");
-
- for (l = meta_backend_get_gpus (backend); l; l = l->next)
- {
- MetaGpu *gpu = l->data;
- MetaKmsDevice *kms_device =
- meta_gpu_kms_get_kms_device (META_GPU_KMS (gpu));
- GList *k;
- gboolean did_mode_set = FALSE;
- MetaKmsUpdateFlag flags;
- g_autoptr (MetaKmsFeedback) kms_feedback = NULL;
-
- for (k = meta_gpu_get_crtcs (gpu); k; k = k->next)
- {
- MetaCrtc *crtc = k->data;
- MetaKmsUpdate *kms_update;
-
- if (meta_crtc_get_config (crtc))
- continue;
-
- kms_update = meta_kms_ensure_pending_update (kms, kms_device);
- meta_crtc_kms_set_mode (META_CRTC_KMS (crtc), kms_update);
-
- did_mode_set = TRUE;
- }
-
- if (!did_mode_set)
- continue;
-
- flags = META_KMS_UPDATE_FLAG_NONE;
- kms_feedback = meta_kms_post_pending_update_sync (kms,
- kms_device,
- flags);
- if (meta_kms_feedback_get_result (kms_feedback) !=
- META_KMS_FEEDBACK_PASSED)
- {
- const GError *error = meta_kms_feedback_get_error (kms_feedback);
-
- if (!g_error_matches (error, G_IO_ERROR,
- G_IO_ERROR_PERMISSION_DENIED))
- g_warning ("Failed to post KMS update: %s", error->message);
- }
- }
-}
-
-static CoglDmaBufHandle *
-meta_renderer_native_create_dma_buf (CoglRenderer *cogl_renderer,
- int width,
- int height,
- GError **error)
-{
- CoglRendererEGL *cogl_renderer_egl = cogl_renderer->winsys;
- MetaRendererNativeGpuData *renderer_gpu_data = cogl_renderer_egl->platform;
- MetaRendererNative *renderer_native = renderer_gpu_data->renderer_native;
-
- switch (renderer_gpu_data->mode)
- {
- case META_RENDERER_NATIVE_MODE_GBM:
- {
- CoglFramebuffer *dmabuf_fb;
- CoglDmaBufHandle *dmabuf_handle;
- struct gbm_bo *new_bo;
- int stride;
- int offset;
- int bpp;
- int dmabuf_fd = -1;
-
- new_bo = gbm_bo_create (renderer_gpu_data->gbm.device,
- width, height, DRM_FORMAT_XRGB8888,
- GBM_BO_USE_RENDERING | GBM_BO_USE_LINEAR);
-
- if (!new_bo)
- {
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- "Failed to allocate buffer");
- return NULL;
- }
-
- dmabuf_fd = gbm_bo_get_fd (new_bo);
-
- if (dmabuf_fd == -1)
- {
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_EXISTS,
- "Failed to export buffer's DMA fd: %s",
- g_strerror (errno));
- return NULL;
- }
-
- stride = gbm_bo_get_stride (new_bo);
- offset = gbm_bo_get_offset (new_bo, 0);
- bpp = 4;
- dmabuf_fb =
- meta_renderer_native_create_dma_buf_framebuffer (renderer_native,
- dmabuf_fd,
- width, height,
- stride,
- offset,
- DRM_FORMAT_MOD_LINEAR,
- DRM_FORMAT_XRGB8888,
- error);
-
- if (!dmabuf_fb)
- return NULL;
-
- dmabuf_handle =
- cogl_dma_buf_handle_new (dmabuf_fb, dmabuf_fd,
- width, height, stride, offset, bpp,
- new_bo,
- (GDestroyNotify) gbm_bo_destroy);
- g_object_unref (dmabuf_fb);
- return dmabuf_handle;
- }
- break;
- case META_RENDERER_NATIVE_MODE_SURFACELESS:
-#ifdef HAVE_EGL_DEVICE
- case META_RENDERER_NATIVE_MODE_EGL_DEVICE:
-#endif
- break;
- }
-
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_UNKNOWN,
- "Current mode does not support exporting DMA buffers");
-
- return NULL;
-}
-
-static gboolean
-meta_renderer_native_init_egl_context (CoglContext *cogl_context,
- GError **error)
-{
-#ifdef HAVE_EGL_DEVICE
- CoglRenderer *cogl_renderer = cogl_context->display->renderer;
- CoglRendererEGL *cogl_renderer_egl = cogl_renderer->winsys;
- MetaRendererNativeGpuData *renderer_gpu_data = cogl_renderer_egl->platform;
-#endif
-
- COGL_FLAGS_SET (cogl_context->winsys_features,
- COGL_WINSYS_FEATURE_SWAP_BUFFERS_EVENT,
- TRUE);
- COGL_FLAGS_SET (cogl_context->winsys_features,
- COGL_WINSYS_FEATURE_SYNC_AND_COMPLETE_EVENT,
- TRUE);
- COGL_FLAGS_SET (cogl_context->winsys_features,
- COGL_WINSYS_FEATURE_MULTIPLE_ONSCREEN,
- TRUE);
-
-#ifdef HAVE_EGL_DEVICE
- if (renderer_gpu_data->mode == META_RENDERER_NATIVE_MODE_EGL_DEVICE)
- COGL_FLAGS_SET (cogl_context->features,
- COGL_FEATURE_ID_TEXTURE_EGL_IMAGE_EXTERNAL, TRUE);
-#endif
-
- return TRUE;
-}
-
-static const CoglWinsysEGLVtable
-_cogl_winsys_egl_vtable = {
- .add_config_attributes = meta_renderer_native_add_egl_config_attributes,
- .choose_config = meta_renderer_native_choose_egl_config,
- .display_setup = meta_renderer_native_setup_egl_display,
- .display_destroy = meta_renderer_native_destroy_egl_display,
- .context_created = meta_renderer_native_egl_context_created,
- .cleanup_context = meta_renderer_native_egl_cleanup_context,
- .context_init = meta_renderer_native_init_egl_context
-};
-
-static void
-meta_renderer_native_queue_modes_reset (MetaRendererNative *renderer_native)
-{
- MetaRenderer *renderer = META_RENDERER (renderer_native);
- GList *l;
-
- g_clear_list (&renderer_native->pending_mode_set_views, NULL);
- for (l = meta_renderer_get_views (renderer); l; l = l->next)
- {
- ClutterStageView *stage_view = l->data;
- CoglFramebuffer *framebuffer =
- clutter_stage_view_get_onscreen (stage_view);
-
- if (COGL_IS_ONSCREEN (framebuffer))
- {
- renderer_native->pending_mode_set_views =
- g_list_prepend (renderer_native->pending_mode_set_views,
- stage_view);
- }
- }
- renderer_native->pending_mode_set = TRUE;
-
- meta_topic (META_DEBUG_KMS, "Queue mode set");
-}
-
-void
-meta_renderer_native_notify_mode_sets_reset (MetaRendererNative *renderer_native)
-{
- renderer_native->pending_mode_set = FALSE;
-}
-
-gboolean
-meta_renderer_native_pop_pending_mode_set (MetaRendererNative *renderer_native,
- MetaRendererView *view)
-{
- MetaRenderer *renderer = META_RENDERER (renderer_native);
- MetaBackend *backend = meta_renderer_get_backend (renderer);
- MetaMonitorManager *monitor_manager =
- meta_backend_get_monitor_manager (backend);
- MetaPowerSave power_save_mode;
- GList *link;
-
- g_assert (META_IS_RENDERER_VIEW (view));
-
- power_save_mode = meta_monitor_manager_get_power_save_mode (monitor_manager);
- if (power_save_mode != META_POWER_SAVE_ON)
- return FALSE;
-
- link = g_list_find (renderer_native->pending_mode_set_views, view);
- if (!link)
- return FALSE;
-
- renderer_native->pending_mode_set_views =
- g_list_delete_link (renderer_native->pending_mode_set_views, link);
- return TRUE;
-}
-
-static CoglOffscreen *
-meta_renderer_native_create_offscreen (MetaRendererNative *renderer,
- CoglContext *context,
- gint view_width,
- gint view_height,
- GError **error)
-{
- CoglOffscreen *fb;
- CoglTexture2D *tex;
-
- tex = cogl_texture_2d_new_with_size (context, view_width, view_height);
- cogl_primitive_texture_set_auto_mipmap (COGL_PRIMITIVE_TEXTURE (tex), FALSE);
-
- if (!cogl_texture_allocate (COGL_TEXTURE (tex), error))
- {
- cogl_object_unref (tex);
- return FALSE;
- }
-
- fb = cogl_offscreen_new_with_texture (COGL_TEXTURE (tex));
- cogl_object_unref (tex);
- if (!cogl_framebuffer_allocate (COGL_FRAMEBUFFER (fb), error))
- {
- g_object_unref (fb);
- return FALSE;
- }
-
- return fb;
-}
-
-static const CoglWinsysVtable *
-get_native_cogl_winsys_vtable (CoglRenderer *cogl_renderer)
-{
- static gboolean vtable_inited = FALSE;
- static CoglWinsysVtable vtable;
-
- if (!vtable_inited)
- {
- /* The this winsys is a subclass of the EGL winsys so we
- start by copying its vtable */
-
- parent_vtable = _cogl_winsys_egl_get_vtable ();
- vtable = *parent_vtable;
-
- vtable.id = COGL_WINSYS_ID_CUSTOM;
- vtable.name = "EGL_KMS";
-
- vtable.renderer_connect = meta_renderer_native_connect;
- vtable.renderer_disconnect = meta_renderer_native_disconnect;
- vtable.renderer_create_dma_buf = meta_renderer_native_create_dma_buf;
-
- vtable_inited = TRUE;
- }
-
- return &vtable;
-}
-
-static CoglRenderer *
-meta_renderer_native_create_cogl_renderer (MetaRenderer *renderer)
-{
- CoglRenderer *cogl_renderer;
-
- cogl_renderer = cogl_renderer_new ();
- cogl_renderer_set_custom_winsys (cogl_renderer,
- get_native_cogl_winsys_vtable,
- renderer);
- return cogl_renderer;
-}
-
-static MetaMonitorTransform
-calculate_view_transform (MetaMonitorManager *monitor_manager,
- MetaLogicalMonitor *logical_monitor,
- MetaOutput *output,
- MetaCrtc *crtc)
-{
- MetaMonitorTransform crtc_transform;
-
- crtc = meta_output_get_assigned_crtc (output);
- crtc_transform =
- meta_output_logical_to_crtc_transform (output, logical_monitor->transform);
-
- if (meta_monitor_manager_is_transform_handled (monitor_manager,
- crtc,
- crtc_transform))
- return META_MONITOR_TRANSFORM_NORMAL;
- else
- return crtc_transform;
-}
-
-static gboolean
-should_force_shadow_fb (MetaRendererNative *renderer_native,
- MetaGpuKms *primary_gpu)
-{
- MetaRenderer *renderer = META_RENDERER (renderer_native);
- CoglContext *cogl_context =
- cogl_context_from_renderer_native (renderer_native);
- MetaKmsDevice *kms_device = meta_gpu_kms_get_kms_device (primary_gpu);
-
- if (meta_renderer_is_hardware_accelerated (renderer))
- return FALSE;
-
- if (!cogl_has_feature (cogl_context, COGL_FEATURE_ID_BLIT_FRAMEBUFFER))
- return FALSE;
-
- return meta_kms_device_prefers_shadow_buffer (kms_device);
-}
-
-static CoglFramebuffer *
-create_fallback_offscreen (MetaRendererNative *renderer_native,
- CoglContext *cogl_context,
- int width,
- int height)
-{
- CoglOffscreen *fallback_offscreen;
- GError *error = NULL;
-
- fallback_offscreen = meta_renderer_native_create_offscreen (renderer_native,
- cogl_context,
- width,
- height,
- &error);
- if (!fallback_offscreen)
- {
- g_error ("Failed to create fallback offscreen framebuffer: %s",
- error->message);
- }
-
- return COGL_FRAMEBUFFER (fallback_offscreen);
-}
-
-static MetaRendererView *
-meta_renderer_native_create_view (MetaRenderer *renderer,
- MetaLogicalMonitor *logical_monitor,
- MetaOutput *output,
- MetaCrtc *crtc)
-{
- MetaRendererNative *renderer_native = META_RENDERER_NATIVE (renderer);
- MetaBackend *backend = meta_renderer_get_backend (renderer);
- MetaMonitorManager *monitor_manager =
- meta_backend_get_monitor_manager (backend);
- CoglContext *cogl_context =
- cogl_context_from_renderer_native (renderer_native);
- CoglDisplay *cogl_display = cogl_context_get_display (cogl_context);
- const MetaCrtcConfig *crtc_config;
- const MetaCrtcModeInfo *crtc_mode_info;
- MetaMonitorTransform view_transform;
- g_autoptr (CoglFramebuffer) framebuffer = NULL;
- g_autoptr (CoglOffscreen) offscreen = NULL;
- gboolean use_shadowfb;
- float scale;
- int onscreen_width;
- int onscreen_height;
- MetaRectangle view_layout;
- MetaRendererView *view;
- EGLSurface egl_surface;
- GError *error = NULL;
-
- crtc_config = meta_crtc_get_config (crtc);
- crtc_mode_info = meta_crtc_mode_get_info (crtc_config->mode);
- onscreen_width = crtc_mode_info->width;
- onscreen_height = crtc_mode_info->height;
-
- if (META_IS_CRTC_KMS (crtc))
- {
- MetaGpuKms *gpu_kms = META_GPU_KMS (meta_crtc_get_gpu (crtc));
- MetaOnscreenNative *onscreen_native;
-
- if (!meta_renderer_native_ensure_gpu_data (renderer_native,
- gpu_kms,
- &error))
- {
- g_warning ("Failed to create secondary GPU data for %s: %s",
- meta_gpu_kms_get_file_path (gpu_kms),
- error->message);
- use_shadowfb = FALSE;
- framebuffer = create_fallback_offscreen (renderer_native,
- cogl_context,
- onscreen_width,
- onscreen_height);
- }
- else
- {
- MetaGpuKms *primary_gpu_kms = renderer_native->primary_gpu_kms;
-
- onscreen_native = meta_onscreen_native_new (renderer_native,
- primary_gpu_kms,
- output,
- crtc,
- cogl_context,
- onscreen_width,
- onscreen_height);
-
- if (!cogl_framebuffer_allocate (COGL_FRAMEBUFFER (onscreen_native), &error))
- {
- g_warning ("Failed to allocate onscreen framebuffer for %s: %s",
- meta_gpu_kms_get_file_path (gpu_kms),
- error->message);
- use_shadowfb = FALSE;
- framebuffer = create_fallback_offscreen (renderer_native,
- cogl_context,
- onscreen_width,
- onscreen_height);
- }
- else
- {
- use_shadowfb = should_force_shadow_fb (renderer_native,
- primary_gpu_kms);
- framebuffer = COGL_FRAMEBUFFER (onscreen_native);
- }
- }
- }
- else
- {
- CoglOffscreen *virtual_onscreen;
-
- g_assert (META_IS_CRTC_VIRTUAL (crtc));
-
- virtual_onscreen = meta_renderer_native_create_offscreen (renderer_native,
- cogl_context,
- onscreen_width,
- onscreen_height,
- &error);
- if (!virtual_onscreen)
- g_error ("Failed to allocate back buffer texture: %s", error->message);
- use_shadowfb = FALSE;
- framebuffer = COGL_FRAMEBUFFER (virtual_onscreen);
- }
-
- view_transform = calculate_view_transform (monitor_manager,
- logical_monitor,
- output,
- crtc);
- if (view_transform != META_MONITOR_TRANSFORM_NORMAL)
- {
- int offscreen_width;
- int offscreen_height;
-
- if (meta_monitor_transform_is_rotated (view_transform))
- {
- offscreen_width = onscreen_height;
- offscreen_height = onscreen_width;
- }
- else
- {
- offscreen_width = onscreen_width;
- offscreen_height = onscreen_height;
- }
-
- offscreen = meta_renderer_native_create_offscreen (renderer_native,
- cogl_context,
- offscreen_width,
- offscreen_height,
- &error);
- if (!offscreen)
- g_error ("Failed to allocate back buffer texture: %s", error->message);
- }
-
- if (meta_is_stage_views_scaled ())
- scale = meta_logical_monitor_get_scale (logical_monitor);
- else
- scale = 1.0;
-
- meta_rectangle_from_graphene_rect (&crtc_config->layout,
- META_ROUNDING_STRATEGY_ROUND,
- &view_layout);
- view = g_object_new (META_TYPE_RENDERER_VIEW,
- "name", meta_output_get_name (output),
- "stage", meta_backend_get_stage (backend),
- "layout", &view_layout,
- "crtc", crtc,
- "scale", scale,
- "framebuffer", framebuffer,
- "offscreen", offscreen,
- "use-shadowfb", use_shadowfb,
- "transform", view_transform,
- "refresh-rate", crtc_mode_info->refresh_rate,
- "vblank-duration-us", crtc_mode_info->vblank_duration_us,
- NULL);
-
- if (META_IS_ONSCREEN_NATIVE (framebuffer))
- {
- CoglDisplayEGL *cogl_display_egl;
- CoglOnscreenEgl *onscreen_egl;
-
- meta_onscreen_native_set_view (COGL_ONSCREEN (framebuffer), view);
-
- /* Ensure we don't point to stale surfaces when creating the offscreen */
- cogl_display_egl = cogl_display->winsys;
- onscreen_egl = COGL_ONSCREEN_EGL (framebuffer);
- egl_surface = cogl_onscreen_egl_get_egl_surface (onscreen_egl);
- _cogl_winsys_egl_make_current (cogl_display,
- egl_surface,
- egl_surface,
- cogl_display_egl->egl_context);
- }
-
- return view;
-}
-
-static void
-keep_current_onscreens_alive (MetaRenderer *renderer)
-{
- MetaRendererNative *renderer_native = META_RENDERER_NATIVE (renderer);
- GList *views;
- GList *l;
-
- views = meta_renderer_get_views (renderer);
- for (l = views; l; l = l->next)
- {
- ClutterStageView *stage_view = l->data;
- CoglFramebuffer *onscreen = clutter_stage_view_get_onscreen (stage_view);
-
- renderer_native->kept_alive_onscreens =
- g_list_prepend (renderer_native->kept_alive_onscreens,
- g_object_ref (onscreen));
- }
-}
-
-static void
-meta_renderer_native_rebuild_views (MetaRenderer *renderer)
-{
- MetaBackend *backend = meta_renderer_get_backend (renderer);
- MetaBackendNative *backend_native = META_BACKEND_NATIVE (backend);
- MetaKms *kms = meta_backend_native_get_kms (backend_native);
- MetaRendererClass *parent_renderer_class =
- META_RENDERER_CLASS (meta_renderer_native_parent_class);
-
- meta_kms_discard_pending_page_flips (kms);
-
- keep_current_onscreens_alive (renderer);
-
- parent_renderer_class->rebuild_views (renderer);
-
- meta_renderer_native_queue_modes_reset (META_RENDERER_NATIVE (renderer));
-}
-
-void
-meta_renderer_native_prepare_frame (MetaRendererNative *renderer_native,
- MetaRendererView *view,
- ClutterFrame *frame)
-{
- MetaRenderer *renderer = META_RENDERER (renderer_native);
- MetaBackend *backend = meta_renderer_get_backend (renderer);
- MetaMonitorManager *monitor_manager =
- meta_backend_get_monitor_manager (backend);
- MetaCrtc *crtc = meta_renderer_view_get_crtc (view);
- MetaPowerSave power_save_mode;
- MetaCrtcKms *crtc_kms;
- MetaKmsCrtc *kms_crtc;
- MetaKmsDevice *kms_device;
-
- if (!META_IS_CRTC_KMS (crtc))
- return;
-
- power_save_mode = meta_monitor_manager_get_power_save_mode (monitor_manager);
- if (power_save_mode != META_POWER_SAVE_ON)
- return;
-
- crtc_kms = META_CRTC_KMS (crtc);
- kms_crtc = meta_crtc_kms_get_kms_crtc (META_CRTC_KMS (crtc));
- kms_device = meta_kms_crtc_get_device (kms_crtc);
-
- meta_crtc_kms_maybe_set_gamma (crtc_kms, kms_device);
-}
-
-void
-meta_renderer_native_finish_frame (MetaRendererNative *renderer_native,
- MetaRendererView *view,
- ClutterFrame *frame)
-{
- if (!clutter_frame_has_result (frame))
- {
- CoglFramebuffer *framebuffer =
- clutter_stage_view_get_onscreen (CLUTTER_STAGE_VIEW (view));
-
- if (COGL_IS_ONSCREEN (framebuffer))
- {
- CoglOnscreen *onscreen = COGL_ONSCREEN (framebuffer);
-
- meta_onscreen_native_finish_frame (onscreen, frame);
- }
- }
-}
-
-static gboolean
-create_secondary_egl_config (MetaEgl *egl,
- MetaRendererNativeMode mode,
- EGLDisplay egl_display,
- EGLConfig *egl_config,
- GError **error)
-{
- EGLint attributes[] = {
- EGL_RED_SIZE, 1,
- EGL_GREEN_SIZE, 1,
- EGL_BLUE_SIZE, 1,
- EGL_ALPHA_SIZE, EGL_DONT_CARE,
- EGL_BUFFER_SIZE, EGL_DONT_CARE,
- EGL_RENDERABLE_TYPE, EGL_OPENGL_ES3_BIT,
- EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
- EGL_NONE
- };
-
- switch (mode)
- {
- case META_RENDERER_NATIVE_MODE_GBM:
- case META_RENDERER_NATIVE_MODE_SURFACELESS:
- return choose_egl_config_from_gbm_format (egl,
- egl_display,
- attributes,
- GBM_FORMAT_XRGB8888,
- egl_config,
- error);
-#ifdef HAVE_EGL_DEVICE
- case META_RENDERER_NATIVE_MODE_EGL_DEVICE:
- return meta_egl_choose_first_config (egl,
- egl_display,
- attributes,
- egl_config,
- error);
-#endif
- }
-
- return FALSE;
-}
-
-static EGLContext
-create_secondary_egl_context (MetaEgl *egl,
- EGLDisplay egl_display,
- EGLConfig egl_config,
- GError **error)
-{
- EGLint attributes[] = {
- EGL_CONTEXT_CLIENT_VERSION, 3,
- EGL_NONE
- };
-
- return meta_egl_create_context (egl,
- egl_display,
- egl_config,
- EGL_NO_CONTEXT,
- attributes,
- error);
-}
-
-static void
-meta_renderer_native_ensure_gles3 (MetaRendererNative *renderer_native)
-{
- MetaEgl *egl = meta_renderer_native_get_egl (renderer_native);
-
- if (renderer_native->gles3)
- return;
-
- renderer_native->gles3 = meta_gles3_new (egl);
-}
-
-static void
-maybe_restore_cogl_egl_api (MetaRendererNative *renderer_native)
-{
- CoglContext *cogl_context;
- CoglDisplay *cogl_display;
- CoglRenderer *cogl_renderer;
-
- cogl_context = cogl_context_from_renderer_native (renderer_native);
- if (!cogl_context)
- return;
-
- cogl_display = cogl_context_get_display (cogl_context);
- cogl_renderer = cogl_display_get_renderer (cogl_display);
- cogl_renderer_bind_api (cogl_renderer);
-}
-
-static gboolean
-init_secondary_gpu_data_gpu (MetaRendererNativeGpuData *renderer_gpu_data,
- GError **error)
-{
- MetaRendererNative *renderer_native = renderer_gpu_data->renderer_native;
- MetaEgl *egl = meta_renderer_native_get_egl (renderer_native);
- EGLDisplay egl_display = renderer_gpu_data->egl_display;
- EGLConfig egl_config;
- EGLContext egl_context;
- const char **missing_gl_extensions;
- const char *renderer_str;
-
- meta_egl_bind_api (egl, EGL_OPENGL_ES_API, NULL);
-
- if (!create_secondary_egl_config (egl, renderer_gpu_data->mode, egl_display,
- &egl_config, error))
- goto err;
-
- egl_context = create_secondary_egl_context (egl, egl_display, egl_config, error);
- if (egl_context == EGL_NO_CONTEXT)
- goto err;
-
- meta_renderer_native_ensure_gles3 (renderer_native);
-
- if (!meta_egl_make_current (egl,
- egl_display,
- EGL_NO_SURFACE,
- EGL_NO_SURFACE,
- egl_context,
- error))
- {
- meta_egl_destroy_context (egl, egl_display, egl_context, NULL);
- goto err;
- }
-
- renderer_str = (const char *) glGetString (GL_RENDERER);
- if (g_str_has_prefix (renderer_str, "llvmpipe") ||
- g_str_has_prefix (renderer_str, "softpipe") ||
- g_str_has_prefix (renderer_str, "swrast"))
- {
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- "Do not want to use software renderer (%s), falling back to CPU copy path",
- renderer_str);
- goto err_fail_with_context;
- }
-
- if (!meta_gles3_has_extensions (renderer_native->gles3,
- &missing_gl_extensions,
- "GL_OES_EGL_image_external",
- NULL))
- {
- char *missing_gl_extensions_str;
-
- missing_gl_extensions_str = g_strjoinv (", ",
- (char **) missing_gl_extensions);
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- "Missing OpenGL ES extensions: %s",
- missing_gl_extensions_str);
- g_free (missing_gl_extensions_str);
- g_free (missing_gl_extensions);
-
- goto err_fail_with_context;
- }
-
- renderer_gpu_data->secondary.is_hardware_rendering = TRUE;
- renderer_gpu_data->secondary.egl_context = egl_context;
- renderer_gpu_data->secondary.egl_config = egl_config;
- renderer_gpu_data->secondary.copy_mode = META_SHARED_FRAMEBUFFER_COPY_MODE_SECONDARY_GPU;
-
- renderer_gpu_data->secondary.has_EGL_EXT_image_dma_buf_import_modifiers =
- meta_egl_has_extensions (egl, egl_display, NULL,
- "EGL_EXT_image_dma_buf_import_modifiers",
- NULL);
-
- maybe_restore_cogl_egl_api (renderer_native);
-
- return TRUE;
-
-err_fail_with_context:
- meta_egl_make_current (egl,
- egl_display,
- EGL_NO_SURFACE,
- EGL_NO_SURFACE,
- EGL_NO_CONTEXT,
- NULL);
- meta_egl_destroy_context (egl, egl_display, egl_context, NULL);
-
-err:
- maybe_restore_cogl_egl_api (renderer_native);
-
- return FALSE;
-}
-
-static void
-init_secondary_gpu_data_cpu (MetaRendererNativeGpuData *renderer_gpu_data)
-{
- renderer_gpu_data->secondary.is_hardware_rendering = FALSE;
-
- /* First try ZERO, it automatically falls back to PRIMARY as needed */
- renderer_gpu_data->secondary.copy_mode =
- META_SHARED_FRAMEBUFFER_COPY_MODE_ZERO;
-}
-
-static void
-init_secondary_gpu_data (MetaRendererNativeGpuData *renderer_gpu_data)
-{
- GError *error = NULL;
-
- if (init_secondary_gpu_data_gpu (renderer_gpu_data, &error))
- return;
-
- g_message ("Failed to initialize accelerated iGPU/dGPU framebuffer sharing: %s",
- error->message);
- g_error_free (error);
-
- init_secondary_gpu_data_cpu (renderer_gpu_data);
-}
-
-static gboolean
-gpu_kms_is_hardware_rendering (MetaRendererNative *renderer_native,
- MetaGpuKms *gpu_kms)
-{
- MetaRendererNativeGpuData *data;
-
- data = meta_renderer_native_get_gpu_data (renderer_native, gpu_kms);
- return data->secondary.is_hardware_rendering;
-}
-
-static EGLDisplay
-init_gbm_egl_display (MetaRendererNative *renderer_native,
- struct gbm_device *gbm_device,
- GError **error)
-{
- MetaEgl *egl = meta_renderer_native_get_egl (renderer_native);
- EGLDisplay egl_display;
-
- if (!meta_egl_has_extensions (egl, EGL_NO_DISPLAY, NULL,
- "EGL_MESA_platform_gbm",
- NULL) &&
- !meta_egl_has_extensions (egl, EGL_NO_DISPLAY, NULL,
- "EGL_KHR_platform_gbm",
- NULL))
- {
- g_set_error (error, G_IO_ERROR,
- G_IO_ERROR_FAILED,
- "Missing extension for GBM renderer: EGL_KHR_platform_gbm");
- return EGL_NO_DISPLAY;
- }
-
- egl_display = meta_egl_get_platform_display (egl,
- EGL_PLATFORM_GBM_KHR,
- gbm_device, NULL, error);
- if (egl_display == EGL_NO_DISPLAY)
- return EGL_NO_DISPLAY;
-
- if (!meta_egl_initialize (egl, egl_display, error))
- return EGL_NO_DISPLAY;
-
- return egl_display;
-}
-
-static MetaRendererNativeGpuData *
-create_renderer_gpu_data_gbm (MetaRendererNative *renderer_native,
- MetaDeviceFile *device_file,
- GError **error)
-{
- struct gbm_device *gbm_device;
- MetaRendererNativeGpuData *renderer_gpu_data;
- g_autoptr (GError) local_error = NULL;
-
- gbm_device = gbm_create_device (meta_device_file_get_fd (device_file));
- if (!gbm_device)
- {
- g_set_error (error, G_IO_ERROR,
- G_IO_ERROR_FAILED,
- "Failed to create gbm device: %s", g_strerror (errno));
- return NULL;
- }
-
- renderer_gpu_data = meta_create_renderer_native_gpu_data ();
- renderer_gpu_data->device_file = meta_device_file_acquire (device_file);
- renderer_gpu_data->renderer_native = renderer_native;
- renderer_gpu_data->gbm.device = gbm_device;
- renderer_gpu_data->mode = META_RENDERER_NATIVE_MODE_GBM;
-
- renderer_gpu_data->egl_display = init_gbm_egl_display (renderer_native,
- gbm_device,
- &local_error);
- if (renderer_gpu_data->egl_display == EGL_NO_DISPLAY)
- {
- g_debug ("GBM EGL init for %s failed: %s",
- meta_device_file_get_path (device_file),
- local_error->message);
-
- init_secondary_gpu_data_cpu (renderer_gpu_data);
- return renderer_gpu_data;
- }
-
- init_secondary_gpu_data (renderer_gpu_data);
- return renderer_gpu_data;
-}
-
-static EGLDisplay
-init_surfaceless_egl_display (MetaRendererNative *renderer_native,
- GError **error)
-{
- MetaEgl *egl = meta_renderer_native_get_egl (renderer_native);
- EGLDisplay egl_display;
-
- if (!meta_egl_has_extensions (egl, EGL_NO_DISPLAY, NULL,
- "EGL_MESA_platform_surfaceless",
- NULL))
- {
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- "Missing EGL platform required for surfaceless context: "
- "EGL_MESA_platform_surfaceless");
- return EGL_NO_DISPLAY;
- }
-
- egl_display = meta_egl_get_platform_display (egl,
- EGL_PLATFORM_SURFACELESS_MESA,
- EGL_DEFAULT_DISPLAY,
- NULL, error);
- if (egl_display == EGL_NO_DISPLAY)
- return EGL_NO_DISPLAY;
-
- if (!meta_egl_initialize (egl, egl_display, error))
- return EGL_NO_DISPLAY;
-
- if (!meta_egl_has_extensions (egl, egl_display, NULL,
- "EGL_KHR_no_config_context",
- NULL))
- {
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- "Missing EGL extension required for surfaceless context: "
- "EGL_KHR_no_config_context");
- return EGL_NO_DISPLAY;
- }
-
- return egl_display;
-}
-
-static MetaRendererNativeGpuData *
-create_renderer_gpu_data_surfaceless (MetaRendererNative *renderer_native,
- GError **error)
-{
- MetaRendererNativeGpuData *renderer_gpu_data;
- EGLDisplay egl_display;
-
- egl_display = init_surfaceless_egl_display (renderer_native, error);
- if (egl_display == EGL_NO_DISPLAY)
- return NULL;
-
- renderer_gpu_data = meta_create_renderer_native_gpu_data ();
- renderer_gpu_data->renderer_native = renderer_native;
- renderer_gpu_data->mode = META_RENDERER_NATIVE_MODE_SURFACELESS;
- renderer_gpu_data->egl_display = egl_display;
-
- return renderer_gpu_data;
-}
-
-#ifdef HAVE_EGL_DEVICE
-static const char *
-get_drm_device_file (MetaEgl *egl,
- EGLDeviceEXT device,
- GError **error)
-{
- if (!meta_egl_egl_device_has_extensions (egl, device,
- NULL,
- "EGL_EXT_device_drm",
- NULL))
- {
- g_set_error (error, G_IO_ERROR,
- G_IO_ERROR_FAILED,
- "Missing required EGLDevice extension EGL_EXT_device_drm");
- return NULL;
- }
-
- return meta_egl_query_device_string (egl, device,
- EGL_DRM_DEVICE_FILE_EXT,
- error);
-}
-
-static EGLDeviceEXT
-find_egl_device (MetaRendererNative *renderer_native,
- MetaDeviceFile *device_file,
- GError **error)
-{
- MetaEgl *egl = meta_renderer_native_get_egl (renderer_native);
- const char **missing_extensions;
- EGLint num_devices;
- EGLDeviceEXT *devices;
- const char *kms_file_path;
- EGLDeviceEXT device;
- EGLint i;
-
- if (!meta_egl_has_extensions (egl,
- EGL_NO_DISPLAY,
- &missing_extensions,
- "EGL_EXT_device_base",
- NULL))
- {
- char *missing_extensions_str;
-
- missing_extensions_str = g_strjoinv (", ", (char **) missing_extensions);
- g_set_error (error, G_IO_ERROR,
- G_IO_ERROR_FAILED,
- "Missing EGL extensions required for EGLDevice renderer: %s",
- missing_extensions_str);
- g_free (missing_extensions_str);
- g_free (missing_extensions);
- return EGL_NO_DEVICE_EXT;
- }
-
- if (!meta_egl_query_devices (egl, 0, NULL, &num_devices, error))
- return EGL_NO_DEVICE_EXT;
-
- devices = g_new0 (EGLDeviceEXT, num_devices);
- if (!meta_egl_query_devices (egl, num_devices, devices, &num_devices,
- error))
- {
- g_free (devices);
- return EGL_NO_DEVICE_EXT;
- }
-
- kms_file_path = meta_device_file_get_path (device_file);
-
- device = EGL_NO_DEVICE_EXT;
- for (i = 0; i < num_devices; i++)
- {
- const char *egl_device_drm_path;
-
- g_clear_error (error);
-
- egl_device_drm_path = get_drm_device_file (egl, devices[i], error);
- if (!egl_device_drm_path)
- continue;
-
- if (g_str_equal (egl_device_drm_path, kms_file_path))
- {
- device = devices[i];
- break;
- }
- }
- g_free (devices);
-
- if (device == EGL_NO_DEVICE_EXT)
- {
- if (!*error)
- g_set_error (error, G_IO_ERROR,
- G_IO_ERROR_FAILED,
- "Failed to find matching EGLDeviceEXT");
- return EGL_NO_DEVICE_EXT;
- }
-
- return device;
-}
-
-static EGLDisplay
-get_egl_device_display (MetaRendererNative *renderer_native,
- MetaDeviceFile *device_file,
- EGLDeviceEXT egl_device,
- GError **error)
-{
- MetaEgl *egl = meta_renderer_native_get_egl (renderer_native);
- int kms_fd = meta_device_file_get_fd (device_file);
- EGLint platform_attribs[] = {
- EGL_DRM_MASTER_FD_EXT, kms_fd,
- EGL_NONE
- };
-
- return meta_egl_get_platform_display (egl, EGL_PLATFORM_DEVICE_EXT,
- (void *) egl_device,
- platform_attribs,
- error);
-}
-
-static int
-count_drm_devices (MetaRendererNative *renderer_native)
-{
- MetaRenderer *renderer = META_RENDERER (renderer_native);
- MetaBackend *backend = meta_renderer_get_backend (renderer);
-
- return g_list_length (meta_backend_get_gpus (backend));
-}
-
-static MetaRendererNativeGpuData *
-create_renderer_gpu_data_egl_device (MetaRendererNative *renderer_native,
- MetaDeviceFile *device_file,
- GError **error)
-{
- MetaEgl *egl = meta_renderer_native_get_egl (renderer_native);
- const char **missing_extensions;
- EGLDeviceEXT egl_device;
- EGLDisplay egl_display;
- MetaRendererNativeGpuData *renderer_gpu_data;
-
- if (count_drm_devices (renderer_native) != 1)
- {
- g_set_error (error, G_IO_ERROR,
- G_IO_ERROR_FAILED,
- "EGLDevice currently only works with single GPU systems");
- return NULL;
- }
-
- egl_device = find_egl_device (renderer_native, device_file, error);
- if (egl_device == EGL_NO_DEVICE_EXT)
- return NULL;
-
- egl_display = get_egl_device_display (renderer_native, device_file,
- egl_device, error);
- if (egl_display == EGL_NO_DISPLAY)
- return NULL;
-
- if (!meta_egl_initialize (egl, egl_display, error))
- return NULL;
-
- if (!meta_egl_has_extensions (egl,
- egl_display,
- &missing_extensions,
- "EGL_NV_output_drm_flip_event",
- "EGL_EXT_output_base",
- "EGL_EXT_output_drm",
- "EGL_KHR_stream",
- "EGL_KHR_stream_producer_eglsurface",
- "EGL_EXT_stream_consumer_egloutput",
- "EGL_EXT_stream_acquire_mode",
- NULL))
- {
- char *missing_extensions_str;
-
- missing_extensions_str = g_strjoinv (", ", (char **) missing_extensions);
- g_set_error (error, G_IO_ERROR,
- G_IO_ERROR_FAILED,
- "Missing EGL extensions required for EGLDevice renderer: %s",
- missing_extensions_str);
- meta_egl_terminate (egl, egl_display, NULL);
- g_free (missing_extensions_str);
- g_free (missing_extensions);
- return NULL;
- }
-
- renderer_gpu_data = meta_create_renderer_native_gpu_data ();
- renderer_gpu_data->device_file = meta_device_file_acquire (device_file);
- renderer_gpu_data->renderer_native = renderer_native;
- renderer_gpu_data->egl.device = egl_device;
- renderer_gpu_data->mode = META_RENDERER_NATIVE_MODE_EGL_DEVICE;
- renderer_gpu_data->egl_display = egl_display;
-
- return renderer_gpu_data;
-}
-#endif /* HAVE_EGL_DEVICE */
-
-static MetaRendererNativeGpuData *
-meta_renderer_native_create_renderer_gpu_data (MetaRendererNative *renderer_native,
- MetaGpuKms *gpu_kms,
- GError **error)
-{
- MetaRenderer *renderer = META_RENDERER (renderer_native);
- MetaBackend *backend = meta_renderer_get_backend (renderer);
- MetaDevicePool *device_pool =
- meta_backend_native_get_device_pool (META_BACKEND_NATIVE (backend));
- MetaRendererNativeGpuData *renderer_gpu_data;
- MetaDeviceFileFlags device_file_flags = META_DEVICE_FILE_FLAG_NONE;
- g_autoptr (MetaDeviceFile) device_file = NULL;
- GError *gbm_error = NULL;
-#ifdef HAVE_EGL_DEVICE
- GError *egl_device_error = NULL;
-#endif
-
- if (!gpu_kms)
- return create_renderer_gpu_data_surfaceless (renderer_native, error);
-
- if (!(meta_kms_device_get_flags (meta_gpu_kms_get_kms_device (gpu_kms)) &
- META_KMS_DEVICE_FLAG_NO_MODE_SETTING))
- device_file_flags = META_DEVICE_FILE_FLAG_TAKE_CONTROL;
-
- device_file = meta_device_pool_open (device_pool,
- meta_gpu_kms_get_file_path (gpu_kms),
- device_file_flags,
- error);
- if (!device_file)
- return NULL;
-
-#ifdef HAVE_EGL_DEVICE
- /* Try to initialize the EGLDevice backend first. Whenever we use a
- * non-NVIDIA GPU, the EGLDevice enumeration function won't find a match, and
- * we'll fall back to GBM (which will always succeed as it has a software
- * rendering fallback)
- */
- renderer_gpu_data = create_renderer_gpu_data_egl_device (renderer_native,
- device_file,
- &egl_device_error);
- if (renderer_gpu_data)
- return renderer_gpu_data;
-#endif
-
- renderer_gpu_data = create_renderer_gpu_data_gbm (renderer_native,
- device_file,
- &gbm_error);
- if (renderer_gpu_data)
- {
-#ifdef HAVE_EGL_DEVICE
- g_error_free (egl_device_error);
-#endif
- return renderer_gpu_data;
- }
-
- g_set_error (error, G_IO_ERROR,
- G_IO_ERROR_FAILED,
- "Failed to initialize renderer: "
- "%s"
-#ifdef HAVE_EGL_DEVICE
- ", %s"
-#endif
- , gbm_error->message
-#ifdef HAVE_EGL_DEVICE
- , egl_device_error->message
-#endif
- );
-
- g_error_free (gbm_error);
-#ifdef HAVE_EGL_DEVICE
- g_error_free (egl_device_error);
-#endif
-
- return NULL;
-}
-
-static gboolean
-create_renderer_gpu_data (MetaRendererNative *renderer_native,
- MetaGpuKms *gpu_kms,
- GError **error)
-{
- MetaRendererNativeGpuData *renderer_gpu_data;
-
- renderer_gpu_data =
- meta_renderer_native_create_renderer_gpu_data (renderer_native,
- gpu_kms,
- error);
- if (!renderer_gpu_data)
- return FALSE;
-
- g_hash_table_insert (renderer_native->gpu_datas,
- gpu_kms,
- renderer_gpu_data);
-
- return TRUE;
-}
-
-static gboolean
-meta_renderer_native_ensure_gpu_data (MetaRendererNative *renderer_native,
- MetaGpuKms *gpu_kms,
- GError **error)
-{
- MetaRendererNativeGpuData *renderer_gpu_data;
-
- renderer_gpu_data = g_hash_table_lookup (renderer_native->gpu_datas, gpu_kms);
- if (renderer_gpu_data)
- return TRUE;
-
- return create_renderer_gpu_data (renderer_native, gpu_kms, error);
-}
-
-static void
-on_gpu_added (MetaBackendNative *backend_native,
- MetaGpuKms *gpu_kms,
- MetaRendererNative *renderer_native)
-{
- MetaBackend *backend = META_BACKEND (backend_native);
- ClutterBackend *clutter_backend = meta_backend_get_clutter_backend (backend);
- CoglContext *cogl_context = clutter_backend_get_cogl_context (clutter_backend);
- CoglDisplay *cogl_display = cogl_context_get_display (cogl_context);
- GError *error = NULL;
-
- if (!create_renderer_gpu_data (renderer_native, gpu_kms, &error))
- {
- g_warning ("on_gpu_added: could not create gpu_data for gpu %s: %s",
- meta_gpu_kms_get_file_path (gpu_kms), error->message);
- g_clear_error (&error);
- }
-
- _cogl_winsys_egl_ensure_current (cogl_display);
-}
-
-static void
-on_power_save_mode_changed (MetaMonitorManager *monitor_manager,
- MetaRendererNative *renderer_native)
-{
- MetaRenderer *renderer = META_RENDERER (renderer_native);
- MetaBackend *backend = meta_renderer_get_backend (renderer);
- MetaBackendNative *backend_native = META_BACKEND_NATIVE (backend);
- MetaKms *kms = meta_backend_native_get_kms (backend_native);
- MetaPowerSave power_save_mode;
-
- power_save_mode = meta_monitor_manager_get_power_save_mode (monitor_manager);
- if (power_save_mode == META_POWER_SAVE_ON)
- meta_renderer_native_queue_modes_reset (renderer_native);
- else
- meta_kms_discard_pending_page_flips (kms);
-}
-
-void
-meta_renderer_native_reset_modes (MetaRendererNative *renderer_native)
-{
- MetaRenderer *renderer = META_RENDERER (renderer_native);
- MetaBackend *backend = meta_renderer_get_backend (renderer);
- MetaBackendNative *backend_native = META_BACKEND_NATIVE (backend);
- MetaKms *kms = meta_backend_native_get_kms (backend_native);
-
- unset_disabled_crtcs (backend, kms);
-}
-
-static MetaGpuKms *
-choose_primary_gpu_unchecked (MetaBackend *backend,
- MetaRendererNative *renderer_native)
-{
- GList *gpus = meta_backend_get_gpus (backend);
- GList *l;
- int allow_sw;
-
- /*
- * Check first hardware rendering devices, and if none found,
- * then software rendering devices.
- */
- for (allow_sw = 0; allow_sw < 2; allow_sw++)
- {
- /* First check if one was explicitly configured. */
- for (l = gpus; l; l = l->next)
- {
- MetaGpuKms *gpu_kms = META_GPU_KMS (l->data);
- MetaKmsDevice *kms_device = meta_gpu_kms_get_kms_device (gpu_kms);
-
- if (meta_kms_device_get_flags (kms_device) &
- META_KMS_DEVICE_FLAG_PREFERRED_PRIMARY)
- {
- g_message ("GPU %s selected primary given udev rule",
- meta_gpu_kms_get_file_path (gpu_kms));
- return gpu_kms;
- }
- }
-
- /* Prefer a platform device */
- for (l = gpus; l; l = l->next)
- {
- MetaGpuKms *gpu_kms = META_GPU_KMS (l->data);
-
- if (meta_gpu_kms_is_platform_device (gpu_kms) &&
- (allow_sw == 1 ||
- gpu_kms_is_hardware_rendering (renderer_native, gpu_kms)))
- {
- g_message ("Integrated GPU %s selected as primary",
- meta_gpu_kms_get_file_path (gpu_kms));
- return gpu_kms;
- }
- }
-
- /* Otherwise a device we booted with */
- for (l = gpus; l; l = l->next)
- {
- MetaGpuKms *gpu_kms = META_GPU_KMS (l->data);
-
- if (meta_gpu_kms_is_boot_vga (gpu_kms) &&
- (allow_sw == 1 ||
- gpu_kms_is_hardware_rendering (renderer_native, gpu_kms)))
- {
- g_message ("Boot VGA GPU %s selected as primary",
- meta_gpu_kms_get_file_path (gpu_kms));
- return gpu_kms;
- }
- }
-
- /* Fall back to any device */
- for (l = gpus; l; l = l->next)
- {
- MetaGpuKms *gpu_kms = META_GPU_KMS (l->data);
-
- if (allow_sw == 1 ||
- gpu_kms_is_hardware_rendering (renderer_native, gpu_kms))
- {
- g_message ("GPU %s selected as primary",
- meta_gpu_kms_get_file_path (gpu_kms));
- return gpu_kms;
- }
- }
- }
-
- g_assert_not_reached ();
- return NULL;
-}
-
-static MetaGpuKms *
-choose_primary_gpu (MetaBackend *backend,
- MetaRendererNative *renderer_native,
- GError **error)
-{
- MetaGpuKms *gpu_kms;
- MetaRendererNativeGpuData *renderer_gpu_data;
-
- gpu_kms = choose_primary_gpu_unchecked (backend, renderer_native);
- renderer_gpu_data = meta_renderer_native_get_gpu_data (renderer_native,
- gpu_kms);
- if (renderer_gpu_data->egl_display == EGL_NO_DISPLAY)
- {
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- "The GPU %s chosen as primary is not supported by EGL.",
- meta_gpu_kms_get_file_path (gpu_kms));
- return NULL;
- }
-
- return gpu_kms;
-}
-
-static gboolean
-meta_renderer_native_initable_init (GInitable *initable,
- GCancellable *cancellable,
- GError **error)
-{
- MetaRendererNative *renderer_native = META_RENDERER_NATIVE (initable);
- MetaRenderer *renderer = META_RENDERER (renderer_native);
- MetaBackend *backend = meta_renderer_get_backend (renderer);
- GList *gpus;
- GList *l;
-
- gpus = meta_backend_get_gpus (backend);
- if (gpus)
- {
- const char *use_kms_modifiers_debug_env;
-
- for (l = gpus; l; l = l->next)
- {
- MetaGpuKms *gpu_kms = META_GPU_KMS (l->data);
-
- if (!create_renderer_gpu_data (renderer_native, gpu_kms, error))
- return FALSE;
- }
-
- renderer_native->primary_gpu_kms = choose_primary_gpu (backend,
- renderer_native,
- error);
- if (!renderer_native->primary_gpu_kms)
- return FALSE;
-
- use_kms_modifiers_debug_env = g_getenv ("MUTTER_DEBUG_USE_KMS_MODIFIERS");
- if (use_kms_modifiers_debug_env)
- {
- renderer_native->use_modifiers =
- g_strcmp0 (use_kms_modifiers_debug_env, "1") == 0;
- }
- else
- {
- renderer_native->use_modifiers =
- !meta_gpu_kms_disable_modifiers (renderer_native->primary_gpu_kms);
- }
-
- meta_topic (META_DEBUG_KMS, "Usage of KMS modifiers is %s",
- renderer_native->use_modifiers ? "enabled" : "disabled");
- }
- else
- {
- if (!create_renderer_gpu_data (renderer_native, NULL, error))
- return FALSE;
- }
-
- return TRUE;
-}
-
-static void
-initable_iface_init (GInitableIface *initable_iface)
-{
- initable_iface->init = meta_renderer_native_initable_init;
-}
-
-static void
-meta_renderer_native_finalize (GObject *object)
-{
- MetaRendererNative *renderer_native = META_RENDERER_NATIVE (object);
-
- clear_kept_alive_onscreens (renderer_native);
-
- g_clear_list (&renderer_native->power_save_page_flip_onscreens,
- g_object_unref);
- g_clear_handle_id (&renderer_native->power_save_page_flip_source_id,
- g_source_remove);
-
- g_list_free (renderer_native->pending_mode_set_views);
-
- g_hash_table_destroy (renderer_native->gpu_datas);
- g_clear_object (&renderer_native->gles3);
-
- G_OBJECT_CLASS (meta_renderer_native_parent_class)->finalize (object);
-}
-
-static void
-meta_renderer_native_constructed (GObject *object)
-{
- MetaRendererNative *renderer_native = META_RENDERER_NATIVE (object);
- MetaRenderer *renderer = META_RENDERER (renderer_native);
- MetaBackend *backend = meta_renderer_get_backend (renderer);
- MetaSettings *settings = meta_backend_get_settings (backend);
- MetaMonitorManager *monitor_manager =
- meta_backend_get_monitor_manager (backend);
-
- if (meta_settings_is_experimental_feature_enabled (
- settings, META_EXPERIMENTAL_FEATURE_KMS_MODIFIERS))
- renderer_native->use_modifiers = TRUE;
-
- g_signal_connect (backend, "gpu-added",
- G_CALLBACK (on_gpu_added), renderer_native);
- g_signal_connect (monitor_manager, "power-save-mode-changed",
- G_CALLBACK (on_power_save_mode_changed), renderer_native);
-
- G_OBJECT_CLASS (meta_renderer_native_parent_class)->constructed (object);
-}
-
-static void
-meta_renderer_native_init (MetaRendererNative *renderer_native)
-{
- renderer_native->gpu_datas =
- g_hash_table_new_full (NULL, NULL,
- NULL,
- (GDestroyNotify) meta_renderer_native_gpu_data_free);
-}
-
-static void
-meta_renderer_native_class_init (MetaRendererNativeClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
- MetaRendererClass *renderer_class = META_RENDERER_CLASS (klass);
-
- object_class->finalize = meta_renderer_native_finalize;
- object_class->constructed = meta_renderer_native_constructed;
-
- renderer_class->create_cogl_renderer = meta_renderer_native_create_cogl_renderer;
- renderer_class->create_view = meta_renderer_native_create_view;
- renderer_class->rebuild_views = meta_renderer_native_rebuild_views;
-}
-
-MetaRendererNative *
-meta_renderer_native_new (MetaBackendNative *backend_native,
- GError **error)
-{
- return g_initable_new (META_TYPE_RENDERER_NATIVE,
- NULL,
- error,
- "backend", backend_native,
- NULL);
-}
diff --git a/src/backends/native/meta-renderer-native.h b/src/backends/native/meta-renderer-native.h
deleted file mode 100644
index 2c23c651a..000000000
--- a/src/backends/native/meta-renderer-native.h
+++ /dev/null
@@ -1,71 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2016 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Written by:
- * Jonas Ådahl <jadahl@gmail.com>
- */
-
-#ifndef META_RENDERER_NATIVE_H
-#define META_RENDERER_NATIVE_H
-
-#include <gbm.h>
-#include <glib-object.h>
-#include <xf86drmMode.h>
-
-#include "backends/meta-renderer.h"
-#include "backends/native/meta-gpu-kms.h"
-#include "backends/native/meta-monitor-manager-native.h"
-
-#define META_TYPE_RENDERER_NATIVE (meta_renderer_native_get_type ())
-G_DECLARE_FINAL_TYPE (MetaRendererNative, meta_renderer_native,
- META, RENDERER_NATIVE,
- MetaRenderer)
-
-typedef enum _MetaRendererNativeMode
-{
- META_RENDERER_NATIVE_MODE_GBM,
- META_RENDERER_NATIVE_MODE_SURFACELESS,
-#ifdef HAVE_EGL_DEVICE
- META_RENDERER_NATIVE_MODE_EGL_DEVICE
-#endif
-} MetaRendererNativeMode;
-
-MetaRendererNative * meta_renderer_native_new (MetaBackendNative *backend_native,
- GError **error);
-
-struct gbm_device * meta_gbm_device_from_gpu (MetaGpuKms *gpu_kms);
-
-MetaGpuKms * meta_renderer_native_get_primary_gpu (MetaRendererNative *renderer_native);
-
-MetaDeviceFile * meta_renderer_native_get_primary_device_file (MetaRendererNative *renderer_native);
-
-void meta_renderer_native_prepare_frame (MetaRendererNative *renderer_native,
- MetaRendererView *view,
- ClutterFrame *frame);
-
-void meta_renderer_native_finish_frame (MetaRendererNative *renderer_native,
- MetaRendererView *view,
- ClutterFrame *frame);
-
-void meta_renderer_native_reset_modes (MetaRendererNative *renderer_native);
-
-gboolean meta_renderer_native_use_modifiers (MetaRendererNative *renderer_native);
-
-#endif /* META_RENDERER_NATIVE_H */
diff --git a/src/backends/native/meta-seat-impl.c b/src/backends/native/meta-seat-impl.c
deleted file mode 100644
index 26db30bd4..000000000
--- a/src/backends/native/meta-seat-impl.c
+++ /dev/null
@@ -1,3542 +0,0 @@
-/*
- * Clutter.
- *
- * An OpenGL based 'interactive canvas' library.
- *
- * Copyright (C) 2010 Intel Corp.
- * Copyright (C) 2014 Jonas Ådahl
- * Copyright (C) 2016 Red Hat Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
- *
- * Author: Damien Lespiau <damien.lespiau@intel.com>
- * Author: Jonas Ådahl <jadahl@gmail.com>
- * Author: Carlos Garnacho <carlosg@gnome.org>
- */
-
-#include "config.h"
-
-#include <errno.h>
-#include <fcntl.h>
-#include <libinput.h>
-#include <linux/input.h>
-#include <math.h>
-
-#include "backends/meta-cursor-tracker-private.h"
-#include "backends/native/meta-backend-native-private.h"
-#include "backends/native/meta-barrier-native.h"
-#include "backends/native/meta-device-pool.h"
-#include "backends/native/meta-input-thread.h"
-#include "backends/native/meta-virtual-input-device-native.h"
-#include "clutter/clutter-mutter.h"
-#include "core/bell.h"
-
-#include "meta-private-enum-types.h"
-
-/*
- * Clutter makes the assumption that two core devices have ID's 2 and 3 (core
- * pointer and core keyboard).
- *
- * Since the two first devices that will ever be created will be the virtual
- * pointer and virtual keyboard of the first seat, we fulfill the made
- * assumptions by having the first device having ID 2 and following 3.
- */
-#define INITIAL_DEVICE_ID 2
-
-/* Try to keep the pointer inside the stage. Hopefully no one is using
- * this backend with stages smaller than this. */
-#define INITIAL_POINTER_X 16
-#define INITIAL_POINTER_Y 16
-
-#define AUTOREPEAT_VALUE 2
-
-#define DISCRETE_SCROLL_STEP 10.0
-
-#ifndef BTN_STYLUS3
-#define BTN_STYLUS3 0x149 /* Linux 4.15 */
-#endif
-
-struct _MetaEventSource
-{
- GSource source;
-
- MetaSeatImpl *seat_impl;
- GPollFD event_poll_fd;
-};
-
-enum
-{
- PROP_0,
- PROP_SEAT,
- PROP_SEAT_ID,
- PROP_FLAGS,
- N_PROPS,
-};
-
-static GParamSpec *props[N_PROPS] = { NULL };
-
-enum
-{
- KBD_A11Y_FLAGS_CHANGED,
- KBD_A11Y_MODS_STATE_CHANGED,
- TOUCH_MODE,
- BELL,
- MODS_STATE_CHANGED,
- N_SIGNALS
-};
-
-static guint signals[N_SIGNALS] = { 0 };
-
-typedef struct _MetaSeatImplPrivate
-{
- GHashTable *device_files;
-} MetaSeatImplPrivate;
-
-static void meta_seat_impl_initable_iface_init (GInitableIface *iface);
-
-G_DEFINE_TYPE_WITH_CODE (MetaSeatImpl, meta_seat_impl, G_TYPE_OBJECT,
- G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE,
- meta_seat_impl_initable_iface_init)
- G_ADD_PRIVATE (MetaSeatImpl))
-
-static void process_events (MetaSeatImpl *seat_impl);
-void meta_seat_impl_constrain_pointer (MetaSeatImpl *seat_impl,
- ClutterInputDevice *core_pointer,
- uint64_t time_us,
- float x,
- float y,
- float *new_x,
- float *new_y);
-void meta_seat_impl_filter_relative_motion (MetaSeatImpl *seat_impl,
- ClutterInputDevice *device,
- float x,
- float y,
- float *dx,
- float *dy);
-void meta_seat_impl_clear_repeat_source (MetaSeatImpl *seat_impl);
-
-void
-meta_seat_impl_run_input_task (MetaSeatImpl *seat_impl,
- GTask *task,
- GSourceFunc dispatch_func)
-{
- GSource *source;
-
- source = g_idle_source_new ();
- g_source_set_priority (source, G_PRIORITY_HIGH);
- g_source_set_callback (source,
- dispatch_func,
- g_object_ref (task),
- g_object_unref);
- g_source_attach (source, seat_impl->input_context);
- g_source_unref (source);
-}
-
-void
-meta_seat_impl_sync_leds_in_impl (MetaSeatImpl *seat_impl)
-{
- GSList *iter;
- MetaInputDeviceNative *device_native;
- int caps_lock, num_lock, scroll_lock;
- enum libinput_led leds = 0;
-
- caps_lock = xkb_state_led_index_is_active (seat_impl->xkb,
- seat_impl->caps_lock_led);
- num_lock = xkb_state_led_index_is_active (seat_impl->xkb,
- seat_impl->num_lock_led);
- scroll_lock = xkb_state_led_index_is_active (seat_impl->xkb,
- seat_impl->scroll_lock_led);
-
- if (caps_lock)
- leds |= LIBINPUT_LED_CAPS_LOCK;
- if (num_lock)
- leds |= LIBINPUT_LED_NUM_LOCK;
- if (scroll_lock)
- leds |= LIBINPUT_LED_SCROLL_LOCK;
-
- for (iter = seat_impl->devices; iter; iter = iter->next)
- {
- device_native = iter->data;
- meta_input_device_native_update_leds_in_impl (device_native, leds);
- }
-}
-
-MetaTouchState *
-meta_seat_impl_lookup_touch_state_in_impl (MetaSeatImpl *seat_impl,
- int seat_slot)
-{
- if (!seat_impl->touch_states)
- return NULL;
-
- return g_hash_table_lookup (seat_impl->touch_states,
- GINT_TO_POINTER (seat_slot));
-}
-
-static void
-meta_touch_state_free (MetaTouchState *state)
-{
- g_free (state);
-}
-
-MetaTouchState *
-meta_seat_impl_acquire_touch_state_in_impl (MetaSeatImpl *seat_impl,
- int seat_slot)
-{
- MetaTouchState *touch_state;
-
- if (!seat_impl->touch_states)
- {
- seat_impl->touch_states =
- g_hash_table_new_full (NULL, NULL, NULL,
- (GDestroyNotify) meta_touch_state_free);
- }
-
- g_assert (!g_hash_table_contains (seat_impl->touch_states,
- GINT_TO_POINTER (seat_slot)));
-
- touch_state = g_new0 (MetaTouchState, 1);
- *touch_state = (MetaTouchState) {
- .seat_impl = seat_impl,
- .seat_slot = seat_slot,
- };
-
- g_hash_table_insert (seat_impl->touch_states, GINT_TO_POINTER (seat_slot),
- touch_state);
-
- return touch_state;
-}
-
-void
-meta_seat_impl_release_touch_state_in_impl (MetaSeatImpl *seat_impl,
- int seat_slot)
-{
- if (!seat_impl->touch_states)
- return;
- g_hash_table_remove (seat_impl->touch_states, GINT_TO_POINTER (seat_slot));
-}
-
-void
-meta_seat_impl_clear_repeat_source (MetaSeatImpl *seat_impl)
-{
- if (seat_impl->repeat_source)
- {
- g_source_destroy (seat_impl->repeat_source);
- g_clear_pointer (&seat_impl->repeat_source, g_source_unref);
- }
-
- g_clear_object (&seat_impl->repeat_device);
-}
-
-static void
-dispatch_libinput (MetaSeatImpl *seat_impl)
-{
- libinput_dispatch (seat_impl->libinput);
- process_events (seat_impl);
-}
-
-static gboolean
-keyboard_repeat (gpointer data)
-{
- MetaSeatImpl *seat_impl = data;
-
- /* There might be events queued in libinput that could cancel the
- repeat timer. */
- if (seat_impl->libinput)
- {
- dispatch_libinput (seat_impl);
- if (!seat_impl->repeat_source)
- return G_SOURCE_REMOVE;
- }
-
- g_return_val_if_fail (seat_impl->repeat_device != NULL, G_SOURCE_REMOVE);
-
- meta_seat_impl_notify_key_in_impl (seat_impl,
- seat_impl->repeat_device,
- g_source_get_time (seat_impl->repeat_source),
- seat_impl->repeat_key,
- AUTOREPEAT_VALUE,
- FALSE);
-
- return G_SOURCE_CONTINUE;
-}
-
-static void
-queue_event (MetaSeatImpl *seat_impl,
- ClutterEvent *event)
-{
- _clutter_event_push (event, FALSE);
-}
-
-static int
-update_button_count (MetaSeatImpl *seat_impl,
- uint32_t button,
- uint32_t state)
-{
- if (state)
- {
- return ++seat_impl->button_count[button];
- }
- else
- {
- /* Handle cases where we newer saw the initial pressed event. */
- if (seat_impl->button_count[button] == 0)
- {
- meta_topic (META_DEBUG_INPUT,
- "Counting release of key 0x%x and count is already 0",
- button);
- return 0;
- }
-
- return --seat_impl->button_count[button];
- }
-}
-
-void
-meta_seat_impl_queue_main_thread_idle (MetaSeatImpl *seat_impl,
- GSourceFunc func,
- gpointer user_data,
- GDestroyNotify destroy_notify)
-{
- GSource *source;
-
- source = g_idle_source_new ();
- g_source_set_priority (source, G_PRIORITY_HIGH);
- g_source_set_callback (source, func, user_data, destroy_notify);
-
- g_source_attach (source, seat_impl->main_context);
- g_source_unref (source);
-}
-
-typedef struct
-{
- MetaSeatImpl *seat_impl;
- guint signal_id;
- GArray *args;
-} MetaSeatSignalData;
-
-static gboolean
-emit_signal_in_main (MetaSeatSignalData *data)
-{
- g_signal_emitv ((GValue *) data->args->data,
- data->signal_id,
- 0, NULL);
-
- return G_SOURCE_REMOVE;
-}
-
-static void
-signal_data_free (MetaSeatSignalData *data)
-{
- g_array_unref (data->args);
- g_free (data);
-}
-
-static void
-emit_signal (MetaSeatImpl *seat_impl,
- guint signal_id,
- GValue *args,
- int n_args)
-{
- MetaSeatSignalData *emit_signal_data;
- GArray *array;
- GValue self = G_VALUE_INIT;
-
- g_value_init (&self, META_TYPE_SEAT_IMPL);
- g_value_set_object (&self, seat_impl);
-
- array = g_array_new (FALSE, FALSE, sizeof (GValue));
- g_array_append_val (array, self);
- if (args && n_args > 0)
- g_array_append_vals (array, args, n_args);
-
- emit_signal_data = g_new0 (MetaSeatSignalData, 1);
- emit_signal_data->seat_impl = seat_impl;
- emit_signal_data->signal_id = signal_id;
- emit_signal_data->args = array;
-
- meta_seat_impl_queue_main_thread_idle (seat_impl,
- (GSourceFunc) emit_signal_in_main,
- emit_signal_data,
- (GDestroyNotify) signal_data_free);
-}
-
-void
-meta_seat_impl_notify_key_in_impl (MetaSeatImpl *seat_impl,
- ClutterInputDevice *device,
- uint64_t time_us,
- uint32_t key,
- uint32_t state,
- gboolean update_keys)
-{
- ClutterEvent *event = NULL;
- enum xkb_state_component changed_state;
- uint32_t keycode;
-
- if (state != AUTOREPEAT_VALUE)
- {
- /* Drop any repeated button press (for example from virtual devices. */
- int count = update_button_count (seat_impl, key, state);
- if ((state && count > 1) ||
- (!state && count != 0))
- {
- meta_topic (META_DEBUG_INPUT,
- "Dropping repeated %s of key 0x%x, count %d, state %d",
- state ? "press" : "release", key, count, state);
- return;
- }
- }
-
- event = meta_key_event_new_from_evdev (device,
- seat_impl->core_keyboard,
- seat_impl->xkb,
- seat_impl->button_state,
- us2ms (time_us), key, state);
- event->key.evdev_code = key;
-
- keycode = meta_xkb_evdev_to_keycode (key);
-
- /* We must be careful and not pass multiple releases to xkb, otherwise it gets
- confused and locks the modifiers */
- if (state != AUTOREPEAT_VALUE)
- {
- changed_state = xkb_state_update_key (seat_impl->xkb, keycode,
- state ? XKB_KEY_DOWN : XKB_KEY_UP);
- }
- else
- {
- changed_state = 0;
- clutter_event_set_flags (event, CLUTTER_EVENT_FLAG_REPEATED);
- }
-
- if (!meta_input_device_native_process_kbd_a11y_event_in_impl (seat_impl->core_keyboard,
- event))
- queue_event (seat_impl, event);
- else
- clutter_event_free (event);
-
- if (update_keys && (changed_state & XKB_STATE_LEDS))
- {
- MetaInputDeviceNative *keyboard_native;
- gboolean numlock_active;
-
- meta_keymap_native_update_in_impl (seat_impl->keymap,
- seat_impl,
- seat_impl->xkb);
- meta_seat_impl_sync_leds_in_impl (seat_impl);
-
- numlock_active =
- xkb_state_mod_name_is_active (seat_impl->xkb, XKB_MOD_NAME_NUM,
- XKB_STATE_MODS_LATCHED |
- XKB_STATE_MODS_LOCKED);
- meta_input_settings_maybe_save_numlock_state (seat_impl->input_settings,
- numlock_active);
-
- keyboard_native = META_INPUT_DEVICE_NATIVE (seat_impl->core_keyboard);
- meta_input_device_native_a11y_maybe_notify_toggle_keys_in_impl (keyboard_native);
- }
-
- if (state == 0 || /* key release */
- !seat_impl->repeat ||
- !xkb_keymap_key_repeats (xkb_state_get_keymap (seat_impl->xkb),
- keycode))
- {
- seat_impl->repeat_count = 0;
- meta_seat_impl_clear_repeat_source (seat_impl);
- return;
- }
-
- if (state == 1) /* key press */
- seat_impl->repeat_count = 0;
-
- seat_impl->repeat_count += 1;
- seat_impl->repeat_key = key;
-
- switch (seat_impl->repeat_count)
- {
- case 1:
- case 2:
- {
- uint32_t interval;
-
- meta_seat_impl_clear_repeat_source (seat_impl);
- seat_impl->repeat_device = g_object_ref (device);
-
- if (seat_impl->repeat_count == 1)
- interval = seat_impl->repeat_delay;
- else
- interval = seat_impl->repeat_interval;
-
- seat_impl->repeat_source = g_timeout_source_new (interval);
- g_source_set_priority (seat_impl->repeat_source, CLUTTER_PRIORITY_EVENTS);
- g_source_set_callback (seat_impl->repeat_source,
- keyboard_repeat, seat_impl, NULL);
- g_source_attach (seat_impl->repeat_source, seat_impl->input_context);
- return;
- }
- default:
- return;
- }
-}
-
-static ClutterEvent *
-new_absolute_motion_event (MetaSeatImpl *seat_impl,
- ClutterInputDevice *input_device,
- uint64_t time_us,
- float x,
- float y,
- double *axes)
-{
- ClutterEvent *event;
-
- event = clutter_event_new (CLUTTER_MOTION);
-
- if (clutter_input_device_get_device_type (input_device) != CLUTTER_TABLET_DEVICE)
- {
- meta_seat_impl_constrain_pointer (seat_impl,
- seat_impl->core_pointer,
- time_us,
- seat_impl->pointer_x,
- seat_impl->pointer_y,
- &x, &y);
- }
- else
- {
- /* This may happen early at startup */
- if (seat_impl->viewports)
- {
- meta_input_device_native_translate_coordinates_in_impl (input_device,
- seat_impl->viewports,
- &x,
- &y);
- }
- }
-
- event->motion.time_us = time_us;
- event->motion.time = us2ms (time_us);
- meta_xkb_translate_state (event, seat_impl->xkb, seat_impl->button_state);
- event->motion.x = x;
- event->motion.y = y;
-
- event->motion.axes = axes;
- clutter_event_set_device (event, seat_impl->core_pointer);
- clutter_event_set_source_device (event, input_device);
-
- g_rw_lock_writer_lock (&seat_impl->state_lock);
-
- if (clutter_input_device_get_device_type (input_device) == CLUTTER_TABLET_DEVICE)
- {
- MetaInputDeviceNative *device_native =
- META_INPUT_DEVICE_NATIVE (input_device);
-
- clutter_event_set_device_tool (event, device_native->last_tool);
- clutter_event_set_device (event, input_device);
- meta_input_device_native_set_coords_in_impl (META_INPUT_DEVICE_NATIVE (input_device),
- x, y);
- }
- else
- {
- clutter_event_set_device (event, seat_impl->core_pointer);
- meta_input_device_native_set_coords_in_impl (META_INPUT_DEVICE_NATIVE (seat_impl->core_pointer),
- x, y);
- }
-
- if (clutter_input_device_get_device_type (input_device) != CLUTTER_TABLET_DEVICE)
- {
- seat_impl->pointer_x = x;
- seat_impl->pointer_y = y;
- }
-
- g_rw_lock_writer_unlock (&seat_impl->state_lock);
-
- return event;
-}
-
-void
-meta_seat_impl_notify_relative_motion_in_impl (MetaSeatImpl *seat_impl,
- ClutterInputDevice *input_device,
- uint64_t time_us,
- float dx,
- float dy,
- float dx_unaccel,
- float dy_unaccel)
-{
- float new_x, new_y;
- ClutterEvent *event;
-
- meta_seat_impl_filter_relative_motion (seat_impl,
- input_device,
- seat_impl->pointer_x,
- seat_impl->pointer_y,
- &dx,
- &dy);
-
- new_x = seat_impl->pointer_x + dx;
- new_y = seat_impl->pointer_y + dy;
- event = new_absolute_motion_event (seat_impl, input_device,
- time_us, new_x, new_y, NULL);
-
- event->motion.flags |= CLUTTER_EVENT_FLAG_RELATIVE_MOTION;
- event->motion.dx = dx;
- event->motion.dy = dy;
- event->motion.dx_unaccel = dx_unaccel;
- event->motion.dy_unaccel = dy_unaccel;
-
- queue_event (seat_impl, event);
-}
-
-void
-meta_seat_impl_notify_absolute_motion_in_impl (MetaSeatImpl *seat_impl,
- ClutterInputDevice *input_device,
- uint64_t time_us,
- float x,
- float y,
- double *axes)
-{
- ClutterEvent *event;
-
- event = new_absolute_motion_event (seat_impl, input_device, time_us, x, y, axes);
-
- queue_event (seat_impl, event);
-}
-
-void
-meta_seat_impl_notify_button_in_impl (MetaSeatImpl *seat_impl,
- ClutterInputDevice *input_device,
- uint64_t time_us,
- uint32_t button,
- uint32_t state)
-{
- MetaInputDeviceNative *device_native = (MetaInputDeviceNative *) input_device;
- ClutterEvent *event = NULL;
- int button_nr;
- static int maskmap[8] =
- {
- CLUTTER_BUTTON1_MASK, CLUTTER_BUTTON3_MASK, CLUTTER_BUTTON2_MASK,
- CLUTTER_BUTTON4_MASK, CLUTTER_BUTTON5_MASK, 0, 0, 0
- };
- int button_count;
-
- /* Drop any repeated button press (for example from virtual devices. */
- button_count = update_button_count (seat_impl, button, state);
- if ((state && button_count > 1) ||
- (!state && button_count != 0))
- {
- meta_topic (META_DEBUG_INPUT,
- "Dropping repeated %s of button 0x%x, count %d",
- state ? "press" : "release", button, button_count);
- return;
- }
-
- /* The evdev button numbers don't map sequentially to clutter button
- * numbers (the right and middle mouse buttons are in the opposite
- * order) so we'll map them directly with a switch statement */
- switch (button)
- {
- case BTN_LEFT:
- case BTN_TOUCH:
- button_nr = CLUTTER_BUTTON_PRIMARY;
- break;
-
- case BTN_RIGHT:
- case BTN_STYLUS:
- button_nr = CLUTTER_BUTTON_SECONDARY;
- break;
-
- case BTN_MIDDLE:
- case BTN_STYLUS2:
- button_nr = CLUTTER_BUTTON_MIDDLE;
- break;
-
- case 0x149: /* BTN_STYLUS3 */
- button_nr = 8;
- break;
-
- default:
- /* For compatibility reasons, all additional buttons go after the old 4-7 scroll ones */
- if (clutter_input_device_get_device_type (input_device) == CLUTTER_TABLET_DEVICE)
- button_nr = button - BTN_TOOL_PEN + 4;
- else
- button_nr = button - (BTN_LEFT - 1) + 4;
- break;
- }
-
- if (button_nr < 1 || button_nr > 12)
- {
- g_warning ("Unhandled button event 0x%x", button);
- return;
- }
-
- if (state)
- event = clutter_event_new (CLUTTER_BUTTON_PRESS);
- else
- event = clutter_event_new (CLUTTER_BUTTON_RELEASE);
-
- if (button_nr < G_N_ELEMENTS (maskmap))
- {
- /* Update the modifiers */
- if (state)
- seat_impl->button_state |= maskmap[button_nr - 1];
- else
- seat_impl->button_state &= ~maskmap[button_nr - 1];
- }
-
- event->button.time = us2ms (time_us);
- meta_xkb_translate_state (event, seat_impl->xkb, seat_impl->button_state);
- event->button.button = button_nr;
-
- if (clutter_input_device_get_device_type (input_device) == CLUTTER_TABLET_DEVICE)
- {
- meta_input_device_native_get_coords_in_impl (device_native,
- &event->button.x,
- &event->button.y);
- }
- else
- {
- meta_input_device_native_get_coords_in_impl (META_INPUT_DEVICE_NATIVE (seat_impl->core_pointer),
- &event->button.x,
- &event->button.y);
- }
-
- clutter_event_set_device (event, seat_impl->core_pointer);
- clutter_event_set_source_device (event, input_device);
-
- if (device_native->last_tool)
- {
- /* Apply the button event code as per the tool mapping */
- uint32_t mapped_button;
-
- mapped_button = meta_input_device_tool_native_get_button_code_in_impl (device_native->last_tool,
- button_nr);
- if (mapped_button != 0)
- button = mapped_button;
- }
-
- event->button.evdev_code = button;
-
- if (clutter_input_device_get_device_type (input_device) == CLUTTER_TABLET_DEVICE)
- {
- clutter_event_set_device_tool (event, device_native->last_tool);
- clutter_event_set_device (event, input_device);
- }
- else
- {
- clutter_event_set_device (event, seat_impl->core_pointer);
- }
-
- queue_event (seat_impl, event);
-}
-
-static MetaSeatImpl *
-seat_impl_from_device (ClutterInputDevice *device)
-{
- MetaInputDeviceNative *device_native = META_INPUT_DEVICE_NATIVE (device);
-
- return meta_input_device_native_get_seat_impl (device_native);
-}
-
-static void
-notify_scroll (ClutterInputDevice *input_device,
- uint64_t time_us,
- double dx,
- double dy,
- ClutterScrollSource scroll_source,
- ClutterScrollFinishFlags flags,
- gboolean emulated)
-{
- MetaSeatImpl *seat_impl;
- ClutterEvent *event = NULL;
- double scroll_factor;
-
- seat_impl = seat_impl_from_device (input_device);
-
- event = clutter_event_new (CLUTTER_SCROLL);
-
- event->scroll.time = us2ms (time_us);
- meta_xkb_translate_state (event, seat_impl->xkb, seat_impl->button_state);
-
- /* libinput pointer axis events are in pointer motion coordinate space.
- * To convert to Xi2 discrete step coordinate space, multiply the factor
- * 1/10. */
- event->scroll.direction = CLUTTER_SCROLL_SMOOTH;
- scroll_factor = 1.0 / DISCRETE_SCROLL_STEP;
- clutter_event_set_scroll_delta (event,
- scroll_factor * dx,
- scroll_factor * dy);
-
- event->scroll.x = seat_impl->pointer_x;
- event->scroll.y = seat_impl->pointer_y;
- clutter_event_set_device (event, seat_impl->core_pointer);
- clutter_event_set_source_device (event, input_device);
- event->scroll.scroll_source = scroll_source;
- event->scroll.finish_flags = flags;
-
- _clutter_event_set_pointer_emulated (event, emulated);
-
- queue_event (seat_impl, event);
-}
-
-static void
-notify_discrete_scroll (ClutterInputDevice *input_device,
- uint64_t time_us,
- ClutterScrollDirection direction,
- ClutterScrollSource scroll_source,
- gboolean emulated)
-{
- MetaSeatImpl *seat_impl;
- ClutterEvent *event = NULL;
-
- if (direction == CLUTTER_SCROLL_SMOOTH)
- return;
-
- seat_impl = seat_impl_from_device (input_device);
-
- event = clutter_event_new (CLUTTER_SCROLL);
-
- event->scroll.time = us2ms (time_us);
- meta_xkb_translate_state (event, seat_impl->xkb, seat_impl->button_state);
-
- event->scroll.direction = direction;
-
- event->scroll.x = seat_impl->pointer_x;
- event->scroll.y = seat_impl->pointer_y;
- clutter_event_set_device (event, seat_impl->core_pointer);
- clutter_event_set_source_device (event, input_device);
- event->scroll.scroll_source = scroll_source;
-
- _clutter_event_set_pointer_emulated (event, emulated);
-
- queue_event (seat_impl, event);
-}
-
-static void
-check_notify_discrete_scroll (MetaSeatImpl *seat_impl,
- ClutterInputDevice *device,
- uint64_t time_us,
- ClutterScrollSource scroll_source)
-{
- int i, n_xscrolls, n_yscrolls;
-
- n_xscrolls = floor ((fabs (seat_impl->accum_scroll_dx) + DBL_EPSILON) /
- DISCRETE_SCROLL_STEP);
- n_yscrolls = floor ((fabs (seat_impl->accum_scroll_dy) + DBL_EPSILON) /
- DISCRETE_SCROLL_STEP);
-
- for (i = 0; i < n_xscrolls; i++)
- {
- notify_discrete_scroll (device, time_us,
- seat_impl->accum_scroll_dx > 0 ?
- CLUTTER_SCROLL_RIGHT : CLUTTER_SCROLL_LEFT,
- scroll_source, TRUE);
- }
-
- for (i = 0; i < n_yscrolls; i++)
- {
- notify_discrete_scroll (device, time_us,
- seat_impl->accum_scroll_dy > 0 ?
- CLUTTER_SCROLL_DOWN : CLUTTER_SCROLL_UP,
- scroll_source, TRUE);
- }
-
- seat_impl->accum_scroll_dx =
- fmodf (seat_impl->accum_scroll_dx, DISCRETE_SCROLL_STEP);
- seat_impl->accum_scroll_dy =
- fmodf (seat_impl->accum_scroll_dy, DISCRETE_SCROLL_STEP);
-}
-
-void
-meta_seat_impl_notify_scroll_continuous_in_impl (MetaSeatImpl *seat_impl,
- ClutterInputDevice *input_device,
- uint64_t time_us,
- double dx,
- double dy,
- ClutterScrollSource scroll_source,
- ClutterScrollFinishFlags finish_flags)
-{
- if (finish_flags & CLUTTER_SCROLL_FINISHED_HORIZONTAL)
- seat_impl->accum_scroll_dx = 0;
- else
- seat_impl->accum_scroll_dx += dx;
-
- if (finish_flags & CLUTTER_SCROLL_FINISHED_VERTICAL)
- seat_impl->accum_scroll_dy = 0;
- else
- seat_impl->accum_scroll_dy += dy;
-
- notify_scroll (input_device, time_us, dx, dy, scroll_source,
- finish_flags, FALSE);
- check_notify_discrete_scroll (seat_impl, input_device, time_us, scroll_source);
-}
-
-static ClutterScrollDirection
-discrete_to_direction (double discrete_dx,
- double discrete_dy)
-{
- if (discrete_dx > 0)
- return CLUTTER_SCROLL_RIGHT;
- else if (discrete_dx < 0)
- return CLUTTER_SCROLL_LEFT;
- else if (discrete_dy > 0)
- return CLUTTER_SCROLL_DOWN;
- else if (discrete_dy < 0)
- return CLUTTER_SCROLL_UP;
- else
- g_assert_not_reached ();
- return 0;
-}
-
-void
-meta_seat_impl_notify_discrete_scroll_in_impl (MetaSeatImpl *seat_impl,
- ClutterInputDevice *input_device,
- uint64_t time_us,
- double discrete_dx,
- double discrete_dy,
- ClutterScrollSource scroll_source)
-{
- notify_scroll (input_device, time_us,
- discrete_dx * DISCRETE_SCROLL_STEP,
- discrete_dy * DISCRETE_SCROLL_STEP,
- scroll_source, CLUTTER_SCROLL_FINISHED_NONE,
- TRUE);
- notify_discrete_scroll (input_device, time_us,
- discrete_to_direction (discrete_dx, discrete_dy),
- scroll_source, FALSE);
-
-}
-
-void
-meta_seat_impl_notify_touch_event_in_impl (MetaSeatImpl *seat_impl,
- ClutterInputDevice *input_device,
- ClutterEventType evtype,
- uint64_t time_us,
- int slot,
- double x,
- double y)
-{
- ClutterEvent *event = NULL;
-
- event = clutter_event_new (evtype);
-
- event->touch.time = us2ms (time_us);
- event->touch.x = x;
- event->touch.y = y;
- meta_input_device_native_translate_coordinates_in_impl (input_device,
- seat_impl->viewports,
- &event->touch.x,
- &event->touch.y);
-
- /* "NULL" sequences are special cased in clutter */
- event->touch.sequence = GINT_TO_POINTER (MAX (1, slot + 1));
- meta_xkb_translate_state (event, seat_impl->xkb, seat_impl->button_state);
-
- if (evtype == CLUTTER_TOUCH_BEGIN ||
- evtype == CLUTTER_TOUCH_UPDATE)
- event->touch.modifier_state |= CLUTTER_BUTTON1_MASK;
-
- clutter_event_set_device (event, seat_impl->core_pointer);
- clutter_event_set_source_device (event, input_device);
-
- queue_event (seat_impl, event);
-}
-
-/*
- * MetaEventSource for reading input devices
- */
-
-static gboolean
-meta_event_prepare (GSource *g_source,
- int *timeout_ms)
-{
- MetaEventSource *source = (MetaEventSource *) g_source;
- MetaSeatImpl *seat_impl = source->seat_impl;
-
- *timeout_ms = -1;
-
- switch (libinput_next_event_type (seat_impl->libinput))
- {
- case LIBINPUT_EVENT_NONE:
- return FALSE;
- default:
- return TRUE;
- }
-}
-
-static gboolean
-meta_event_check (GSource *source)
-{
- MetaEventSource *event_source = (MetaEventSource *) source;
- gboolean retval;
-
- retval = !!(event_source->event_poll_fd.revents & G_IO_IN);
-
- return retval;
-}
-
-static void
-constrain_to_barriers (MetaSeatImpl *seat_impl,
- ClutterInputDevice *device,
- uint32_t time,
- float *new_x,
- float *new_y)
-{
- meta_barrier_manager_native_process_in_impl (seat_impl->barrier_manager,
- device,
- time,
- new_x, new_y);
-}
-
-/*
- * The pointer constrain code is mostly a rip-off of the XRandR code from Xorg.
- * (from xserver/randr/rrcrtc.c, RRConstrainCursorHarder)
- *
- * Copyright © 2006 Keith Packard
- * Copyright 2010 Red Hat, Inc
- *
- */
-
-static void
-constrain_all_screen_monitors (ClutterInputDevice *device,
- MetaViewportInfo *viewports,
- float *x,
- float *y)
-{
- float cx, cy;
- int i, n_views;
-
- meta_input_device_native_get_coords_in_impl (META_INPUT_DEVICE_NATIVE (device),
- &cx, &cy);
-
- /* if we're trying to escape, clamp to the CRTC we're coming from */
-
- n_views = meta_viewport_info_get_num_views (viewports);
-
- for (i = 0; i < n_views; i++)
- {
- int left, right, top, bottom;
- cairo_rectangle_int_t rect;
-
- meta_viewport_info_get_view_info (viewports, i, &rect, NULL);
-
- left = rect.x;
- right = left + rect.width;
- top = rect.y;
- bottom = top + rect.height;
-
- if ((cx >= left) && (cx < right) && (cy >= top) && (cy < bottom))
- {
- if (*x < left)
- *x = left;
- if (*x >= right)
- *x = right - 1;
- if (*y < top)
- *y = top;
- if (*y >= bottom)
- *y = bottom - 1;
-
- return;
- }
- }
-}
-
-void
-meta_seat_impl_constrain_pointer (MetaSeatImpl *seat_impl,
- ClutterInputDevice *core_pointer,
- uint64_t time_us,
- float x,
- float y,
- float *new_x,
- float *new_y)
-{
- /* Constrain to barriers */
- constrain_to_barriers (seat_impl, core_pointer,
- us2ms (time_us),
- new_x, new_y);
-
- /* Bar to constraints */
- if (seat_impl->pointer_constraint)
- {
- meta_pointer_constraint_impl_constrain (seat_impl->pointer_constraint,
- core_pointer,
- us2ms (time_us),
- x, y,
- new_x, new_y);
- }
-
- if (seat_impl->viewports)
- {
- /* if we're moving inside a monitor, we're fine */
- if (meta_viewport_info_get_view_at (seat_impl->viewports,
- *new_x, *new_y) >= 0)
- return;
-
- /* if we're trying to escape, clamp to the CRTC we're coming from */
- constrain_all_screen_monitors (core_pointer, seat_impl->viewports,
- new_x, new_y);
- }
-}
-
-static void
-relative_motion_across_outputs (MetaViewportInfo *viewports,
- int view,
- float cur_x,
- float cur_y,
- float *dx_inout,
- float *dy_inout)
-{
- int cur_view = view;
- float x = cur_x, y = cur_y;
- float target_x = cur_x, target_y = cur_y;
- float dx = *dx_inout, dy = *dy_inout;
- MetaDisplayDirection direction = -1;
-
- while (cur_view >= 0)
- {
- MetaLine2 left, right, top, bottom, motion;
- MetaVector2 intersection;
- cairo_rectangle_int_t rect;
- float scale;
-
- meta_viewport_info_get_view_info (viewports, cur_view, &rect, &scale);
-
- motion = (MetaLine2) {
- .a = { x, y },
- .b = { x + (dx * scale), y + (dy * scale) }
- };
- left = (MetaLine2) {
- { rect.x, rect.y },
- { rect.x, rect.y + rect.height }
- };
- right = (MetaLine2) {
- { rect.x + rect.width, rect.y },
- { rect.x + rect.width, rect.y + rect.height }
- };
- top = (MetaLine2) {
- { rect.x, rect.y },
- { rect.x + rect.width, rect.y }
- };
- bottom = (MetaLine2) {
- { rect.x, rect.y + rect.height },
- { rect.x + rect.width, rect.y + rect.height }
- };
-
- target_x = motion.b.x;
- target_y = motion.b.y;
-
- if (direction != META_DISPLAY_RIGHT &&
- meta_line2_intersects_with (&motion, &left, &intersection))
- direction = META_DISPLAY_LEFT;
- else if (direction != META_DISPLAY_LEFT &&
- meta_line2_intersects_with (&motion, &right, &intersection))
- direction = META_DISPLAY_RIGHT;
- else if (direction != META_DISPLAY_DOWN &&
- meta_line2_intersects_with (&motion, &top, &intersection))
- direction = META_DISPLAY_UP;
- else if (direction != META_DISPLAY_UP &&
- meta_line2_intersects_with (&motion, &bottom, &intersection))
- direction = META_DISPLAY_DOWN;
- else
- /* We reached the dest logical monitor */
- break;
-
- x = intersection.x;
- y = intersection.y;
- dx -= intersection.x - motion.a.x;
- dy -= intersection.y - motion.a.y;
-
- cur_view = meta_viewport_info_get_neighbor (viewports, cur_view,
- direction);
- }
-
- *dx_inout = target_x - cur_x;
- *dy_inout = target_y - cur_y;
-}
-
-void
-meta_seat_impl_filter_relative_motion (MetaSeatImpl *seat_impl,
- ClutterInputDevice *device,
- float x,
- float y,
- float *dx,
- float *dy)
-{
- int view, dest_view;
- float new_dx, new_dy, scale;
-
- if (!seat_impl->viewports)
- return;
- if (meta_viewport_info_is_views_scaled (seat_impl->viewports))
- return;
-
- view = meta_viewport_info_get_view_at (seat_impl->viewports, x, y);
- if (view < 0)
- return;
-
- meta_viewport_info_get_view_info (seat_impl->viewports, view, NULL, &scale);
- new_dx = (*dx) * scale;
- new_dy = (*dy) * scale;
-
- dest_view = meta_viewport_info_get_view_at (seat_impl->viewports,
- x + new_dx,
- y + new_dy);
- if (dest_view >= 0 && dest_view != view)
- {
- /* If we are crossing monitors, attempt to bisect the distance on each
- * axis and apply the relative scale for each of them.
- */
- new_dx = *dx;
- new_dy = *dy;
- relative_motion_across_outputs (seat_impl->viewports, view,
- x, y, &new_dx, &new_dy);
- }
-
- *dx = new_dx;
- *dy = new_dy;
-}
-
-static void
-notify_absolute_motion_in_impl (ClutterInputDevice *input_device,
- uint64_t time_us,
- float x,
- float y,
- double *axes)
-{
- MetaSeatImpl *seat_impl;
- ClutterEvent *event;
-
- seat_impl = seat_impl_from_device (input_device);
- event = new_absolute_motion_event (seat_impl, input_device, time_us, x, y, axes);
-
- queue_event (seat_impl, event);
-}
-
-static void
-notify_relative_tool_motion_in_impl (ClutterInputDevice *input_device,
- uint64_t time_us,
- float dx,
- float dy,
- double *axes)
-{
- MetaInputDeviceNative *device_native;
- ClutterEvent *event;
- MetaSeatImpl *seat_impl;
- float x, y;
-
- device_native = META_INPUT_DEVICE_NATIVE (input_device);
- seat_impl = seat_impl_from_device (input_device);
- x = device_native->pointer_x + dx;
- y = device_native->pointer_y + dy;
-
- meta_seat_impl_filter_relative_motion (seat_impl,
- input_device,
- seat_impl->pointer_x,
- seat_impl->pointer_y,
- &dx,
- &dy);
-
- event = new_absolute_motion_event (seat_impl, input_device, time_us,
- x, y, axes);
-
- event->motion.flags |= CLUTTER_EVENT_FLAG_RELATIVE_MOTION;
- event->motion.dx = dx;
- event->motion.dy = dy;
-
- queue_event (seat_impl, event);
-}
-
-static void
-notify_pinch_gesture_event (ClutterInputDevice *input_device,
- ClutterTouchpadGesturePhase phase,
- uint64_t time_us,
- double dx,
- double dy,
- double dx_unaccel,
- double dy_unaccel,
- double angle_delta,
- double scale,
- uint32_t n_fingers)
-{
- MetaSeatImpl *seat_impl;
- ClutterEvent *event = NULL;
-
- seat_impl = seat_impl_from_device (input_device);
-
- event = clutter_event_new (CLUTTER_TOUCHPAD_PINCH);
-
- meta_input_device_native_get_coords_in_impl (META_INPUT_DEVICE_NATIVE (seat_impl->core_pointer),
- &event->touchpad_pinch.x,
- &event->touchpad_pinch.y);
-
- event->touchpad_pinch.phase = phase;
- event->touchpad_pinch.time = us2ms (time_us);
- event->touchpad_pinch.dx = dx;
- event->touchpad_pinch.dy = dy;
- event->touchpad_pinch.dx_unaccel = dx_unaccel;
- event->touchpad_pinch.dy_unaccel = dy_unaccel;
- event->touchpad_pinch.angle_delta = angle_delta;
- event->touchpad_pinch.scale = scale;
- event->touchpad_pinch.n_fingers = n_fingers;
-
- meta_xkb_translate_state (event, seat_impl->xkb, seat_impl->button_state);
-
- clutter_event_set_device (event, seat_impl->core_pointer);
- clutter_event_set_source_device (event, input_device);
-
- queue_event (seat_impl, event);
-}
-
-static void
-notify_swipe_gesture_event (ClutterInputDevice *input_device,
- ClutterTouchpadGesturePhase phase,
- uint64_t time_us,
- uint32_t n_fingers,
- double dx,
- double dy,
- double dx_unaccel,
- double dy_unaccel)
-{
- MetaSeatImpl *seat_impl;
- ClutterEvent *event = NULL;
-
- seat_impl = seat_impl_from_device (input_device);
-
- event = clutter_event_new (CLUTTER_TOUCHPAD_SWIPE);
-
- event->touchpad_swipe.phase = phase;
- event->touchpad_swipe.time = us2ms (time_us);
-
- meta_input_device_native_get_coords_in_impl (META_INPUT_DEVICE_NATIVE (seat_impl->core_pointer),
- &event->touchpad_swipe.x,
- &event->touchpad_swipe.y);
- event->touchpad_swipe.dx = dx;
- event->touchpad_swipe.dy = dy;
- event->touchpad_swipe.dx_unaccel = dx_unaccel;
- event->touchpad_swipe.dy_unaccel = dy_unaccel;
- event->touchpad_swipe.n_fingers = n_fingers;
-
- meta_xkb_translate_state (event, seat_impl->xkb, seat_impl->button_state);
-
- clutter_event_set_device (event, seat_impl->core_pointer);
- clutter_event_set_source_device (event, input_device);
-
- queue_event (seat_impl, event);
-}
-
-static void
-notify_proximity (ClutterInputDevice *input_device,
- uint64_t time_us,
- gboolean in)
-{
- MetaInputDeviceNative *device_native;
- MetaSeatImpl *seat_impl;
- ClutterEvent *event = NULL;
-
- device_native = META_INPUT_DEVICE_NATIVE (input_device);
- seat_impl = seat_impl_from_device (input_device);
-
- if (in)
- event = clutter_event_new (CLUTTER_PROXIMITY_IN);
- else
- event = clutter_event_new (CLUTTER_PROXIMITY_OUT);
-
- event->proximity.time = us2ms (time_us);
- clutter_event_set_device_tool (event, device_native->last_tool);
- clutter_event_set_device (event, seat_impl->core_pointer);
- clutter_event_set_source_device (event, input_device);
-
- queue_event (seat_impl, event);
-}
-
-static void
-notify_pad_button (ClutterInputDevice *input_device,
- uint64_t time_us,
- uint32_t button,
- uint32_t mode_group,
- uint32_t mode,
- uint32_t pressed)
-{
- MetaSeatImpl *seat_impl;
- ClutterEvent *event;
-
- seat_impl = seat_impl_from_device (input_device);
-
- if (pressed)
- event = clutter_event_new (CLUTTER_PAD_BUTTON_PRESS);
- else
- event = clutter_event_new (CLUTTER_PAD_BUTTON_RELEASE);
-
- event->pad_button.button = button;
- event->pad_button.group = mode_group;
- event->pad_button.mode = mode;
- clutter_event_set_device (event, input_device);
- clutter_event_set_source_device (event, input_device);
- clutter_event_set_time (event, us2ms (time_us));
-
- queue_event (seat_impl, event);
-}
-
-static void
-notify_pad_strip (ClutterInputDevice *input_device,
- uint64_t time_us,
- uint32_t strip_number,
- uint32_t strip_source,
- uint32_t mode_group,
- uint32_t mode,
- double value)
-{
- ClutterInputDevicePadSource source;
- MetaSeatImpl *seat_impl;
- ClutterEvent *event;
-
- seat_impl = seat_impl_from_device (input_device);
-
- if (strip_source == LIBINPUT_TABLET_PAD_STRIP_SOURCE_FINGER)
- source = CLUTTER_INPUT_DEVICE_PAD_SOURCE_FINGER;
- else
- source = CLUTTER_INPUT_DEVICE_PAD_SOURCE_UNKNOWN;
-
- event = clutter_event_new (CLUTTER_PAD_STRIP);
- event->pad_strip.strip_source = source;
- event->pad_strip.strip_number = strip_number;
- event->pad_strip.value = value;
- event->pad_strip.group = mode_group;
- event->pad_strip.mode = mode;
- clutter_event_set_device (event, input_device);
- clutter_event_set_source_device (event, input_device);
- clutter_event_set_time (event, us2ms (time_us));
-
- queue_event (seat_impl, event);
-}
-
-static void
-notify_pad_ring (ClutterInputDevice *input_device,
- uint64_t time_us,
- uint32_t ring_number,
- uint32_t ring_source,
- uint32_t mode_group,
- uint32_t mode,
- double angle)
-{
- ClutterInputDevicePadSource source;
- MetaSeatImpl *seat_impl;
- ClutterEvent *event;
-
- seat_impl = seat_impl_from_device (input_device);
-
- if (ring_source == LIBINPUT_TABLET_PAD_RING_SOURCE_FINGER)
- source = CLUTTER_INPUT_DEVICE_PAD_SOURCE_FINGER;
- else
- source = CLUTTER_INPUT_DEVICE_PAD_SOURCE_UNKNOWN;
-
- event = clutter_event_new (CLUTTER_PAD_RING);
- event->pad_ring.ring_source = source;
- event->pad_ring.ring_number = ring_number;
- event->pad_ring.angle = angle;
- event->pad_ring.group = mode_group;
- event->pad_ring.mode = mode;
- clutter_event_set_device (event, input_device);
- clutter_event_set_source_device (event, input_device);
- clutter_event_set_time (event, us2ms (time_us));
-
- queue_event (seat_impl, event);
-}
-
-static gboolean
-meta_event_dispatch (GSource *g_source,
- GSourceFunc callback,
- gpointer user_data)
-{
- MetaEventSource *source = (MetaEventSource *) g_source;
- MetaSeatImpl *seat_impl;
-
- seat_impl = source->seat_impl;
-
- dispatch_libinput (seat_impl);
-
- return TRUE;
-}
-
-static GSourceFuncs event_funcs = {
- meta_event_prepare,
- meta_event_check,
- meta_event_dispatch,
- NULL
-};
-
-static MetaEventSource *
-meta_event_source_new (MetaSeatImpl *seat_impl)
-{
- GSource *source;
- MetaEventSource *event_source;
- int fd;
-
- source = g_source_new (&event_funcs, sizeof (MetaEventSource));
- event_source = (MetaEventSource *) source;
-
- /* setup the source */
- event_source->seat_impl = seat_impl;
-
- fd = libinput_get_fd (seat_impl->libinput);
- event_source->event_poll_fd.fd = fd;
- event_source->event_poll_fd.events = G_IO_IN;
-
- /* and finally configure and attach the GSource */
- g_source_set_priority (source, CLUTTER_PRIORITY_EVENTS);
- g_source_add_poll (source, &event_source->event_poll_fd);
- g_source_set_can_recurse (source, TRUE);
- g_source_attach (source, seat_impl->input_context);
-
- return event_source;
-}
-
-static void
-meta_event_source_free (MetaEventSource *source)
-{
- GSource *g_source = (GSource *) source;
-
- /* ignore the return value of close, it's not like we can do something
- * about it */
- close (source->event_poll_fd.fd);
-
- g_source_destroy (g_source);
- g_source_unref (g_source);
-}
-
-static gboolean
-has_touchscreen (MetaSeatImpl *seat_impl)
-{
- GSList *l;
-
- for (l = seat_impl->devices; l; l = l->next)
- {
- ClutterInputDeviceType device_type;
-
- device_type = clutter_input_device_get_device_type (l->data);
-
- if (device_type == CLUTTER_TOUCHSCREEN_DEVICE)
- return TRUE;
- }
-
- return FALSE;
-}
-
-static inline gboolean
-device_type_is_pointer (ClutterInputDeviceType device_type)
-{
- return device_type == CLUTTER_POINTER_DEVICE ||
- device_type == CLUTTER_TOUCHPAD_DEVICE;
-}
-
-static gboolean
-has_pointer (MetaSeatImpl *seat_impl)
-{
- GSList *l;
-
- for (l = seat_impl->devices; l; l = l->next)
- {
- ClutterInputDeviceType device_type;
-
- device_type = clutter_input_device_get_device_type (l->data);
- if (device_type_is_pointer (device_type))
- return TRUE;
- }
-
- return FALSE;
-}
-
-static gboolean
-device_is_tablet_switch (MetaInputDeviceNative *device_native)
-{
- if (libinput_device_has_capability (device_native->libinput_device,
- LIBINPUT_DEVICE_CAP_SWITCH) &&
- libinput_device_switch_has_switch (device_native->libinput_device,
- LIBINPUT_SWITCH_TABLET_MODE))
- return TRUE;
-
- return FALSE;
-}
-
-static gboolean
-has_tablet_switch (MetaSeatImpl *seat_impl)
-{
- GSList *l;
-
- for (l = seat_impl->devices; l; l = l->next)
- {
- MetaInputDeviceNative *device_native = META_INPUT_DEVICE_NATIVE (l->data);
-
- if (device_is_tablet_switch (device_native))
- return TRUE;
- }
-
- return FALSE;
-}
-
-static void
-update_touch_mode (MetaSeatImpl *seat_impl)
-{
- gboolean touch_mode;
-
- /* No touch mode if we don't have a touchscreen, easy */
- if (!seat_impl->has_touchscreen)
- touch_mode = FALSE;
- /* If we have a tablet mode switch, honor it being unset */
- else if (seat_impl->has_tablet_switch && !seat_impl->tablet_mode_switch_state)
- touch_mode = FALSE;
- /* If tablet mode is enabled, go for it */
- else if (seat_impl->has_tablet_switch && seat_impl->tablet_mode_switch_state)
- touch_mode = TRUE;
- /* If there is no tablet mode switch (eg. kiosk machines),
- * assume touch-mode is mutually exclusive with pointers.
- */
- else
- touch_mode = !seat_impl->has_pointer;
-
- if (seat_impl->touch_mode != touch_mode)
- {
- GValue value = G_VALUE_INIT;
-
- g_value_init (&value, G_TYPE_BOOLEAN);
- g_value_set_boolean (&value, touch_mode);
- seat_impl->touch_mode = touch_mode;
- emit_signal (seat_impl, signals[TOUCH_MODE], &value, 1);
- g_value_unset (&value);
- }
-}
-
-static ClutterInputDevice *
-evdev_add_device (MetaSeatImpl *seat_impl,
- struct libinput_device *libinput_device)
-{
- ClutterInputDeviceType type;
- ClutterInputDevice *device;
- gboolean is_touchscreen, is_tablet_switch, is_pointer;
-
- device = meta_input_device_native_new_in_impl (seat_impl, libinput_device);
-
- seat_impl->devices = g_slist_prepend (seat_impl->devices, device);
- meta_seat_impl_sync_leds_in_impl (seat_impl);
-
- /* Clutter assumes that device types are exclusive in the
- * ClutterInputDevice API */
- type = meta_input_device_native_determine_type_in_impl (libinput_device);
-
- is_touchscreen = type == CLUTTER_TOUCHSCREEN_DEVICE;
- is_tablet_switch =
- device_is_tablet_switch (META_INPUT_DEVICE_NATIVE (device));
- is_pointer = device_type_is_pointer (type);
-
- seat_impl->has_touchscreen |= is_touchscreen;
- seat_impl->has_tablet_switch |= is_tablet_switch;
- seat_impl->has_pointer |= is_pointer;
-
- if (is_touchscreen || is_tablet_switch || is_pointer)
- update_touch_mode (seat_impl);
-
- return device;
-}
-
-static void
-evdev_remove_device (MetaSeatImpl *seat_impl,
- MetaInputDeviceNative *device_native)
-{
- ClutterInputDevice *device;
- ClutterInputDeviceType device_type;
- gboolean is_touchscreen, is_tablet_switch, is_pointer;
-
- device = CLUTTER_INPUT_DEVICE (device_native);
- seat_impl->devices = g_slist_remove (seat_impl->devices, device);
-
- device_type = clutter_input_device_get_device_type (device);
-
- is_touchscreen = device_type == CLUTTER_TOUCHSCREEN_DEVICE;
- is_tablet_switch = device_is_tablet_switch (device_native);
- is_pointer = device_type_is_pointer (device_type);
-
- if (is_touchscreen)
- seat_impl->has_touchscreen = has_touchscreen (seat_impl);
- if (is_tablet_switch)
- seat_impl->has_tablet_switch = has_tablet_switch (seat_impl);
- if (is_pointer)
- seat_impl->has_pointer = has_pointer (seat_impl);
-
- if (is_touchscreen || is_tablet_switch || is_pointer)
- update_touch_mode (seat_impl);
-
- if (seat_impl->repeat_source && seat_impl->repeat_device == device)
- meta_seat_impl_clear_repeat_source (seat_impl);
-
- meta_input_device_native_detach_libinput_in_impl (device_native);
-
- g_object_unref (device);
-}
-
-static gboolean
-process_base_event (MetaSeatImpl *seat_impl,
- struct libinput_event *event)
-{
- ClutterInputDevice *device;
- ClutterEvent *device_event = NULL;
- struct libinput_device *libinput_device;
- MetaInputSettings *input_settings;
-
- input_settings = seat_impl->input_settings;
-
- switch (libinput_event_get_type (event))
- {
- case LIBINPUT_EVENT_DEVICE_ADDED:
- libinput_device = libinput_event_get_device (event);
-
- device = evdev_add_device (seat_impl, libinput_device);
- device_event = clutter_event_new (CLUTTER_DEVICE_ADDED);
- clutter_event_set_device (device_event, device);
- meta_input_settings_add_device (input_settings, device);
- break;
-
- case LIBINPUT_EVENT_DEVICE_REMOVED:
- libinput_device = libinput_event_get_device (event);
-
- device = libinput_device_get_user_data (libinput_device);
- device_event = clutter_event_new (CLUTTER_DEVICE_REMOVED);
- clutter_event_set_device (device_event, device);
- meta_input_settings_remove_device (input_settings, device);
- evdev_remove_device (seat_impl,
- META_INPUT_DEVICE_NATIVE (device));
- break;
-
- default:
- break;
- }
-
- if (device_event)
- {
- queue_event (seat_impl, device_event);
- return TRUE;
- }
-
- return FALSE;
-}
-
-static ClutterScrollSource
-translate_scroll_source (enum libinput_pointer_axis_source source)
-{
- switch (source)
- {
- case LIBINPUT_POINTER_AXIS_SOURCE_WHEEL:
- return CLUTTER_SCROLL_SOURCE_WHEEL;
- case LIBINPUT_POINTER_AXIS_SOURCE_FINGER:
- return CLUTTER_SCROLL_SOURCE_FINGER;
- case LIBINPUT_POINTER_AXIS_SOURCE_CONTINUOUS:
- return CLUTTER_SCROLL_SOURCE_CONTINUOUS;
- default:
- return CLUTTER_SCROLL_SOURCE_UNKNOWN;
- }
-}
-
-static ClutterInputDeviceToolType
-translate_tool_type (struct libinput_tablet_tool *libinput_tool)
-{
- enum libinput_tablet_tool_type tool;
-
- tool = libinput_tablet_tool_get_type (libinput_tool);
-
- switch (tool)
- {
- case LIBINPUT_TABLET_TOOL_TYPE_PEN:
- return CLUTTER_INPUT_DEVICE_TOOL_PEN;
- case LIBINPUT_TABLET_TOOL_TYPE_ERASER:
- return CLUTTER_INPUT_DEVICE_TOOL_ERASER;
- case LIBINPUT_TABLET_TOOL_TYPE_BRUSH:
- return CLUTTER_INPUT_DEVICE_TOOL_BRUSH;
- case LIBINPUT_TABLET_TOOL_TYPE_PENCIL:
- return CLUTTER_INPUT_DEVICE_TOOL_PENCIL;
- case LIBINPUT_TABLET_TOOL_TYPE_AIRBRUSH:
- return CLUTTER_INPUT_DEVICE_TOOL_AIRBRUSH;
- case LIBINPUT_TABLET_TOOL_TYPE_MOUSE:
- return CLUTTER_INPUT_DEVICE_TOOL_MOUSE;
- case LIBINPUT_TABLET_TOOL_TYPE_LENS:
- return CLUTTER_INPUT_DEVICE_TOOL_LENS;
- default:
- return CLUTTER_INPUT_DEVICE_TOOL_NONE;
- }
-}
-
-static void
-input_device_update_tool (MetaSeatImpl *seat_impl,
- ClutterInputDevice *input_device,
- struct libinput_tablet_tool *libinput_tool)
-{
- MetaInputDeviceNative *evdev_device = META_INPUT_DEVICE_NATIVE (input_device);
- ClutterInputDeviceTool *tool = NULL;
- MetaInputSettings *input_settings;
-
- if (libinput_tool)
- {
- if (!seat_impl->tools)
- {
- seat_impl->tools =
- g_hash_table_new_full (NULL, NULL, NULL,
- (GDestroyNotify) g_object_unref);
- }
-
- tool = g_hash_table_lookup (seat_impl->tools, libinput_tool);
-
- if (!tool)
- {
- ClutterInputDeviceToolType tool_type;
- uint64_t tool_serial;
-
- tool_serial = libinput_tablet_tool_get_serial (libinput_tool);
- tool_type = translate_tool_type (libinput_tool);
- tool = meta_input_device_tool_native_new (libinput_tool,
- tool_serial, tool_type);
- g_hash_table_insert (seat_impl->tools, libinput_tool, tool);
- }
- }
-
- if (evdev_device->last_tool != tool)
- {
- evdev_device->last_tool = tool;
- input_settings = seat_impl->input_settings;
- meta_input_settings_notify_tool_change (input_settings, input_device, tool);
- }
-}
-
-static double *
-translate_tablet_axes (struct libinput_event_tablet_tool *tablet_event,
- ClutterInputDeviceTool *tool)
-{
- double *axes = g_new0 (double, CLUTTER_INPUT_AXIS_LAST);
- struct libinput_tablet_tool *libinput_tool;
- double value;
-
- libinput_tool = libinput_event_tablet_tool_get_tool (tablet_event);
-
- value = libinput_event_tablet_tool_get_x (tablet_event);
- axes[CLUTTER_INPUT_AXIS_X] = value;
- value = libinput_event_tablet_tool_get_y (tablet_event);
- axes[CLUTTER_INPUT_AXIS_Y] = value;
-
- if (libinput_tablet_tool_has_distance (libinput_tool))
- {
- value = libinput_event_tablet_tool_get_distance (tablet_event);
- axes[CLUTTER_INPUT_AXIS_DISTANCE] = value;
- }
-
- if (libinput_tablet_tool_has_pressure (libinput_tool))
- {
- value = libinput_event_tablet_tool_get_pressure (tablet_event);
- value = meta_input_device_tool_native_translate_pressure_in_impl (tool, value);
- axes[CLUTTER_INPUT_AXIS_PRESSURE] = value;
- }
-
- if (libinput_tablet_tool_has_tilt (libinput_tool))
- {
- value = libinput_event_tablet_tool_get_tilt_x (tablet_event);
- axes[CLUTTER_INPUT_AXIS_XTILT] = value;
- value = libinput_event_tablet_tool_get_tilt_y (tablet_event);
- axes[CLUTTER_INPUT_AXIS_YTILT] = value;
- }
-
- if (libinput_tablet_tool_has_rotation (libinput_tool))
- {
- value = libinput_event_tablet_tool_get_rotation (tablet_event);
- axes[CLUTTER_INPUT_AXIS_ROTATION] = value;
- }
-
- if (libinput_tablet_tool_has_slider (libinput_tool))
- {
- value = libinput_event_tablet_tool_get_slider_position (tablet_event);
- axes[CLUTTER_INPUT_AXIS_SLIDER] = value;
- }
-
- if (libinput_tablet_tool_has_wheel (libinput_tool))
- {
- value = libinput_event_tablet_tool_get_wheel_delta (tablet_event);
- axes[CLUTTER_INPUT_AXIS_WHEEL] = value;
- }
-
- return axes;
-}
-
-static void
-notify_continuous_axis (MetaSeatImpl *seat_impl,
- ClutterInputDevice *device,
- uint64_t time_us,
- ClutterScrollSource scroll_source,
- struct libinput_event_pointer *axis_event)
-{
- double dx = 0.0, dy = 0.0;
- ClutterScrollFinishFlags finish_flags = CLUTTER_SCROLL_FINISHED_NONE;
-
- if (libinput_event_pointer_has_axis (axis_event,
- LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL))
- {
- dx = libinput_event_pointer_get_axis_value (
- axis_event, LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL);
-
- if (fabs (dx) < DBL_EPSILON)
- finish_flags |= CLUTTER_SCROLL_FINISHED_HORIZONTAL;
- }
- if (libinput_event_pointer_has_axis (axis_event,
- LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL))
- {
- dy = libinput_event_pointer_get_axis_value (
- axis_event, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL);
-
- if (fabs (dy) < DBL_EPSILON)
- finish_flags |= CLUTTER_SCROLL_FINISHED_VERTICAL;
- }
-
- meta_seat_impl_notify_scroll_continuous_in_impl (seat_impl, device, time_us,
- dx, dy,
- scroll_source, finish_flags);
-}
-
-static void
-notify_discrete_axis (MetaSeatImpl *seat_impl,
- ClutterInputDevice *device,
- uint64_t time_us,
- ClutterScrollSource scroll_source,
- struct libinput_event_pointer *axis_event)
-{
- double discrete_dx = 0.0, discrete_dy = 0.0;
-
- if (libinput_event_pointer_has_axis (axis_event,
- LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL))
- {
- discrete_dx = libinput_event_pointer_get_axis_value_discrete (
- axis_event, LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL);
- }
- if (libinput_event_pointer_has_axis (axis_event,
- LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL))
- {
- discrete_dy = libinput_event_pointer_get_axis_value_discrete (
- axis_event, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL);
- }
-
- meta_seat_impl_notify_discrete_scroll_in_impl (seat_impl, device,
- time_us,
- discrete_dx, discrete_dy,
- scroll_source);
-}
-
-static void
-process_tablet_axis (MetaSeatImpl *seat_impl,
- struct libinput_event *event)
-{
- struct libinput_device *libinput_device = libinput_event_get_device (event);
- uint64_t time;
- double x, y, dx, dy, *axes;
- float stage_width, stage_height;
- ClutterInputDevice *device;
- struct libinput_event_tablet_tool *tablet_event =
- libinput_event_get_tablet_tool_event (event);
- MetaInputDeviceNative *evdev_device;
-
- device = libinput_device_get_user_data (libinput_device);
- evdev_device = META_INPUT_DEVICE_NATIVE (device);
-
- axes = translate_tablet_axes (tablet_event,
- evdev_device->last_tool);
-
- meta_viewport_info_get_extents (seat_impl->viewports,
- &stage_width, &stage_height);
-
- time = libinput_event_tablet_tool_get_time_usec (tablet_event);
-
- if (meta_input_device_native_get_mapping_mode_in_impl (device) == META_INPUT_DEVICE_MAPPING_RELATIVE ||
- clutter_input_device_tool_get_tool_type (evdev_device->last_tool) == CLUTTER_INPUT_DEVICE_TOOL_MOUSE ||
- clutter_input_device_tool_get_tool_type (evdev_device->last_tool) == CLUTTER_INPUT_DEVICE_TOOL_LENS)
- {
- dx = libinput_event_tablet_tool_get_dx (tablet_event);
- dy = libinput_event_tablet_tool_get_dy (tablet_event);
- notify_relative_tool_motion_in_impl (device, time, dx, dy, axes);
- }
- else
- {
- x = libinput_event_tablet_tool_get_x_transformed (tablet_event, stage_width);
- y = libinput_event_tablet_tool_get_y_transformed (tablet_event, stage_height);
- notify_absolute_motion_in_impl (device, time, x, y, axes);
- }
-}
-
-static gboolean
-process_device_event (MetaSeatImpl *seat_impl,
- struct libinput_event *event)
-{
- gboolean handled = TRUE;
- struct libinput_device *libinput_device = libinput_event_get_device(event);
- ClutterInputDevice *device;
- MetaInputDeviceNative *device_native;
-
- switch (libinput_event_get_type (event))
- {
- case LIBINPUT_EVENT_KEYBOARD_KEY:
- {
- uint32_t key, key_state, seat_key_count;
- uint64_t time_us;
- struct libinput_event_keyboard *key_event =
- libinput_event_get_keyboard_event (event);
-
- device = libinput_device_get_user_data (libinput_device);
- time_us = libinput_event_keyboard_get_time_usec (key_event);
- key = libinput_event_keyboard_get_key (key_event);
- key_state = libinput_event_keyboard_get_key_state (key_event) ==
- LIBINPUT_KEY_STATE_PRESSED;
- seat_key_count =
- libinput_event_keyboard_get_seat_key_count (key_event);
-
- /* Ignore key events that are not seat wide state changes. */
- if ((key_state == LIBINPUT_KEY_STATE_PRESSED &&
- seat_key_count != 1) ||
- (key_state == LIBINPUT_KEY_STATE_RELEASED &&
- seat_key_count != 0))
- {
- meta_topic (META_DEBUG_INPUT,
- "Dropping key-%s of key 0x%x because seat-wide "
- "key count is %d",
- key_state == LIBINPUT_KEY_STATE_PRESSED ? "press" : "release",
- key, seat_key_count);
- break;
- }
-
- meta_seat_impl_notify_key_in_impl (seat_impl,
- device,
- time_us, key, key_state, TRUE);
-
- break;
- }
-
- case LIBINPUT_EVENT_POINTER_MOTION:
- {
- struct libinput_event_pointer *pointer_event =
- libinput_event_get_pointer_event (event);
- uint64_t time_us;
- double dx;
- double dy;
- double dx_unaccel;
- double dy_unaccel;
-
- device = libinput_device_get_user_data (libinput_device);
- time_us = libinput_event_pointer_get_time_usec (pointer_event);
- dx = libinput_event_pointer_get_dx (pointer_event);
- dy = libinput_event_pointer_get_dy (pointer_event);
- dx_unaccel = libinput_event_pointer_get_dx_unaccelerated (pointer_event);
- dy_unaccel = libinput_event_pointer_get_dy_unaccelerated (pointer_event);
-
- meta_seat_impl_notify_relative_motion_in_impl (seat_impl,
- device,
- time_us,
- dx, dy,
- dx_unaccel, dy_unaccel);
-
- break;
- }
-
- case LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE:
- {
- uint64_t time_us;
- double x, y;
- float stage_width, stage_height;
- struct libinput_event_pointer *motion_event =
- libinput_event_get_pointer_event (event);
- device = libinput_device_get_user_data (libinput_device);
-
- meta_viewport_info_get_extents (seat_impl->viewports,
- &stage_width, &stage_height);
-
- time_us = libinput_event_pointer_get_time_usec (motion_event);
- x = libinput_event_pointer_get_absolute_x_transformed (motion_event,
- stage_width);
- y = libinput_event_pointer_get_absolute_y_transformed (motion_event,
- stage_height);
-
- meta_seat_impl_notify_absolute_motion_in_impl (seat_impl,
- device,
- time_us,
- x, y,
- NULL);
-
- break;
- }
-
- case LIBINPUT_EVENT_POINTER_BUTTON:
- {
- uint32_t button, button_state, seat_button_count;
- uint64_t time_us;
- struct libinput_event_pointer *button_event =
- libinput_event_get_pointer_event (event);
- device = libinput_device_get_user_data (libinput_device);
-
- time_us = libinput_event_pointer_get_time_usec (button_event);
- button = libinput_event_pointer_get_button (button_event);
- button_state = libinput_event_pointer_get_button_state (button_event) ==
- LIBINPUT_BUTTON_STATE_PRESSED;
- seat_button_count =
- libinput_event_pointer_get_seat_button_count (button_event);
-
- /* Ignore button events that are not seat wide state changes. */
- if ((button_state == LIBINPUT_BUTTON_STATE_PRESSED &&
- seat_button_count != 1) ||
- (button_state == LIBINPUT_BUTTON_STATE_RELEASED &&
- seat_button_count != 0))
- {
- meta_topic (META_DEBUG_INPUT,
- "Dropping button-%s of button 0x%x because seat-wide "
- "button count is %d",
- button_state == LIBINPUT_BUTTON_STATE_PRESSED ? "press" : "release",
- button, seat_button_count);
- break;
- }
-
- meta_seat_impl_notify_button_in_impl (seat_impl, device,
- time_us, button, button_state);
- break;
- }
-
- case LIBINPUT_EVENT_POINTER_AXIS:
- {
- uint64_t time_us;
- enum libinput_pointer_axis_source source;
- struct libinput_event_pointer *axis_event =
- libinput_event_get_pointer_event (event);
- ClutterScrollSource scroll_source;
-
- device = libinput_device_get_user_data (libinput_device);
-
- time_us = libinput_event_pointer_get_time_usec (axis_event);
- source = libinput_event_pointer_get_axis_source (axis_event);
- scroll_source = translate_scroll_source (source);
-
- /* libinput < 0.8 sent wheel click events with value 10. Since 0.8
- the value is the angle of the click in degrees. To keep
- backwards-compat with existing clients, we just send multiples of
- the click count. */
-
- switch (scroll_source)
- {
- case CLUTTER_SCROLL_SOURCE_WHEEL:
- notify_discrete_axis (seat_impl, device, time_us, scroll_source,
- axis_event);
- break;
- case CLUTTER_SCROLL_SOURCE_FINGER:
- case CLUTTER_SCROLL_SOURCE_CONTINUOUS:
- case CLUTTER_SCROLL_SOURCE_UNKNOWN:
- notify_continuous_axis (seat_impl, device, time_us, scroll_source,
- axis_event);
- break;
- }
- break;
- }
-
- case LIBINPUT_EVENT_TOUCH_DOWN:
- {
- int seat_slot;
- uint64_t time_us;
- double x, y;
- float stage_width, stage_height;
- MetaTouchState *touch_state;
- struct libinput_event_touch *touch_event =
- libinput_event_get_touch_event (event);
-
- device = libinput_device_get_user_data (libinput_device);
- device_native = META_INPUT_DEVICE_NATIVE (device);
-
- meta_viewport_info_get_extents (seat_impl->viewports,
- &stage_width, &stage_height);
-
- seat_slot = libinput_event_touch_get_seat_slot (touch_event);
- time_us = libinput_event_touch_get_time_usec (touch_event);
- x = libinput_event_touch_get_x_transformed (touch_event,
- stage_width);
- y = libinput_event_touch_get_y_transformed (touch_event,
- stage_height);
-
- g_rw_lock_writer_lock (&seat_impl->state_lock);
-
- touch_state = meta_seat_impl_acquire_touch_state_in_impl (seat_impl, seat_slot);
- touch_state->coords.x = x;
- touch_state->coords.y = y;
-
- g_rw_lock_writer_unlock (&seat_impl->state_lock);
-
- meta_seat_impl_notify_touch_event_in_impl (seat_impl, device,
- CLUTTER_TOUCH_BEGIN,
- time_us,
- touch_state->seat_slot,
- touch_state->coords.x,
- touch_state->coords.y);
- break;
- }
-
- case LIBINPUT_EVENT_TOUCH_UP:
- {
- int seat_slot;
- uint64_t time_us;
- MetaTouchState *touch_state;
- struct libinput_event_touch *touch_event =
- libinput_event_get_touch_event (event);
-
- device = libinput_device_get_user_data (libinput_device);
- device_native = META_INPUT_DEVICE_NATIVE (device);
-
- seat_slot = libinput_event_touch_get_seat_slot (touch_event);
- time_us = libinput_event_touch_get_time_usec (touch_event);
- touch_state = meta_seat_impl_lookup_touch_state_in_impl (seat_impl, seat_slot);
- if (!touch_state)
- break;
-
- meta_seat_impl_notify_touch_event_in_impl (seat_impl, device,
- CLUTTER_TOUCH_END, time_us,
- touch_state->seat_slot,
- touch_state->coords.x,
- touch_state->coords.y);
-
- g_rw_lock_writer_lock (&seat_impl->state_lock);
- meta_seat_impl_release_touch_state_in_impl (seat_impl, seat_slot);
- g_rw_lock_writer_unlock (&seat_impl->state_lock);
- break;
- }
-
- case LIBINPUT_EVENT_TOUCH_MOTION:
- {
- int seat_slot;
- uint64_t time_us;
- double x, y;
- float stage_width, stage_height;
- MetaTouchState *touch_state;
- struct libinput_event_touch *touch_event =
- libinput_event_get_touch_event (event);
-
- device = libinput_device_get_user_data (libinput_device);
- device_native = META_INPUT_DEVICE_NATIVE (device);
-
- meta_viewport_info_get_extents (seat_impl->viewports,
- &stage_width, &stage_height);
-
- seat_slot = libinput_event_touch_get_seat_slot (touch_event);
- time_us = libinput_event_touch_get_time_usec (touch_event);
- x = libinput_event_touch_get_x_transformed (touch_event,
- stage_width);
- y = libinput_event_touch_get_y_transformed (touch_event,
- stage_height);
-
- g_rw_lock_writer_lock (&seat_impl->state_lock);
- touch_state = meta_seat_impl_lookup_touch_state_in_impl (seat_impl, seat_slot);
- if (touch_state)
- {
- touch_state->coords.x = x;
- touch_state->coords.y = y;
- }
- g_rw_lock_writer_unlock (&seat_impl->state_lock);
-
- if (!touch_state)
- break;
-
- meta_seat_impl_notify_touch_event_in_impl (seat_impl, device,
- CLUTTER_TOUCH_UPDATE,
- time_us,
- touch_state->seat_slot,
- touch_state->coords.x,
- touch_state->coords.y);
- break;
- }
- case LIBINPUT_EVENT_TOUCH_CANCEL:
- {
- int seat_slot;
- MetaTouchState *touch_state;
- uint64_t time_us;
- struct libinput_event_touch *touch_event =
- libinput_event_get_touch_event (event);
-
- device = libinput_device_get_user_data (libinput_device);
- device_native = META_INPUT_DEVICE_NATIVE (device);
- time_us = libinput_event_touch_get_time_usec (touch_event);
-
- seat_slot = libinput_event_touch_get_seat_slot (touch_event);
- touch_state = meta_seat_impl_lookup_touch_state_in_impl (seat_impl, seat_slot);
- if (!touch_state)
- break;
-
- meta_seat_impl_notify_touch_event_in_impl (touch_state->seat_impl,
- CLUTTER_INPUT_DEVICE (device_native),
- CLUTTER_TOUCH_CANCEL,
- time_us,
- touch_state->seat_slot,
- touch_state->coords.x,
- touch_state->coords.y);
-
- meta_seat_impl_release_touch_state_in_impl (seat_impl, seat_slot);
- break;
- }
- case LIBINPUT_EVENT_GESTURE_PINCH_BEGIN:
- case LIBINPUT_EVENT_GESTURE_PINCH_END:
- {
- struct libinput_event_gesture *gesture_event =
- libinput_event_get_gesture_event (event);
- ClutterTouchpadGesturePhase phase;
- uint32_t n_fingers;
- uint64_t time_us;
-
- if (libinput_event_get_type (event) == LIBINPUT_EVENT_GESTURE_PINCH_BEGIN)
- phase = CLUTTER_TOUCHPAD_GESTURE_PHASE_BEGIN;
- else
- phase = libinput_event_gesture_get_cancelled (gesture_event) ?
- CLUTTER_TOUCHPAD_GESTURE_PHASE_CANCEL : CLUTTER_TOUCHPAD_GESTURE_PHASE_END;
-
- n_fingers = libinput_event_gesture_get_finger_count (gesture_event);
- device = libinput_device_get_user_data (libinput_device);
- time_us = libinput_event_gesture_get_time_usec (gesture_event);
- notify_pinch_gesture_event (device, phase, time_us, 0, 0, 0, 0, 0, 0, n_fingers);
- break;
- }
- case LIBINPUT_EVENT_GESTURE_PINCH_UPDATE:
- {
- struct libinput_event_gesture *gesture_event =
- libinput_event_get_gesture_event (event);
- double angle_delta, scale, dx, dy, dx_unaccel, dy_unaccel;
- uint32_t n_fingers;
- uint64_t time_us;
-
- n_fingers = libinput_event_gesture_get_finger_count (gesture_event);
- device = libinput_device_get_user_data (libinput_device);
- time_us = libinput_event_gesture_get_time_usec (gesture_event);
- angle_delta = libinput_event_gesture_get_angle_delta (gesture_event);
- scale = libinput_event_gesture_get_scale (gesture_event);
- dx = libinput_event_gesture_get_dx (gesture_event);
- dy = libinput_event_gesture_get_dy (gesture_event);
- dx_unaccel = libinput_event_gesture_get_dx_unaccelerated (gesture_event);
- dy_unaccel = libinput_event_gesture_get_dy_unaccelerated (gesture_event);
-
- notify_pinch_gesture_event (device,
- CLUTTER_TOUCHPAD_GESTURE_PHASE_UPDATE,
- time_us, dx, dy, dx_unaccel, dy_unaccel,
- angle_delta, scale, n_fingers);
- break;
- }
- case LIBINPUT_EVENT_GESTURE_SWIPE_BEGIN:
- case LIBINPUT_EVENT_GESTURE_SWIPE_END:
- {
- struct libinput_event_gesture *gesture_event =
- libinput_event_get_gesture_event (event);
- ClutterTouchpadGesturePhase phase;
- uint32_t n_fingers;
- uint64_t time_us;
-
- device = libinput_device_get_user_data (libinput_device);
- time_us = libinput_event_gesture_get_time_usec (gesture_event);
- n_fingers = libinput_event_gesture_get_finger_count (gesture_event);
-
- if (libinput_event_get_type (event) == LIBINPUT_EVENT_GESTURE_SWIPE_BEGIN)
- phase = CLUTTER_TOUCHPAD_GESTURE_PHASE_BEGIN;
- else
- phase = libinput_event_gesture_get_cancelled (gesture_event) ?
- CLUTTER_TOUCHPAD_GESTURE_PHASE_CANCEL : CLUTTER_TOUCHPAD_GESTURE_PHASE_END;
-
- notify_swipe_gesture_event (device, phase, time_us, n_fingers, 0, 0, 0, 0);
- break;
- }
- case LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE:
- {
- struct libinput_event_gesture *gesture_event =
- libinput_event_get_gesture_event (event);
- uint32_t n_fingers;
- uint64_t time_us;
- double dx, dy, dx_unaccel, dy_unaccel;
-
- device = libinput_device_get_user_data (libinput_device);
- time_us = libinput_event_gesture_get_time_usec (gesture_event);
- n_fingers = libinput_event_gesture_get_finger_count (gesture_event);
- dx = libinput_event_gesture_get_dx (gesture_event);
- dy = libinput_event_gesture_get_dy (gesture_event);
- dx_unaccel = libinput_event_gesture_get_dx_unaccelerated (gesture_event);
- dy_unaccel = libinput_event_gesture_get_dy_unaccelerated (gesture_event);
-
- notify_swipe_gesture_event (device,
- CLUTTER_TOUCHPAD_GESTURE_PHASE_UPDATE,
- time_us, n_fingers, dx, dy, dx_unaccel, dy_unaccel);
- break;
- }
- case LIBINPUT_EVENT_TABLET_TOOL_AXIS:
- {
- process_tablet_axis (seat_impl, event);
- break;
- }
- case LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY:
- {
- uint64_t time;
- struct libinput_event_tablet_tool *tablet_event =
- libinput_event_get_tablet_tool_event (event);
- struct libinput_tablet_tool *libinput_tool = NULL;
- enum libinput_tablet_tool_proximity_state state;
- gboolean in;
-
- state = libinput_event_tablet_tool_get_proximity_state (tablet_event);
- time = libinput_event_tablet_tool_get_time_usec (tablet_event);
- device = libinput_device_get_user_data (libinput_device);
- in = state == LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN;
-
- libinput_tool = libinput_event_tablet_tool_get_tool (tablet_event);
-
- if (in)
- input_device_update_tool (seat_impl, device, libinput_tool);
- notify_proximity (device, time, in);
- if (!in)
- input_device_update_tool (seat_impl, device, NULL);
-
- break;
- }
- case LIBINPUT_EVENT_TABLET_TOOL_BUTTON:
- {
- uint64_t time_us;
- uint32_t button_state;
- struct libinput_event_tablet_tool *tablet_event =
- libinput_event_get_tablet_tool_event (event);
- uint32_t tablet_button;
-
- process_tablet_axis (seat_impl, event);
-
- device = libinput_device_get_user_data (libinput_device);
- time_us = libinput_event_tablet_tool_get_time_usec (tablet_event);
- tablet_button = libinput_event_tablet_tool_get_button (tablet_event);
-
- button_state = libinput_event_tablet_tool_get_button_state (tablet_event) ==
- LIBINPUT_BUTTON_STATE_PRESSED;
-
- meta_seat_impl_notify_button_in_impl (seat_impl, device,
- time_us, tablet_button, button_state);
- break;
- }
- case LIBINPUT_EVENT_TABLET_TOOL_TIP:
- {
- uint64_t time_us;
- uint32_t button_state;
- struct libinput_event_tablet_tool *tablet_event =
- libinput_event_get_tablet_tool_event (event);
-
- device = libinput_device_get_user_data (libinput_device);
- time_us = libinput_event_tablet_tool_get_time_usec (tablet_event);
-
- button_state = libinput_event_tablet_tool_get_tip_state (tablet_event) ==
- LIBINPUT_TABLET_TOOL_TIP_DOWN;
-
- /* To avoid jumps on tip, notify axes before the tip down event
- but after the tip up event */
- if (button_state)
- process_tablet_axis (seat_impl, event);
-
- meta_seat_impl_notify_button_in_impl (seat_impl, device,
- time_us, BTN_TOUCH, button_state);
- if (!button_state)
- process_tablet_axis (seat_impl, event);
- break;
- }
- case LIBINPUT_EVENT_TABLET_PAD_BUTTON:
- {
- uint64_t time;
- uint32_t button_state, button, group, mode;
- struct libinput_tablet_pad_mode_group *mode_group;
- struct libinput_event_tablet_pad *pad_event =
- libinput_event_get_tablet_pad_event (event);
-
- device = libinput_device_get_user_data (libinput_device);
- time = libinput_event_tablet_pad_get_time_usec (pad_event);
-
- mode_group = libinput_event_tablet_pad_get_mode_group (pad_event);
- group = libinput_tablet_pad_mode_group_get_index (mode_group);
- mode = libinput_event_tablet_pad_get_mode (pad_event);
-
- button = libinput_event_tablet_pad_get_button_number (pad_event);
- button_state = libinput_event_tablet_pad_get_button_state (pad_event) ==
- LIBINPUT_BUTTON_STATE_PRESSED;
- notify_pad_button (device, time, button, group, mode, button_state);
- break;
- }
- case LIBINPUT_EVENT_TABLET_PAD_STRIP:
- {
- uint64_t time;
- uint32_t number, source, group, mode;
- struct libinput_tablet_pad_mode_group *mode_group;
- struct libinput_event_tablet_pad *pad_event =
- libinput_event_get_tablet_pad_event (event);
- double value;
-
- device = libinput_device_get_user_data (libinput_device);
- time = libinput_event_tablet_pad_get_time_usec (pad_event);
- number = libinput_event_tablet_pad_get_strip_number (pad_event);
- value = libinput_event_tablet_pad_get_strip_position (pad_event);
- source = libinput_event_tablet_pad_get_strip_source (pad_event);
-
- mode_group = libinput_event_tablet_pad_get_mode_group (pad_event);
- group = libinput_tablet_pad_mode_group_get_index (mode_group);
- mode = libinput_event_tablet_pad_get_mode (pad_event);
-
- notify_pad_strip (device, time, number, source, group, mode, value);
- break;
- }
- case LIBINPUT_EVENT_TABLET_PAD_RING:
- {
- uint64_t time;
- uint32_t number, source, group, mode;
- struct libinput_tablet_pad_mode_group *mode_group;
- struct libinput_event_tablet_pad *pad_event =
- libinput_event_get_tablet_pad_event (event);
- double angle;
-
- device = libinput_device_get_user_data (libinput_device);
- time = libinput_event_tablet_pad_get_time_usec (pad_event);
- number = libinput_event_tablet_pad_get_ring_number (pad_event);
- angle = libinput_event_tablet_pad_get_ring_position (pad_event);
- source = libinput_event_tablet_pad_get_ring_source (pad_event);
-
- mode_group = libinput_event_tablet_pad_get_mode_group (pad_event);
- group = libinput_tablet_pad_mode_group_get_index (mode_group);
- mode = libinput_event_tablet_pad_get_mode (pad_event);
-
- notify_pad_ring (device, time, number, source, group, mode, angle);
- break;
- }
- case LIBINPUT_EVENT_SWITCH_TOGGLE:
- {
- struct libinput_event_switch *switch_event =
- libinput_event_get_switch_event (event);
- enum libinput_switch sw =
- libinput_event_switch_get_switch (switch_event);
- enum libinput_switch_state state =
- libinput_event_switch_get_switch_state (switch_event);
-
- if (sw == LIBINPUT_SWITCH_TABLET_MODE)
- {
- seat_impl->tablet_mode_switch_state = (state == LIBINPUT_SWITCH_STATE_ON);
- update_touch_mode (seat_impl);
- }
- break;
- }
- default:
- handled = FALSE;
- }
-
- return handled;
-}
-
-static void
-process_event (MetaSeatImpl *seat_impl,
- struct libinput_event *event)
-{
- if (process_base_event (seat_impl, event))
- return;
- if (process_device_event (seat_impl, event))
- return;
-}
-
-static void
-process_events (MetaSeatImpl *seat_impl)
-{
- struct libinput_event *event;
-
- while ((event = libinput_get_event (seat_impl->libinput)))
- {
- process_event(seat_impl, event);
- libinput_event_destroy(event);
- }
-}
-
-static int
-open_restricted (const char *path,
- int open_flags,
- void *user_data)
-{
- MetaSeatImpl *seat_impl = user_data;
- MetaSeatImplPrivate *priv = meta_seat_impl_get_instance_private (seat_impl);
- MetaBackend *backend = meta_seat_native_get_backend (seat_impl->seat_native);
- MetaDevicePool *device_pool =
- meta_backend_native_get_device_pool (META_BACKEND_NATIVE (backend));
- MetaDeviceFileFlags flags;
- g_autoptr (GError) error = NULL;
- MetaDeviceFile *device_file;
- int fd;
-
- flags = META_DEVICE_FILE_FLAG_NONE;
- if (!(open_flags & (O_RDWR | O_WRONLY)))
- flags |= META_DEVICE_FILE_FLAG_READ_ONLY;
-
- if (!g_str_has_prefix (path, "/sys/"))
- flags |= META_DEVICE_FILE_FLAG_TAKE_CONTROL;
-
- device_file = meta_device_pool_open (device_pool, path, flags, &error);
- if (!device_file)
- {
- g_warning ("Could not open device %s: %s", path, error->message);
- return -1;
- }
-
- fd = meta_device_file_get_fd (device_file);
- g_hash_table_insert (priv->device_files, GINT_TO_POINTER (fd), device_file);
-
- return fd;
-}
-
-static void
-close_restricted (int fd,
- void *user_data)
-{
- MetaSeatImpl *seat_impl = user_data;
- MetaSeatImplPrivate *priv = meta_seat_impl_get_instance_private (seat_impl);
-
- g_hash_table_remove (priv->device_files, GINT_TO_POINTER (fd));
-}
-
-static const struct libinput_interface libinput_interface = {
- open_restricted,
- close_restricted
-};
-
-static void
-kbd_a11y_changed_cb (MetaInputSettings *input_settings,
- MetaKbdA11ySettings *a11y_settings,
- MetaSeatImpl *seat_impl)
-{
- MetaInputDeviceNative *keyboard;
-
- keyboard = META_INPUT_DEVICE_NATIVE (seat_impl->core_keyboard);
- meta_input_device_native_apply_kbd_a11y_settings_in_impl (keyboard, a11y_settings);
-}
-
-static void
-meta_seat_impl_set_keyboard_numlock_in_impl (MetaSeatImpl *seat_impl,
- gboolean numlock_state)
-{
- xkb_mod_mask_t depressed_mods;
- xkb_mod_mask_t latched_mods;
- xkb_mod_mask_t locked_mods;
- xkb_mod_mask_t group_mods;
- xkb_mod_mask_t numlock;
- struct xkb_keymap *xkb_keymap;
- MetaKeymapNative *keymap;
-
- keymap = seat_impl->keymap;
- xkb_keymap = meta_keymap_native_get_keyboard_map_in_impl (keymap);
-
- numlock = (1 << xkb_keymap_mod_get_index (xkb_keymap, "Mod2"));
-
- depressed_mods =
- xkb_state_serialize_mods (seat_impl->xkb, XKB_STATE_MODS_DEPRESSED);
- latched_mods =
- xkb_state_serialize_mods (seat_impl->xkb, XKB_STATE_MODS_LATCHED);
- locked_mods =
- xkb_state_serialize_mods (seat_impl->xkb, XKB_STATE_MODS_LOCKED);
- group_mods =
- xkb_state_serialize_layout (seat_impl->xkb, XKB_STATE_LAYOUT_EFFECTIVE);
-
- if (numlock_state)
- locked_mods |= numlock;
- else
- locked_mods &= ~numlock;
-
- xkb_state_update_mask (seat_impl->xkb,
- depressed_mods,
- latched_mods,
- locked_mods,
- 0, 0,
- group_mods);
-
- meta_seat_impl_sync_leds_in_impl (seat_impl);
- meta_keymap_native_update_in_impl (seat_impl->keymap,
- seat_impl,
- seat_impl->xkb);
-}
-
-static gboolean
-init_libinput (MetaSeatImpl *seat_impl,
- GError **error)
-{
- MetaEventSource *source;
- struct udev *udev;
- struct libinput *libinput;
-
- udev = udev_new ();
- if (G_UNLIKELY (udev == NULL))
- {
- g_warning ("Failed to create udev object");
- seat_impl->input_thread_initialized = TRUE;
- return FALSE;
- }
-
- libinput = libinput_udev_create_context (&libinput_interface,
- seat_impl, udev);
- udev_unref (udev);
-
- if (libinput == NULL)
- {
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- "Failed to create the libinput object.");
- return FALSE;
- }
-
- if (libinput_udev_assign_seat (libinput, seat_impl->seat_id) == -1)
- {
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- "Failed to assign a seat to the libinput object.");
- libinput_unref (seat_impl->libinput);
- return FALSE;
- }
-
- seat_impl->libinput = libinput;
- source = meta_event_source_new (seat_impl);
- seat_impl->event_source = source;
-
- return TRUE;
-}
-
-static gpointer
-input_thread (MetaSeatImpl *seat_impl)
-{
- MetaSeatImplPrivate *priv = meta_seat_impl_get_instance_private (seat_impl);
- struct xkb_keymap *xkb_keymap;
-
- g_main_context_push_thread_default (seat_impl->input_context);
-
- priv->device_files =
- g_hash_table_new_full (NULL, NULL,
- NULL,
- (GDestroyNotify) meta_device_file_release);
-
- if (!(seat_impl->flags & META_SEAT_NATIVE_FLAG_NO_LIBINPUT))
- {
- g_autoptr (GError) error = NULL;
-
- if (!init_libinput (seat_impl, &error))
- {
- g_critical ("Failed to initialize seat: %s", error->message);
- seat_impl->input_thread_initialized = TRUE;
- return NULL;
- }
- }
-
- seat_impl->input_settings = meta_input_settings_native_new_in_impl (seat_impl);
- g_signal_connect_object (seat_impl->input_settings, "kbd-a11y-changed",
- G_CALLBACK (kbd_a11y_changed_cb), seat_impl, 0);
-
- seat_impl->keymap = g_object_new (META_TYPE_KEYMAP_NATIVE, NULL);
-
- xkb_keymap = meta_keymap_native_get_keyboard_map_in_impl (seat_impl->keymap);
-
- if (xkb_keymap)
- {
- seat_impl->xkb = xkb_state_new (xkb_keymap);
-
- seat_impl->caps_lock_led =
- xkb_keymap_led_get_index (xkb_keymap, XKB_LED_NAME_CAPS);
- seat_impl->num_lock_led =
- xkb_keymap_led_get_index (xkb_keymap, XKB_LED_NAME_NUM);
- seat_impl->scroll_lock_led =
- xkb_keymap_led_get_index (xkb_keymap, XKB_LED_NAME_SCROLL);
- }
-
- if (meta_input_settings_maybe_restore_numlock_state (seat_impl->input_settings))
- meta_seat_impl_set_keyboard_numlock_in_impl (seat_impl, TRUE);
-
- seat_impl->has_touchscreen = has_touchscreen (seat_impl);
- seat_impl->has_tablet_switch = has_tablet_switch (seat_impl);
- update_touch_mode (seat_impl);
-
- g_mutex_lock (&seat_impl->init_mutex);
- seat_impl->input_thread_initialized = TRUE;
- g_cond_signal (&seat_impl->init_cond);
- g_mutex_unlock (&seat_impl->init_mutex);
-
- seat_impl->input_loop = g_main_loop_new (seat_impl->input_context, FALSE);
- g_main_loop_run (seat_impl->input_loop);
- g_main_loop_unref (seat_impl->input_loop);
-
- g_main_context_pop_thread_default (seat_impl->input_context);
-
- return NULL;
-}
-
-static gboolean
-meta_seat_impl_initable_init (GInitable *initable,
- GCancellable *cancellable,
- GError **error)
-{
- MetaSeatImpl *seat_impl = META_SEAT_IMPL (initable);
-
- seat_impl->input_context = g_main_context_new ();
- seat_impl->main_context = g_main_context_ref_thread_default ();
- g_assert (seat_impl->main_context == g_main_context_default ());
-
- seat_impl->input_thread =
- g_thread_try_new ("Mutter Input Thread",
- (GThreadFunc) input_thread,
- initable,
- error);
- if (!seat_impl->input_thread)
- return FALSE;
-
- /* Initialize thread synchronously */
- g_mutex_lock (&seat_impl->init_mutex);
- while (!seat_impl->input_thread_initialized)
- g_cond_wait (&seat_impl->init_cond, &seat_impl->init_mutex);
- g_mutex_unlock (&seat_impl->init_mutex);
-
- return TRUE;
-}
-
-static void
-meta_seat_impl_constructed (GObject *object)
-{
- MetaSeatImpl *seat_impl = META_SEAT_IMPL (object);
- ClutterInputDevice *device;
-
- device = meta_input_device_native_new_virtual (
- seat_impl, CLUTTER_POINTER_DEVICE,
- CLUTTER_INPUT_MODE_LOGICAL);
- seat_impl->pointer_x = INITIAL_POINTER_X;
- seat_impl->pointer_y = INITIAL_POINTER_Y;
- meta_input_device_native_set_coords_in_impl (META_INPUT_DEVICE_NATIVE (device),
- seat_impl->pointer_x,
- seat_impl->pointer_y);
- seat_impl->core_pointer = device;
-
- device = meta_input_device_native_new_virtual (
- seat_impl, CLUTTER_KEYBOARD_DEVICE,
- CLUTTER_INPUT_MODE_LOGICAL);
- seat_impl->core_keyboard = device;
-
- if (G_OBJECT_CLASS (meta_seat_impl_parent_class)->constructed)
- G_OBJECT_CLASS (meta_seat_impl_parent_class)->constructed (object);
-}
-
-static void
-meta_seat_impl_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- MetaSeatImpl *seat_impl = META_SEAT_IMPL (object);
-
- switch (prop_id)
- {
- case PROP_SEAT:
- seat_impl->seat_native = g_value_get_object (value);
- break;
- case PROP_SEAT_ID:
- seat_impl->seat_id = g_value_dup_string (value);
- break;
- case PROP_FLAGS:
- seat_impl->flags = g_value_get_flags (value);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- }
-}
-
-static void
-meta_seat_impl_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- MetaSeatImpl *seat_impl = META_SEAT_IMPL (object);
-
- switch (prop_id)
- {
- case PROP_SEAT:
- g_value_set_object (value, seat_impl->seat_native);
- break;
- case PROP_SEAT_ID:
- g_value_set_string (value, seat_impl->seat_id);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- }
-}
-
-static gboolean
-destroy_in_impl (GTask *task)
-{
- MetaSeatImpl *seat_impl = g_task_get_source_object (task);
- MetaSeatImplPrivate *priv = meta_seat_impl_get_instance_private (seat_impl);
- gboolean numlock_active;
-
- g_slist_foreach (seat_impl->devices,
- (GFunc) meta_input_device_native_detach_libinput_in_impl,
- NULL);
- g_slist_free_full (seat_impl->devices, g_object_unref);
- seat_impl->devices = NULL;
-
- g_clear_pointer (&seat_impl->libinput, libinput_unref);
- g_clear_pointer (&seat_impl->tools, g_hash_table_unref);
- g_clear_pointer (&seat_impl->touch_states, g_hash_table_destroy);
- g_clear_pointer (&seat_impl->event_source, meta_event_source_free);
-
- numlock_active =
- xkb_state_mod_name_is_active (seat_impl->xkb, XKB_MOD_NAME_NUM,
- XKB_STATE_MODS_LATCHED |
- XKB_STATE_MODS_LOCKED);
- meta_input_settings_maybe_save_numlock_state (seat_impl->input_settings,
- numlock_active);
-
- g_clear_pointer (&seat_impl->xkb, xkb_state_unref);
-
- meta_seat_impl_clear_repeat_source (seat_impl);
-
- g_clear_pointer (&priv->device_files, g_hash_table_destroy);
-
- g_main_loop_quit (seat_impl->input_loop);
- g_task_return_boolean (task, TRUE);
-
- return G_SOURCE_REMOVE;
-}
-
-void
-meta_seat_impl_destroy (MetaSeatImpl *seat_impl)
-{
- if (seat_impl->libinput)
- {
- GTask *task;
-
- task = g_task_new (seat_impl, NULL, NULL, NULL);
- meta_seat_impl_run_input_task (seat_impl, task,
- (GSourceFunc) destroy_in_impl);
- g_object_unref (task);
-
- g_thread_join (seat_impl->input_thread);
- g_assert (!seat_impl->libinput);
- }
-
- g_object_unref (seat_impl);
-}
-
-static void
-meta_seat_impl_finalize (GObject *object)
-{
- MetaSeatImpl *seat_impl = META_SEAT_IMPL (object);
-
- g_assert (!seat_impl->libinput);
- g_assert (!seat_impl->tools);
- g_assert (!seat_impl->event_source);
-
- g_free (seat_impl->seat_id);
-
- g_rw_lock_clear (&seat_impl->state_lock);
-
- G_OBJECT_CLASS (meta_seat_impl_parent_class)->finalize (object);
-}
-
-ClutterInputDevice *
-meta_seat_impl_get_pointer (MetaSeatImpl *seat_impl)
-{
- return seat_impl->core_pointer;
-}
-
-ClutterInputDevice *
-meta_seat_impl_get_keyboard (MetaSeatImpl *seat_impl)
-{
- return seat_impl->core_keyboard;
-}
-
-GSList *
-meta_seat_impl_get_devices_in_impl (MetaSeatImpl *seat_impl)
-{
- return g_slist_copy_deep (seat_impl->devices,
- (GCopyFunc) g_object_ref,
- NULL);
-}
-
-MetaKeymapNative *
-meta_seat_impl_get_keymap (MetaSeatImpl *seat_impl)
-{
- return g_object_ref (seat_impl->keymap);
-}
-
-static gboolean
-warp_pointer_in_impl (GTask *task)
-{
- MetaSeatImpl *seat_impl = g_task_get_source_object (task);
- graphene_point_t *point;
-
- point = g_task_get_task_data (task);
- notify_absolute_motion_in_impl (seat_impl->core_pointer, 0,
- point->x, point->y, NULL);
- g_task_return_boolean (task, TRUE);
-
- return G_SOURCE_REMOVE;
-}
-
-void
-meta_seat_impl_warp_pointer (MetaSeatImpl *seat_impl,
- int x,
- int y)
-{
- graphene_point_t *point;
- GTask *task;
-
- point = graphene_point_alloc ();
- point->x = x;
- point->y = y;
-
- task = g_task_new (seat_impl, NULL, NULL, NULL);
- g_task_set_task_data (task, point, (GDestroyNotify) graphene_point_free);
- meta_seat_impl_run_input_task (seat_impl, task,
- (GSourceFunc) warp_pointer_in_impl);
- g_object_unref (task);
-}
-
-gboolean
-meta_seat_impl_query_state (MetaSeatImpl *seat_impl,
- ClutterInputDevice *device,
- ClutterEventSequence *sequence,
- graphene_point_t *coords,
- ClutterModifierType *modifiers)
-{
- MetaInputDeviceNative *device_native = META_INPUT_DEVICE_NATIVE (device);
- gboolean retval = FALSE;
- ClutterModifierType mods = 0;
-
- g_rw_lock_reader_lock (&seat_impl->state_lock);
-
- if (sequence)
- {
- MetaTouchState *touch_state;
- int slot;
-
- slot = clutter_event_sequence_get_slot (sequence);
- touch_state = meta_seat_impl_lookup_touch_state_in_impl (seat_impl, slot);
- if (!touch_state)
- goto out;
-
- if (coords)
- {
- coords->x = touch_state->coords.x;
- coords->y = touch_state->coords.y;
- }
-
- if (seat_impl->xkb)
- mods = meta_xkb_translate_modifiers (seat_impl->xkb, 0);
-
- retval = TRUE;
- }
- else
- {
- if (coords)
- {
- coords->x = device_native->pointer_x;
- coords->y = device_native->pointer_y;
- }
-
- if (seat_impl->xkb)
- {
- mods = meta_xkb_translate_modifiers (seat_impl->xkb,
- seat_impl->button_state);
- }
-
- retval = TRUE;
- }
-
- if (modifiers)
- *modifiers = mods;
-
- out:
- g_rw_lock_reader_unlock (&seat_impl->state_lock);
- return retval;
-}
-
-static void
-meta_seat_impl_initable_iface_init (GInitableIface *iface)
-{
- iface->init = meta_seat_impl_initable_init;
-}
-
-static void
-meta_seat_impl_class_init (MetaSeatImplClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- object_class->constructed = meta_seat_impl_constructed;
- object_class->set_property = meta_seat_impl_set_property;
- object_class->get_property = meta_seat_impl_get_property;
- object_class->finalize = meta_seat_impl_finalize;
-
- props[PROP_SEAT] =
- g_param_spec_object ("seat",
- "Seat",
- "Seat",
- META_TYPE_SEAT_NATIVE,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT_ONLY |
- G_PARAM_STATIC_STRINGS);
-
- props[PROP_SEAT_ID] =
- g_param_spec_string ("seat-id",
- "Seat ID",
- "Seat ID",
- NULL,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT_ONLY);
-
- props[PROP_FLAGS] =
- g_param_spec_flags ("flags",
- "Flags",
- "Flags",
- META_TYPE_SEAT_NATIVE_FLAG,
- META_SEAT_NATIVE_FLAG_NONE,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT_ONLY);
-
- signals[KBD_A11Y_FLAGS_CHANGED] =
- g_signal_new ("kbd-a11y-flags-changed",
- G_TYPE_FROM_CLASS (object_class),
- G_SIGNAL_RUN_LAST,
- 0, NULL, NULL, NULL,
- G_TYPE_NONE, 2,
- G_TYPE_UINT, G_TYPE_UINT);
- signals[KBD_A11Y_MODS_STATE_CHANGED] =
- g_signal_new ("kbd-a11y-mods-state-changed",
- G_TYPE_FROM_CLASS (object_class),
- G_SIGNAL_RUN_LAST,
- 0, NULL, NULL, NULL,
- G_TYPE_NONE, 2,
- G_TYPE_UINT, G_TYPE_UINT);
- signals[TOUCH_MODE] =
- g_signal_new ("touch-mode",
- G_TYPE_FROM_CLASS (object_class),
- G_SIGNAL_RUN_LAST,
- 0, NULL, NULL,
- g_cclosure_marshal_VOID__BOOLEAN,
- G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
- signals[BELL] =
- g_signal_new ("bell",
- G_TYPE_FROM_CLASS (object_class),
- G_SIGNAL_RUN_LAST,
- 0, NULL, NULL, NULL,
- G_TYPE_NONE, 0);
- signals[MODS_STATE_CHANGED] =
- g_signal_new ("mods-state-changed",
- G_TYPE_FROM_CLASS (object_class),
- G_SIGNAL_RUN_LAST,
- 0, NULL, NULL, NULL,
- G_TYPE_NONE, 0);
-
- g_object_class_install_properties (object_class, N_PROPS, props);
-}
-
-static void
-meta_seat_impl_init (MetaSeatImpl *seat_impl)
-{
- g_rw_lock_init (&seat_impl->state_lock);
-
- seat_impl->repeat = TRUE;
- seat_impl->repeat_delay = 250; /* ms */
- seat_impl->repeat_interval = 33; /* ms */
-
- g_mutex_init (&seat_impl->init_mutex);
- g_cond_init (&seat_impl->init_cond);
-
- seat_impl->barrier_manager = meta_barrier_manager_native_new ();
-}
-
-void
-meta_seat_impl_update_xkb_state_in_impl (MetaSeatImpl *seat_impl)
-{
- xkb_mod_mask_t latched_mods = 0;
- xkb_mod_mask_t locked_mods = 0;
- struct xkb_keymap *xkb_keymap;
-
- g_rw_lock_writer_lock (&seat_impl->state_lock);
-
- xkb_keymap = meta_keymap_native_get_keyboard_map_in_impl (seat_impl->keymap);
-
- if (seat_impl->xkb)
- {
- latched_mods = xkb_state_serialize_mods (seat_impl->xkb,
- XKB_STATE_MODS_LATCHED);
- locked_mods = xkb_state_serialize_mods (seat_impl->xkb,
- XKB_STATE_MODS_LOCKED);
- xkb_state_unref (seat_impl->xkb);
- }
-
- seat_impl->xkb = xkb_state_new (xkb_keymap);
-
- xkb_state_update_mask (seat_impl->xkb,
- 0, /* depressed */
- latched_mods,
- locked_mods,
- 0, 0, seat_impl->layout_idx);
-
- seat_impl->caps_lock_led =
- xkb_keymap_led_get_index (xkb_keymap, XKB_LED_NAME_CAPS);
- seat_impl->num_lock_led =
- xkb_keymap_led_get_index (xkb_keymap, XKB_LED_NAME_NUM);
- seat_impl->scroll_lock_led =
- xkb_keymap_led_get_index (xkb_keymap, XKB_LED_NAME_SCROLL);
-
- meta_seat_impl_sync_leds_in_impl (seat_impl);
- meta_keymap_native_update_in_impl (seat_impl->keymap,
- seat_impl,
- seat_impl->xkb);
-
- g_rw_lock_writer_unlock (&seat_impl->state_lock);
-}
-
-static gboolean
-release_devices (GTask *task)
-{
- MetaSeatImpl *seat_impl = g_task_get_source_object (task);
-
- if (seat_impl->released)
- {
- g_warning ("meta_seat_impl_release_devices() shouldn't be called "
- "multiple times without a corresponding call to "
- "meta_seat_impl_reclaim_devices() first");
- }
- else
- {
- libinput_suspend (seat_impl->libinput);
- process_events (seat_impl);
-
- seat_impl->released = TRUE;
- }
-
- g_task_return_boolean (task, TRUE);
-
- return G_SOURCE_REMOVE;
-}
-
-/**
- * meta_seat_impl_release_devices:
- *
- * Releases all the evdev devices that Clutter is currently managing. This api
- * is typically used when switching away from the Clutter application when
- * switching tty. The devices can be reclaimed later with a call to
- * meta_seat_impl_reclaim_devices().
- *
- * This function should only be called after clutter has been initialized.
- */
-void
-meta_seat_impl_release_devices (MetaSeatImpl *seat_impl)
-{
- GTask *task;
-
- g_return_if_fail (META_IS_SEAT_IMPL (seat_impl));
-
- task = g_task_new (seat_impl, NULL, NULL, NULL);
- meta_seat_impl_run_input_task (seat_impl, task,
- (GSourceFunc) release_devices);
- g_object_unref (task);
-}
-
-static gboolean
-reclaim_devices (GTask *task)
-{
- MetaSeatImpl *seat_impl = g_task_get_source_object (task);
-
- if (seat_impl->released)
- {
- libinput_resume (seat_impl->libinput);
- meta_seat_impl_update_xkb_state_in_impl (seat_impl);
- process_events (seat_impl);
-
- seat_impl->released = FALSE;
- }
- else
- {
- g_warning ("Spurious call to meta_seat_impl_reclaim_devices() without "
- "previous call to meta_seat_impl_release_devices");
- }
-
- g_task_return_boolean (task, TRUE);
-
- return G_SOURCE_REMOVE;
-}
-
-/**
- * meta_seat_impl_reclaim_devices:
- *
- * This causes Clutter to re-probe for evdev devices. This is must only be
- * called after a corresponding call to meta_seat_impl_release_devices()
- * was previously used to release all evdev devices. This API is typically
- * used when a clutter application using evdev has regained focus due to
- * switching ttys.
- *
- * This function should only be called after clutter has been initialized.
- */
-void
-meta_seat_impl_reclaim_devices (MetaSeatImpl *seat_impl)
-{
- GTask *task;
-
- g_return_if_fail (META_IS_SEAT_IMPL (seat_impl));
-
- task = g_task_new (seat_impl, NULL, NULL, NULL);
- meta_seat_impl_run_input_task (seat_impl, task, (GSourceFunc) reclaim_devices);
- g_object_unref (task);
-}
-
-static gboolean
-set_keyboard_map (GTask *task)
-{
- MetaSeatImpl *seat_impl = g_task_get_source_object (task);
- struct xkb_keymap *xkb_keymap = g_task_get_task_data (task);
- MetaKeymapNative *keymap;
-
- keymap = seat_impl->keymap;
- meta_keymap_native_set_keyboard_map_in_impl (keymap, xkb_keymap);
-
- meta_seat_impl_update_xkb_state_in_impl (seat_impl);
- g_task_return_boolean (task, TRUE);
-
- return G_SOURCE_REMOVE;
-}
-
-/**
- * meta_seat_impl_set_keyboard_map: (skip)
- * @seat_impl: the #ClutterSeat created by the evdev backend
- * @keymap: the new keymap
- *
- * Instructs @evdev to use the speficied keyboard map. This will cause
- * the backend to drop the state and create a new one with the new
- * map. To avoid state being lost, callers should ensure that no key
- * is pressed when calling this function.
- */
-void
-meta_seat_impl_set_keyboard_map (MetaSeatImpl *seat_impl,
- struct xkb_keymap *xkb_keymap)
-{
- GTask *task;
-
- g_return_if_fail (META_IS_SEAT_IMPL (seat_impl));
- g_return_if_fail (xkb_keymap != NULL);
-
- task = g_task_new (seat_impl, NULL, NULL, NULL);
- g_task_set_task_data (task,
- xkb_keymap_ref (xkb_keymap),
- (GDestroyNotify) xkb_keymap_unref);
- meta_seat_impl_run_input_task (seat_impl, task, (GSourceFunc) set_keyboard_map);
- g_object_unref (task);
-}
-
-static gboolean
-set_keyboard_layout_index (GTask *task)
-{
- MetaSeatImpl *seat_impl = g_task_get_source_object (task);
- xkb_layout_index_t idx = GPOINTER_TO_UINT (g_task_get_task_data (task));
- xkb_mod_mask_t depressed_mods;
- xkb_mod_mask_t latched_mods;
- xkb_mod_mask_t locked_mods;
- struct xkb_state *state;
-
- g_rw_lock_writer_lock (&seat_impl->state_lock);
-
- state = seat_impl->xkb;
-
- depressed_mods = xkb_state_serialize_mods (state, XKB_STATE_MODS_DEPRESSED);
- latched_mods = xkb_state_serialize_mods (state, XKB_STATE_MODS_LATCHED);
- locked_mods = xkb_state_serialize_mods (state, XKB_STATE_MODS_LOCKED);
-
- xkb_state_update_mask (state, depressed_mods, latched_mods, locked_mods, 0, 0, idx);
- meta_keymap_native_update_in_impl (seat_impl->keymap,
- seat_impl,
- seat_impl->xkb);
-
- seat_impl->layout_idx = idx;
-
- g_rw_lock_writer_unlock (&seat_impl->state_lock);
-
- g_task_return_boolean (task, TRUE);
-
- return G_SOURCE_REMOVE;
-}
-
-/**
- * meta_seat_impl_set_keyboard_layout_index: (skip)
- * @seat_impl: the #ClutterSeat created by the evdev backend
- * @idx: the xkb layout index to set
- *
- * Sets the xkb layout index on the backend's #xkb_state .
- */
-void
-meta_seat_impl_set_keyboard_layout_index (MetaSeatImpl *seat_impl,
- xkb_layout_index_t idx)
-{
- GTask *task;
-
- g_return_if_fail (META_IS_SEAT_IMPL (seat_impl));
-
- task = g_task_new (seat_impl, NULL, NULL, NULL);
- g_task_set_task_data (task, GUINT_TO_POINTER (idx), NULL);
- meta_seat_impl_run_input_task (seat_impl, task,
- (GSourceFunc) set_keyboard_layout_index);
- g_object_unref (task);
-}
-
-/**
- * meta_seat_impl_set_keyboard_repeat_in_impl:
- * @seat_impl: the #ClutterSeat created by the evdev backend
- * @repeat: whether to enable or disable keyboard repeat events
- * @delay: the delay in ms between the hardware key press event and
- * the first synthetic event
- * @interval: the period in ms between consecutive synthetic key
- * press events
- *
- * Enables or disables sythetic key press events, allowing for initial
- * delay and interval period to be specified.
- */
-void
-meta_seat_impl_set_keyboard_repeat_in_impl (MetaSeatImpl *seat_impl,
- gboolean repeat,
- uint32_t delay,
- uint32_t interval)
-{
- g_return_if_fail (META_IS_SEAT_IMPL (seat_impl));
-
- seat_impl->repeat = repeat;
- seat_impl->repeat_delay = delay;
- seat_impl->repeat_interval = interval;
-}
-
-struct xkb_state *
-meta_seat_impl_get_xkb_state_in_impl (MetaSeatImpl *seat_impl)
-{
- return seat_impl->xkb;
-}
-
-MetaBarrierManagerNative *
-meta_seat_impl_get_barrier_manager (MetaSeatImpl *seat_impl)
-{
- return seat_impl->barrier_manager;
-}
-
-static gboolean
-set_pointer_constraint (GTask *task)
-{
- MetaSeatImpl *seat_impl = g_task_get_source_object (task);
- MetaPointerConstraintImpl *constraint_impl = g_task_get_task_data (task);
-
- if (!g_set_object (&seat_impl->pointer_constraint, constraint_impl))
- return G_SOURCE_REMOVE;
-
- if (constraint_impl)
- {
- meta_pointer_constraint_impl_ensure_constrained (constraint_impl,
- seat_impl->core_pointer);
- }
-
- g_task_return_boolean (task, TRUE);
-
- return G_SOURCE_REMOVE;
-}
-
-void
-meta_seat_impl_set_pointer_constraint (MetaSeatImpl *seat_impl,
- MetaPointerConstraintImpl *constraint_impl)
-{
- GTask *task;
-
- g_return_if_fail (META_IS_SEAT_IMPL (seat_impl));
-
- task = g_task_new (seat_impl, NULL, NULL, NULL);
- if (constraint_impl)
- g_task_set_task_data (task, g_object_ref (constraint_impl), g_object_unref);
- meta_seat_impl_run_input_task (seat_impl, task,
- (GSourceFunc) set_pointer_constraint);
- g_object_unref (task);
-}
-
-static gboolean
-set_viewports (GTask *task)
-{
- MetaSeatImpl *seat_impl = g_task_get_source_object (task);
- MetaViewportInfo *viewports = g_task_get_task_data (task);
-
- g_set_object (&seat_impl->viewports, viewports);
- g_task_return_boolean (task, TRUE);
-
- return G_SOURCE_REMOVE;
-}
-
-void
-meta_seat_impl_set_viewports (MetaSeatImpl *seat_impl,
- MetaViewportInfo *viewports)
-{
- GTask *task;
-
- g_return_if_fail (META_IS_SEAT_IMPL (seat_impl));
-
- task = g_task_new (seat_impl, NULL, NULL, NULL);
- g_task_set_task_data (task, g_object_ref (viewports), g_object_unref);
- meta_seat_impl_run_input_task (seat_impl, task,
- (GSourceFunc) set_viewports);
- g_object_unref (task);
-}
-
-MetaSeatImpl *
-meta_seat_impl_new (MetaSeatNative *seat_native,
- const char *seat_id,
- MetaSeatNativeFlag flags)
-{
- return g_initable_new (META_TYPE_SEAT_IMPL,
- NULL, NULL,
- "seat", seat_native,
- "seat-id", seat_id,
- "flags", flags,
- NULL);
-}
-
-void
-meta_seat_impl_notify_kbd_a11y_flags_changed_in_impl (MetaSeatImpl *seat_impl,
- MetaKeyboardA11yFlags new_flags,
- MetaKeyboardA11yFlags what_changed)
-{
- MetaInputSettings *input_settings;
- GValue values[] = { G_VALUE_INIT, G_VALUE_INIT };
-
- input_settings = seat_impl->input_settings;
- meta_input_settings_notify_kbd_a11y_change (input_settings,
- new_flags, what_changed);
- g_value_init (&values[0], G_TYPE_UINT);
- g_value_set_uint (&values[0], new_flags);
- g_value_init (&values[1], G_TYPE_UINT);
- g_value_set_uint (&values[1], what_changed);
-
- emit_signal (seat_impl, signals[KBD_A11Y_FLAGS_CHANGED],
- values, G_N_ELEMENTS (values));
-}
-
-void
-meta_seat_impl_notify_kbd_a11y_mods_state_changed_in_impl (MetaSeatImpl *seat_impl,
- xkb_mod_mask_t new_latched_mods,
- xkb_mod_mask_t new_locked_mods)
-{
- GValue values[] = { G_VALUE_INIT, G_VALUE_INIT };
-
- g_value_init (&values[0], G_TYPE_UINT);
- g_value_set_uint (&values[0], new_latched_mods);
- g_value_init (&values[1], G_TYPE_UINT);
- g_value_set_uint (&values[1], new_locked_mods);
-
- emit_signal (seat_impl, signals[KBD_A11Y_MODS_STATE_CHANGED],
- values, G_N_ELEMENTS (values));
-}
-
-void
-meta_seat_impl_notify_bell_in_impl (MetaSeatImpl *seat_impl)
-{
- emit_signal (seat_impl, signals[BELL], NULL, 0);
-}
-
-MetaInputSettings *
-meta_seat_impl_get_input_settings (MetaSeatImpl *seat_impl)
-{
- return seat_impl->input_settings;
-}
diff --git a/src/backends/native/meta-seat-impl.h b/src/backends/native/meta-seat-impl.h
deleted file mode 100644
index d3e2ab860..000000000
--- a/src/backends/native/meta-seat-impl.h
+++ /dev/null
@@ -1,254 +0,0 @@
-/*
- * Copyright (C) 2010 Intel Corp.
- * Copyright (C) 2014 Jonas Ådahl
- * Copyright (C) 2016 Red Hat Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
- *
- * Author: Damien Lespiau <damien.lespiau@intel.com>
- * Author: Jonas Ådahl <jadahl@gmail.com>
- */
-
-#ifndef META_SEAT_IMPL_H
-#define META_SEAT_IMPL_H
-
-#ifndef META_INPUT_THREAD_H_INSIDE
-#error "This header cannot be included directly. Use "backends/native/meta-input-thread.h""
-#endif /* META_INPUT_THREAD_H_INSIDE */
-
-#include <gudev/gudev.h>
-#include <libinput.h>
-#include <linux/input-event-codes.h>
-
-#include "backends/meta-input-settings-private.h"
-#include "backends/meta-viewport-info.h"
-#include "backends/native/meta-backend-native-types.h"
-#include "backends/native/meta-barrier-native.h"
-#include "backends/native/meta-cursor-renderer-native.h"
-#include "backends/native/meta-keymap-native.h"
-#include "backends/native/meta-pointer-constraint-native.h"
-#include "backends/native/meta-xkb-utils.h"
-#include "clutter/clutter.h"
-
-typedef struct _MetaTouchState MetaTouchState;
-typedef struct _MetaSeatImpl MetaSeatImpl;
-typedef struct _MetaEventSource MetaEventSource;
-
-struct _MetaTouchState
-{
- MetaSeatImpl *seat_impl;
-
- int device_slot;
- int seat_slot;
- graphene_point_t coords;
-};
-
-struct _MetaSeatImpl
-{
- GObject parent_instance;
-
- GMainContext *main_context;
- GMainContext *input_context;
- GMainLoop *input_loop;
- GThread *input_thread;
- GMutex init_mutex;
- GCond init_cond;
-
- MetaSeatNative *seat_native;
- char *seat_id;
- MetaSeatNativeFlag flags;
- MetaEventSource *event_source;
- struct libinput *libinput;
- GRWLock state_lock;
-
- GSList *devices;
- GHashTable *tools;
-
- ClutterInputDevice *core_pointer;
- ClutterInputDevice *core_keyboard;
-
- GHashTable *touch_states;
- GHashTable *cursor_renderers;
-
- struct xkb_state *xkb;
- xkb_led_index_t caps_lock_led;
- xkb_led_index_t num_lock_led;
- xkb_led_index_t scroll_lock_led;
- xkb_layout_index_t layout_idx;
- uint32_t button_state;
- int button_count[KEY_CNT];
-
- MetaBarrierManagerNative *barrier_manager;
- MetaPointerConstraintImpl *pointer_constraint;
-
- MetaKeymapNative *keymap;
- MetaInputSettings *input_settings;
-
- MetaViewportInfo *viewports;
-
- gboolean tablet_mode_switch_state;
- gboolean has_touchscreen;
- gboolean has_tablet_switch;
- gboolean has_pointer;
- gboolean touch_mode;
- gboolean input_thread_initialized;
-
- /* keyboard repeat */
- gboolean repeat;
- uint32_t repeat_delay;
- uint32_t repeat_interval;
- uint32_t repeat_key;
- uint32_t repeat_count;
- ClutterInputDevice *repeat_device;
- GSource *repeat_source;
-
- float pointer_x;
- float pointer_y;
-
- /* Emulation of discrete scroll events out of smooth ones */
- float accum_scroll_dx;
- float accum_scroll_dy;
-
- gboolean released;
-};
-
-#define META_TYPE_SEAT_IMPL meta_seat_impl_get_type ()
-G_DECLARE_FINAL_TYPE (MetaSeatImpl, meta_seat_impl,
- META, SEAT_IMPL, GObject)
-
-MetaSeatImpl * meta_seat_impl_new (MetaSeatNative *seat_native,
- const char *seat_id,
- MetaSeatNativeFlag flags);
-
-void meta_seat_impl_destroy (MetaSeatImpl *seat_impl);
-
-void meta_seat_impl_run_input_task (MetaSeatImpl *seat_impl,
- GTask *task,
- GSourceFunc dispatch_func);
-
-void meta_seat_impl_notify_key_in_impl (MetaSeatImpl *seat_impl,
- ClutterInputDevice *device,
- uint64_t time_us,
- uint32_t key,
- uint32_t state,
- gboolean update_keys);
-
-void meta_seat_impl_notify_relative_motion_in_impl (MetaSeatImpl *seat_impl,
- ClutterInputDevice *input_device,
- uint64_t time_us,
- float dx,
- float dy,
- float dx_unaccel,
- float dy_unaccel);
-
-void meta_seat_impl_notify_absolute_motion_in_impl (MetaSeatImpl *seat_impl,
- ClutterInputDevice *input_device,
- uint64_t time_us,
- float x,
- float y,
- double *axes);
-
-void meta_seat_impl_notify_button_in_impl (MetaSeatImpl *seat_impl,
- ClutterInputDevice *input_device,
- uint64_t time_us,
- uint32_t button,
- uint32_t state);
-
-void meta_seat_impl_notify_scroll_continuous_in_impl (MetaSeatImpl *seat_impl,
- ClutterInputDevice *input_device,
- uint64_t time_us,
- double dx,
- double dy,
- ClutterScrollSource source,
- ClutterScrollFinishFlags flags);
-
-void meta_seat_impl_notify_discrete_scroll_in_impl (MetaSeatImpl *seat_impl,
- ClutterInputDevice *input_device,
- uint64_t time_us,
- double discrete_dx,
- double discrete_dy,
- ClutterScrollSource source);
-
-void meta_seat_impl_notify_touch_event_in_impl (MetaSeatImpl *seat_impl,
- ClutterInputDevice *input_device,
- ClutterEventType evtype,
- uint64_t time_us,
- int slot,
- double x,
- double y);
-
-void meta_seat_impl_sync_leds_in_impl (MetaSeatImpl *seat_impl);
-
-MetaTouchState * meta_seat_impl_acquire_touch_state_in_impl (MetaSeatImpl *seat_impl,
- int seat_slot);
-MetaTouchState * meta_seat_impl_lookup_touch_state_in_impl (MetaSeatImpl *seat_impl,
- int seat_slot);
-void meta_seat_impl_release_touch_state_in_impl (MetaSeatImpl *seat_impl,
- int seat_slot);
-
-void meta_seat_impl_update_xkb_state_in_impl (MetaSeatImpl *seat_impl);
-
-void meta_seat_impl_release_devices (MetaSeatImpl *seat_impl);
-void meta_seat_impl_reclaim_devices (MetaSeatImpl *seat_impl);
-
-struct xkb_state * meta_seat_impl_get_xkb_state_in_impl (MetaSeatImpl *seat_impl);
-
-void meta_seat_impl_set_keyboard_map (MetaSeatImpl *seat_impl,
- struct xkb_keymap *keymap);
-
-void meta_seat_impl_set_keyboard_layout_index (MetaSeatImpl *seat_impl,
- xkb_layout_index_t idx);
-
-void meta_seat_impl_set_keyboard_repeat_in_impl (MetaSeatImpl *seat_impl,
- gboolean repeat,
- uint32_t delay,
- uint32_t interval);
-
-MetaBarrierManagerNative * meta_seat_impl_get_barrier_manager (MetaSeatImpl *seat_impl);
-
-void meta_seat_impl_set_pointer_constraint (MetaSeatImpl *seat_impl,
- MetaPointerConstraintImpl *constraint_impl);
-void meta_seat_impl_set_viewports (MetaSeatImpl *seat_impl,
- MetaViewportInfo *viewports);
-
-void meta_seat_impl_warp_pointer (MetaSeatImpl *seat_impl,
- int x,
- int y);
-gboolean meta_seat_impl_query_state (MetaSeatImpl *seat_impl,
- ClutterInputDevice *device,
- ClutterEventSequence *sequence,
- graphene_point_t *coords,
- ClutterModifierType *modifiers);
-ClutterInputDevice * meta_seat_impl_get_pointer (MetaSeatImpl *seat_impl);
-ClutterInputDevice * meta_seat_impl_get_keyboard (MetaSeatImpl *seat_impl);
-GSList * meta_seat_impl_get_devices_in_impl (MetaSeatImpl *seat_impl);
-
-MetaKeymapNative * meta_seat_impl_get_keymap (MetaSeatImpl *seat_impl);
-
-void meta_seat_impl_notify_kbd_a11y_flags_changed_in_impl (MetaSeatImpl *seat_impl,
- MetaKeyboardA11yFlags new_flags,
- MetaKeyboardA11yFlags what_changed);
-void meta_seat_impl_notify_kbd_a11y_mods_state_changed_in_impl (MetaSeatImpl *seat_impl,
- xkb_mod_mask_t new_latched_mods,
- xkb_mod_mask_t new_locked_mods);
-void meta_seat_impl_notify_bell_in_impl (MetaSeatImpl *seat_impl);
-
-MetaInputSettings * meta_seat_impl_get_input_settings (MetaSeatImpl *seat_impl);
-
-void meta_seat_impl_queue_main_thread_idle (MetaSeatImpl *seat_impl,
- GSourceFunc func,
- gpointer user_data,
- GDestroyNotify destroy_notify);
-
-#endif /* META_SEAT_IMPL_H */
diff --git a/src/backends/native/meta-seat-native.c b/src/backends/native/meta-seat-native.c
deleted file mode 100644
index 12fead1fb..000000000
--- a/src/backends/native/meta-seat-native.c
+++ /dev/null
@@ -1,634 +0,0 @@
-/*
- * Clutter.
- *
- * An OpenGL based 'interactive canvas' library.
- *
- * Copyright (C) 2010 Intel Corp.
- * Copyright (C) 2014 Jonas Ådahl
- * Copyright (C) 2016 Red Hat Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
- *
- * Author: Damien Lespiau <damien.lespiau@intel.com>
- * Author: Jonas Ådahl <jadahl@gmail.com>
- */
-
-#include "config.h"
-
-#include "backends/native/meta-seat-native.h"
-
-#include "backends/meta-cursor-tracker-private.h"
-#include "backends/meta-keymap-utils.h"
-#include "backends/native/meta-barrier-native.h"
-#include "backends/native/meta-input-thread.h"
-#include "backends/native/meta-keymap-native.h"
-#include "backends/native/meta-virtual-input-device-native.h"
-#include "clutter/clutter-mutter.h"
-#include "core/bell.h"
-
-#include "meta-private-enum-types.h"
-
-enum
-{
- PROP_0,
- PROP_SEAT_ID,
- PROP_FLAGS,
- PROP_BACKEND,
- N_PROPS,
-
- /* This property is overridden */
- PROP_TOUCH_MODE,
-};
-
-static GParamSpec *props[N_PROPS] = { NULL };
-
-G_DEFINE_TYPE (MetaSeatNative, meta_seat_native, CLUTTER_TYPE_SEAT)
-
-static gboolean
-meta_seat_native_handle_event_post (ClutterSeat *seat,
- const ClutterEvent *event)
-{
- MetaSeatNative *seat_native = META_SEAT_NATIVE (seat);
- ClutterInputDevice *device = clutter_event_get_source_device (event);
- ClutterEventType event_type = event->type;
-
- if (event_type == CLUTTER_PROXIMITY_IN)
- {
- MetaCursorRenderer *cursor_renderer;
-
- if (!seat_native->tablet_cursors)
- {
- seat_native->tablet_cursors = g_hash_table_new_full (NULL, NULL, NULL,
- g_object_unref);
- }
-
- cursor_renderer = meta_cursor_renderer_new (meta_get_backend (), device);
- g_hash_table_insert (seat_native->tablet_cursors,
- device, cursor_renderer);
- return TRUE;
- }
- else if (event_type == CLUTTER_PROXIMITY_OUT)
- {
- if (seat_native->tablet_cursors)
- g_hash_table_remove (seat_native->tablet_cursors, device);
- return TRUE;
- }
- else if (event_type == CLUTTER_DEVICE_ADDED)
- {
- if (clutter_input_device_get_device_mode (device) != CLUTTER_INPUT_MODE_LOGICAL)
- seat_native->devices = g_list_prepend (seat_native->devices, g_object_ref (device));
- }
- else if (event_type == CLUTTER_DEVICE_REMOVED)
- {
- GList *l = g_list_find (seat_native->devices, device);
-
- if (l)
- {
- seat_native->devices = g_list_delete_link (seat_native->devices, l);
- g_object_unref (device);
- }
- }
-
- return FALSE;
-}
-
-static void
-proxy_kbd_a11y_flags_changed (MetaSeatImpl *seat_impl,
- MetaKeyboardA11yFlags new_flags,
- MetaKeyboardA11yFlags what_changed,
- MetaSeatNative *seat_native)
-{
- g_signal_emit_by_name (seat_native,
- "kbd-a11y-flags-changed",
- new_flags, what_changed);
-}
-
-static void
-proxy_kbd_a11y_mods_state_changed (MetaSeatImpl *seat_impl,
- xkb_mod_mask_t new_latched_mods,
- xkb_mod_mask_t new_locked_mods,
- MetaSeatNative *seat_native)
-{
- g_signal_emit_by_name (seat_native,
- "kbd-a11y-mods-state-changed",
- new_latched_mods,
- new_locked_mods);
-}
-
-static void
-proxy_touch_mode_changed (MetaSeatImpl *seat_impl,
- gboolean enabled,
- MetaSeatNative *seat_native)
-{
- seat_native->touch_mode = enabled;
- g_object_notify (G_OBJECT (seat_native), "touch-mode");
-}
-
-static void
-proxy_bell (MetaSeatImpl *seat_impl,
- MetaSeatNative *seat_native)
-{
- clutter_seat_bell_notify (CLUTTER_SEAT (seat_native));
-}
-
-static void
-proxy_mods_state_changed (MetaSeatImpl *seat_impl,
- ClutterSeat *seat)
-{
- ClutterKeymap *keymap;
-
- keymap = clutter_seat_get_keymap (seat);
- g_signal_emit_by_name (keymap, "state-changed");
-}
-
-static void
-meta_seat_native_constructed (GObject *object)
-{
- MetaSeatNative *seat = META_SEAT_NATIVE (object);
-
- seat->impl = meta_seat_impl_new (seat, seat->seat_id, seat->flags);
- g_signal_connect (seat->impl, "kbd-a11y-flags-changed",
- G_CALLBACK (proxy_kbd_a11y_flags_changed), seat);
- g_signal_connect (seat->impl, "kbd-a11y-mods-state-changed",
- G_CALLBACK (proxy_kbd_a11y_mods_state_changed), seat);
- g_signal_connect (seat->impl, "touch-mode",
- G_CALLBACK (proxy_touch_mode_changed), seat);
- g_signal_connect (seat->impl, "bell",
- G_CALLBACK (proxy_bell), seat);
- g_signal_connect (seat->impl, "mods-state-changed",
- G_CALLBACK (proxy_mods_state_changed), seat);
-
- seat->core_pointer = meta_seat_impl_get_pointer (seat->impl);
- seat->core_keyboard = meta_seat_impl_get_keyboard (seat->impl);
-
- meta_seat_native_set_keyboard_map (seat, "us", "", "");
-
- if (G_OBJECT_CLASS (meta_seat_native_parent_class)->constructed)
- G_OBJECT_CLASS (meta_seat_native_parent_class)->constructed (object);
-}
-
-static void
-meta_seat_native_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- MetaSeatNative *seat_native = META_SEAT_NATIVE (object);
-
- switch (prop_id)
- {
- case PROP_SEAT_ID:
- seat_native->seat_id = g_value_dup_string (value);
- break;
- case PROP_FLAGS:
- seat_native->flags = g_value_get_flags (value);
- break;
- case PROP_BACKEND:
- seat_native->backend = g_value_get_object (value);
- break;
- case PROP_TOUCH_MODE:
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- }
-}
-
-static void
-meta_seat_native_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- MetaSeatNative *seat_native = META_SEAT_NATIVE (object);
-
- switch (prop_id)
- {
- case PROP_SEAT_ID:
- g_value_set_string (value, seat_native->seat_id);
- break;
- case PROP_TOUCH_MODE:
- g_value_set_boolean (value, seat_native->touch_mode);
- break;
- case PROP_FLAGS:
- g_value_set_flags (value, seat_native->flags);
- break;
- case PROP_BACKEND:
- g_value_set_object (value, seat_native->backend);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- }
-}
-
-static void
-meta_seat_native_dispose (GObject *object)
-{
- MetaSeatNative *seat = META_SEAT_NATIVE (object);
-
- g_clear_pointer (&seat->xkb_keymap, xkb_keymap_unref);
- g_clear_object (&seat->core_pointer);
- g_clear_object (&seat->core_keyboard);
- g_clear_pointer (&seat->impl, meta_seat_impl_destroy);
- g_list_free_full (g_steal_pointer (&seat->devices), g_object_unref);
- g_clear_pointer (&seat->reserved_virtual_slots, g_hash_table_destroy);
- g_clear_pointer (&seat->tablet_cursors, g_hash_table_unref);
- g_clear_object (&seat->cursor_renderer);
-
- g_clear_pointer (&seat->seat_id, g_free);
-
- G_OBJECT_CLASS (meta_seat_native_parent_class)->dispose (object);
-}
-
-static ClutterInputDevice *
-meta_seat_native_get_pointer (ClutterSeat *seat)
-{
- MetaSeatNative *seat_native = META_SEAT_NATIVE (seat);
-
- return seat_native->core_pointer;
-}
-
-static ClutterInputDevice *
-meta_seat_native_get_keyboard (ClutterSeat *seat)
-{
- MetaSeatNative *seat_native = META_SEAT_NATIVE (seat);
-
- return seat_native->core_keyboard;
-}
-
-static const GList *
-meta_seat_native_peek_devices (ClutterSeat *seat)
-{
- MetaSeatNative *seat_native = META_SEAT_NATIVE (seat);
-
- return (const GList *) seat_native->devices;
-}
-
-static void
-meta_seat_native_bell_notify (ClutterSeat *seat)
-{
- MetaDisplay *display = meta_get_display ();
-
- meta_bell_notify (display, NULL);
-}
-
-static ClutterKeymap *
-meta_seat_native_get_keymap (ClutterSeat *seat)
-{
- MetaSeatNative *seat_native = META_SEAT_NATIVE (seat);
-
- if (!seat_native->keymap)
- seat_native->keymap = meta_seat_impl_get_keymap (seat_native->impl);
-
- return CLUTTER_KEYMAP (seat_native->keymap);
-}
-
-static guint
-bump_virtual_touch_slot_base (MetaSeatNative *seat_native)
-{
- while (TRUE)
- {
- if (seat_native->virtual_touch_slot_base < 0x100)
- seat_native->virtual_touch_slot_base = 0x100;
-
- seat_native->virtual_touch_slot_base +=
- CLUTTER_VIRTUAL_INPUT_DEVICE_MAX_TOUCH_SLOTS;
-
- if (!g_hash_table_lookup (seat_native->reserved_virtual_slots,
- GUINT_TO_POINTER (seat_native->virtual_touch_slot_base)))
- break;
- }
-
- return seat_native->virtual_touch_slot_base;
-}
-
-static ClutterVirtualInputDevice *
-meta_seat_native_create_virtual_device (ClutterSeat *seat,
- ClutterInputDeviceType device_type)
-{
- MetaSeatNative *seat_native = META_SEAT_NATIVE (seat);
- guint slot_base;
-
- slot_base = bump_virtual_touch_slot_base (seat_native);
- g_hash_table_add (seat_native->reserved_virtual_slots,
- GUINT_TO_POINTER (slot_base));
-
- return g_object_new (META_TYPE_VIRTUAL_INPUT_DEVICE_NATIVE,
- "seat", seat,
- "slot-base", slot_base,
- "device-type", device_type,
- NULL);
-}
-
-void
-meta_seat_native_release_touch_slots (MetaSeatNative *seat,
- guint base_slot)
-{
- g_hash_table_remove (seat->reserved_virtual_slots,
- GUINT_TO_POINTER (base_slot));
-}
-
-static ClutterVirtualDeviceType
-meta_seat_native_get_supported_virtual_device_types (ClutterSeat *seat)
-{
- return (CLUTTER_VIRTUAL_DEVICE_TYPE_KEYBOARD |
- CLUTTER_VIRTUAL_DEVICE_TYPE_POINTER |
- CLUTTER_VIRTUAL_DEVICE_TYPE_TOUCHSCREEN);
-}
-
-static void
-meta_seat_native_warp_pointer (ClutterSeat *seat,
- int x,
- int y)
-{
- MetaSeatNative *seat_native = META_SEAT_NATIVE (seat);
-
- meta_seat_impl_warp_pointer (seat_native->impl, x, y);
-}
-
-static gboolean
-meta_seat_native_query_state (ClutterSeat *seat,
- ClutterInputDevice *device,
- ClutterEventSequence *sequence,
- graphene_point_t *coords,
- ClutterModifierType *modifiers)
-{
- MetaSeatNative *seat_native = META_SEAT_NATIVE (seat);
-
- return meta_seat_impl_query_state (seat_native->impl, device, sequence,
- coords, modifiers);
-}
-
-static void
-meta_seat_native_class_init (MetaSeatNativeClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
- ClutterSeatClass *seat_class = CLUTTER_SEAT_CLASS (klass);
-
- object_class->constructed = meta_seat_native_constructed;
- object_class->set_property = meta_seat_native_set_property;
- object_class->get_property = meta_seat_native_get_property;
- object_class->dispose = meta_seat_native_dispose;
-
- seat_class->get_pointer = meta_seat_native_get_pointer;
- seat_class->get_keyboard = meta_seat_native_get_keyboard;
- seat_class->peek_devices = meta_seat_native_peek_devices;
- seat_class->bell_notify = meta_seat_native_bell_notify;
- seat_class->get_keymap = meta_seat_native_get_keymap;
- seat_class->create_virtual_device = meta_seat_native_create_virtual_device;
- seat_class->get_supported_virtual_device_types = meta_seat_native_get_supported_virtual_device_types;
- seat_class->warp_pointer = meta_seat_native_warp_pointer;
- seat_class->handle_event_post = meta_seat_native_handle_event_post;
- seat_class->query_state = meta_seat_native_query_state;
-
- props[PROP_SEAT_ID] =
- g_param_spec_string ("seat-id",
- "Seat ID",
- "Seat ID",
- NULL,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT_ONLY);
-
- props[PROP_FLAGS] =
- g_param_spec_flags ("flags",
- "Flags",
- "Flags",
- META_TYPE_SEAT_NATIVE_FLAG,
- META_SEAT_NATIVE_FLAG_NONE,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT_ONLY);
-
- props[PROP_BACKEND] =
- g_param_spec_object ("backend",
- "Backend",
- "Backend",
- META_TYPE_BACKEND,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT_ONLY);
-
- g_object_class_install_properties (object_class, N_PROPS, props);
-
- g_object_class_override_property (object_class, PROP_TOUCH_MODE,
- "touch-mode");
-}
-
-static void
-meta_seat_native_init (MetaSeatNative *seat)
-{
- seat->reserved_virtual_slots = g_hash_table_new (NULL, NULL);
-}
-
-/**
- * meta_seat_native_release_devices:
- *
- * Releases all the evdev devices that Clutter is currently managing. This api
- * is typically used when switching away from the Clutter application when
- * switching tty. The devices can be reclaimed later with a call to
- * meta_seat_native_reclaim_devices().
- *
- * This function should only be called after clutter has been initialized.
- */
-void
-meta_seat_native_release_devices (MetaSeatNative *seat)
-{
- g_return_if_fail (META_IS_SEAT_NATIVE (seat));
-
- if (seat->released)
- {
- g_warning ("meta_seat_native_release_devices() shouldn't be called "
- "multiple times without a corresponding call to "
- "meta_seat_native_reclaim_devices() first");
- return;
- }
-
- meta_seat_impl_release_devices (seat->impl);
- seat->released = TRUE;
-}
-
-/**
- * meta_seat_native_reclaim_devices:
- *
- * This causes Clutter to re-probe for evdev devices. This is must only be
- * called after a corresponding call to meta_seat_native_release_devices()
- * was previously used to release all evdev devices. This API is typically
- * used when a clutter application using evdev has regained focus due to
- * switching ttys.
- *
- * This function should only be called after clutter has been initialized.
- */
-void
-meta_seat_native_reclaim_devices (MetaSeatNative *seat)
-{
- if (!seat->released)
- {
- g_warning ("Spurious call to meta_seat_native_reclaim_devices() without "
- "previous call to meta_seat_native_release_devices");
- return;
- }
-
- meta_seat_impl_reclaim_devices (seat->impl);
- seat->released = FALSE;
-}
-
-static struct xkb_keymap *
-create_keymap (const char *layouts,
- const char *variants,
- const char *options)
-{
- struct xkb_rule_names names;
- struct xkb_keymap *keymap;
- struct xkb_context *context;
-
- names.rules = DEFAULT_XKB_RULES_FILE;
- names.model = DEFAULT_XKB_MODEL;
- names.layout = layouts;
- names.variant = variants;
- names.options = options;
-
- context = meta_create_xkb_context ();
- keymap = xkb_keymap_new_from_names (context, &names, XKB_KEYMAP_COMPILE_NO_FLAGS);
- xkb_context_unref (context);
-
- return keymap;
-}
-
-/**
- * meta_seat_native_set_keyboard_map: (skip)
- * @seat: the #ClutterSeat created by the evdev backend
- * @keymap: the new keymap
- *
- * Instructs @evdev to use the specified keyboard map. This will cause
- * the backend to drop the state and create a new one with the new
- * map. To avoid state being lost, callers should ensure that no key
- * is pressed when calling this function.
- */
-void
-meta_seat_native_set_keyboard_map (MetaSeatNative *seat,
- const char *layouts,
- const char *variants,
- const char *options)
-{
- struct xkb_keymap *keymap, *impl_keymap;
-
- keymap = create_keymap (layouts, variants, options);
- impl_keymap = create_keymap (layouts, variants, options);
-
- if (keymap == NULL)
- {
- g_warning ("Unable to load configured keymap: rules=%s, model=%s, layout=%s, variant=%s, options=%s",
- DEFAULT_XKB_RULES_FILE, DEFAULT_XKB_MODEL, layouts,
- variants, options);
- return;
- }
-
- if (seat->xkb_keymap)
- xkb_keymap_unref (seat->xkb_keymap);
- seat->xkb_keymap = keymap;
-
- meta_seat_impl_set_keyboard_map (seat->impl, impl_keymap);
- xkb_keymap_unref (impl_keymap);
-}
-
-/**
- * meta_seat_native_get_keyboard_map: (skip)
- * @seat: the #ClutterSeat created by the evdev backend
- *
- * Retrieves the #xkb_keymap in use by the evdev backend.
- *
- * Return value: the #xkb_keymap.
- */
-struct xkb_keymap *
-meta_seat_native_get_keyboard_map (MetaSeatNative *seat)
-{
- g_return_val_if_fail (META_IS_SEAT_NATIVE (seat), NULL);
-
- return seat->xkb_keymap;
-}
-
-/**
- * meta_seat_native_set_keyboard_layout_index: (skip)
- * @seat: the #ClutterSeat created by the evdev backend
- * @idx: the xkb layout index to set
- *
- * Sets the xkb layout index on the backend's #xkb_state .
- */
-void
-meta_seat_native_set_keyboard_layout_index (MetaSeatNative *seat,
- xkb_layout_index_t idx)
-{
- g_return_if_fail (META_IS_SEAT_NATIVE (seat));
-
- seat->xkb_layout_index = idx;
- meta_seat_impl_set_keyboard_layout_index (seat->impl, idx);
-}
-
-/**
- * meta_seat_native_get_keyboard_layout_index: (skip)
- */
-xkb_layout_index_t
-meta_seat_native_get_keyboard_layout_index (MetaSeatNative *seat)
-{
- return seat->xkb_layout_index;
-}
-
-MetaBarrierManagerNative *
-meta_seat_native_get_barrier_manager (MetaSeatNative *seat)
-{
- return meta_seat_impl_get_barrier_manager (seat->impl);
-}
-
-MetaBackend *
-meta_seat_native_get_backend (MetaSeatNative *seat_native)
-{
- return seat_native->backend;
-}
-
-void
-meta_seat_native_set_pointer_constraint (MetaSeatNative *seat,
- MetaPointerConstraintImpl *constraint_impl)
-{
- meta_seat_impl_set_pointer_constraint (seat->impl, constraint_impl);
-}
-
-MetaCursorRenderer *
-meta_seat_native_maybe_ensure_cursor_renderer (MetaSeatNative *seat_native,
- ClutterInputDevice *device)
-{
- if (device == seat_native->core_pointer)
- {
- if (!seat_native->cursor_renderer)
- {
- MetaCursorRendererNative *cursor_renderer_native;
-
- cursor_renderer_native =
- meta_cursor_renderer_native_new (meta_get_backend (),
- seat_native->core_pointer);
- seat_native->cursor_renderer =
- META_CURSOR_RENDERER (cursor_renderer_native);
- }
-
- return seat_native->cursor_renderer;
- }
-
- if (seat_native->tablet_cursors &&
- clutter_input_device_get_device_type (device) == CLUTTER_TABLET_DEVICE)
- return g_hash_table_lookup (seat_native->tablet_cursors, device);
-
- return NULL;
-}
-
-void
-meta_seat_native_set_viewports (MetaSeatNative *seat,
- MetaViewportInfo *viewports)
-{
- meta_seat_impl_set_viewports (seat->impl, viewports);
-}
diff --git a/src/backends/native/meta-seat-native.h b/src/backends/native/meta-seat-native.h
deleted file mode 100644
index 53ba00f51..000000000
--- a/src/backends/native/meta-seat-native.h
+++ /dev/null
@@ -1,133 +0,0 @@
-/*
- * Copyright (C) 2010 Intel Corp.
- * Copyright (C) 2014 Jonas Ådahl
- * Copyright (C) 2016 Red Hat Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
- *
- * Author: Damien Lespiau <damien.lespiau@intel.com>
- * Author: Jonas Ådahl <jadahl@gmail.com>
- */
-
-#ifndef META_SEAT_NATIVE_H
-#define META_SEAT_NATIVE_H
-
-#include <gudev/gudev.h>
-#include <libinput.h>
-#include <linux/input-event-codes.h>
-
-#include "backends/meta-input-settings-private.h"
-#include "backends/meta-viewport-info.h"
-#include "backends/native/meta-backend-native-types.h"
-#include "backends/native/meta-barrier-native.h"
-#include "backends/native/meta-cursor-renderer-native.h"
-#include "backends/native/meta-pointer-constraint-native.h"
-#include "backends/native/meta-xkb-utils.h"
-#include "clutter/clutter.h"
-
-typedef struct _MetaSeatNative MetaSeatNative;
-
-struct _MetaSeatNative
-{
- ClutterSeat parent_instance;
-
- MetaBackend *backend;
-
- MetaSeatImpl *impl;
- char *seat_id;
- MetaSeatNativeFlag flags;
-
- GList *devices;
- struct xkb_keymap *xkb_keymap;
- xkb_layout_index_t xkb_layout_index;
-
- ClutterInputDevice *core_pointer;
- ClutterInputDevice *core_keyboard;
-
- guint virtual_touch_slot_base;
- GHashTable *reserved_virtual_slots;
-
- MetaKeymapNative *keymap;
- MetaCursorRenderer *cursor_renderer;
- GHashTable *tablet_cursors;
-
- gboolean released;
- gboolean touch_mode;
-};
-
-#define META_TYPE_SEAT_NATIVE meta_seat_native_get_type ()
-G_DECLARE_FINAL_TYPE (MetaSeatNative, meta_seat_native,
- META, SEAT_NATIVE, ClutterSeat)
-
-void meta_seat_native_set_libinput_seat (MetaSeatNative *seat,
- struct libinput_seat *libinput_seat);
-
-void meta_seat_native_sync_leds (MetaSeatNative *seat);
-
-/**
- * MetaOpenDeviceCallback:
- * @path: the device path
- * @flags: flags to be passed to open
- *
- * This callback will be called when Clutter needs to access an input
- * device. It should return an open file descriptor for the file at @path,
- * or -1 if opening failed.
- */
-typedef int (* MetaOpenDeviceCallback) (const char *path,
- int flags,
- gpointer user_data,
- GError **error);
-typedef void (* MetaCloseDeviceCallback) (int fd,
- gpointer user_data);
-
-void meta_seat_native_set_device_callbacks (MetaOpenDeviceCallback open_callback,
- MetaCloseDeviceCallback close_callback,
- gpointer user_data);
-
-void meta_seat_native_release_devices (MetaSeatNative *seat);
-void meta_seat_native_reclaim_devices (MetaSeatNative *seat);
-
-void meta_seat_native_set_keyboard_map (MetaSeatNative *seat,
- const char *layouts,
- const char *variants,
- const char *options);
-
-struct xkb_keymap * meta_seat_native_get_keyboard_map (MetaSeatNative *seat);
-
-void meta_seat_native_set_keyboard_layout_index (MetaSeatNative *seat,
- xkb_layout_index_t idx);
-
-xkb_layout_index_t meta_seat_native_get_keyboard_layout_index (MetaSeatNative *seat);
-
-void meta_seat_native_set_keyboard_repeat (MetaSeatNative *seat,
- gboolean repeat,
- uint32_t delay,
- uint32_t interval);
-
-void meta_seat_native_release_touch_slots (MetaSeatNative *seat,
- guint base_slot);
-
-MetaBarrierManagerNative * meta_seat_native_get_barrier_manager (MetaSeatNative *seat);
-
-MetaBackend * meta_seat_native_get_backend (MetaSeatNative *seat);
-
-void meta_seat_native_set_pointer_constraint (MetaSeatNative *seat,
- MetaPointerConstraintImpl *constraint_impl);
-MetaCursorRenderer * meta_seat_native_maybe_ensure_cursor_renderer (MetaSeatNative *seat,
- ClutterInputDevice *device);
-
-void meta_seat_native_set_viewports (MetaSeatNative *seat,
- MetaViewportInfo *viewports);
-
-#endif /* META_SEAT_NATIVE_H */
diff --git a/src/backends/native/meta-stage-native.c b/src/backends/native/meta-stage-native.c
deleted file mode 100644
index e1f9fedb2..000000000
--- a/src/backends/native/meta-stage-native.c
+++ /dev/null
@@ -1,191 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2016 Red Hat Inc.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Written by:
- * Jonas Ådahl <jadahl@gmail.com>
- */
-
-#include "config.h"
-
-#include "backends/native/meta-stage-native.h"
-
-#include "backends/meta-backend-private.h"
-#include "backends/native/meta-crtc-virtual.h"
-#include "backends/native/meta-cursor-renderer-native.h"
-#include "backends/native/meta-renderer-native.h"
-#include "meta/meta-backend.h"
-#include "meta/meta-monitor-manager.h"
-#include "meta/util.h"
-
-static GQuark quark_view_frame_closure = 0;
-
-struct _MetaStageNative
-{
- MetaStageImpl parent;
-
- CoglClosure *frame_closure;
-
- int64_t presented_frame_counter_sync;
- int64_t presented_frame_counter_complete;
-};
-
-static ClutterStageWindowInterface *clutter_stage_window_parent_iface = NULL;
-
-static void
-clutter_stage_window_iface_init (ClutterStageWindowInterface *iface);
-
-G_DEFINE_TYPE_WITH_CODE (MetaStageNative, meta_stage_native,
- META_TYPE_STAGE_IMPL,
- G_IMPLEMENT_INTERFACE (CLUTTER_TYPE_STAGE_WINDOW,
- clutter_stage_window_iface_init))
-
-void
-meta_stage_native_rebuild_views (MetaStageNative *stage_native)
-{
- MetaBackend *backend = meta_get_backend ();
- MetaRenderer *renderer = meta_backend_get_renderer (backend);
- ClutterActor *stage = meta_backend_get_stage (backend);
-
- meta_renderer_rebuild_views (renderer);
- clutter_stage_clear_stage_views (CLUTTER_STAGE (stage));
-}
-
-static gboolean
-meta_stage_native_can_clip_redraws (ClutterStageWindow *stage_window)
-{
- return TRUE;
-}
-
-static void
-meta_stage_native_get_geometry (ClutterStageWindow *stage_window,
- cairo_rectangle_int_t *geometry)
-{
- MetaBackend *backend = meta_get_backend ();
- MetaMonitorManager *monitor_manager =
- meta_backend_get_monitor_manager (backend);
-
- if (monitor_manager)
- {
- int width, height;
-
- meta_monitor_manager_get_screen_size (monitor_manager, &width, &height);
- *geometry = (cairo_rectangle_int_t) {
- .width = width,
- .height = height,
- };
- }
- else
- {
- *geometry = (cairo_rectangle_int_t) {
- .width = 1,
- .height = 1,
- };
- }
-}
-
-static GList *
-meta_stage_native_get_views (ClutterStageWindow *stage_window)
-{
- MetaBackend *backend = meta_get_backend ();
- MetaRenderer *renderer = meta_backend_get_renderer (backend);
-
- return meta_renderer_get_views (renderer);
-}
-
-static void
-meta_stage_native_prepare_frame (ClutterStageWindow *stage_window,
- ClutterStageView *stage_view,
- ClutterFrame *frame)
-{
- MetaBackend *backend = meta_get_backend ();
- MetaRenderer *renderer = meta_backend_get_renderer (backend);
- MetaRendererNative *renderer_native = META_RENDERER_NATIVE (renderer);
- MetaCursorRenderer *cursor_renderer =
- meta_backend_get_cursor_renderer (backend);
- MetaCursorRendererNative *cursor_renderer_native =
- META_CURSOR_RENDERER_NATIVE (cursor_renderer);
-
- meta_renderer_native_prepare_frame (renderer_native,
- META_RENDERER_VIEW (stage_view),
- frame);
- meta_cursor_renderer_native_prepare_frame (cursor_renderer_native,
- META_RENDERER_VIEW (stage_view));
-}
-
-static void
-meta_stage_native_redraw_view (ClutterStageWindow *stage_window,
- ClutterStageView *view,
- ClutterFrame *frame)
-{
- MetaCrtc *crtc;
-
- clutter_stage_window_parent_iface->redraw_view (stage_window, view, frame);
-
- crtc = meta_renderer_view_get_crtc (META_RENDERER_VIEW (view));
- if (META_IS_CRTC_VIRTUAL (crtc))
- {
- g_warn_if_fail (!clutter_frame_has_result (frame));
-
- clutter_frame_set_result (frame, CLUTTER_FRAME_RESULT_PENDING_PRESENTED);
- }
-}
-
-static void
-meta_stage_native_finish_frame (ClutterStageWindow *stage_window,
- ClutterStageView *stage_view,
- ClutterFrame *frame)
-{
- MetaBackend *backend = meta_get_backend ();
- MetaRenderer *renderer = meta_backend_get_renderer (backend);
-
- meta_renderer_native_finish_frame (META_RENDERER_NATIVE (renderer),
- META_RENDERER_VIEW (stage_view),
- frame);
-
- if (!clutter_frame_has_result (frame))
- clutter_frame_set_result (frame, CLUTTER_FRAME_RESULT_IDLE);
-}
-
-static void
-meta_stage_native_init (MetaStageNative *stage_native)
-{
- stage_native->presented_frame_counter_sync = -1;
- stage_native->presented_frame_counter_complete = -1;
-}
-
-static void
-meta_stage_native_class_init (MetaStageNativeClass *klass)
-{
- quark_view_frame_closure =
- g_quark_from_static_string ("-meta-native-stage-view-frame-closure");
-}
-
-static void
-clutter_stage_window_iface_init (ClutterStageWindowInterface *iface)
-{
- clutter_stage_window_parent_iface = g_type_interface_peek_parent (iface);
-
- iface->can_clip_redraws = meta_stage_native_can_clip_redraws;
- iface->get_geometry = meta_stage_native_get_geometry;
- iface->get_views = meta_stage_native_get_views;
- iface->prepare_frame = meta_stage_native_prepare_frame;
- iface->redraw_view = meta_stage_native_redraw_view;
- iface->finish_frame = meta_stage_native_finish_frame;
-}
diff --git a/src/backends/native/meta-stage-native.h b/src/backends/native/meta-stage-native.h
deleted file mode 100644
index 5f33e1f9a..000000000
--- a/src/backends/native/meta-stage-native.h
+++ /dev/null
@@ -1,37 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2016 Red Hat Inc.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Written by:
- * Jonas Ådahl <jadahl@gmail.com>
- */
-
-#ifndef META_STAGE_NATIVE_H
-#define META_STAGE_NATIVE_H
-
-#include "backends/meta-stage-impl-private.h"
-#include "clutter/clutter-mutter.h"
-
-#define META_TYPE_STAGE_NATIVE (meta_stage_native_get_type ())
-G_DECLARE_FINAL_TYPE (MetaStageNative, meta_stage_native,
- META, STAGE_NATIVE, MetaStageImpl)
-
-void meta_stage_native_rebuild_views (MetaStageNative *stage_native);
-
-#endif /* META_STAGE_NATIVE_H */
diff --git a/src/backends/native/meta-udev.c b/src/backends/native/meta-udev.c
deleted file mode 100644
index 9fd84e98b..000000000
--- a/src/backends/native/meta-udev.c
+++ /dev/null
@@ -1,274 +0,0 @@
-/*
- * Copyright (C) 2018 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- */
-
-#include "config.h"
-
-#include "backends/native/meta-udev.h"
-
-#include "backends/native/meta-backend-native.h"
-#include "backends/native/meta-launcher.h"
-
-#define DRM_CARD_UDEV_DEVICE_TYPE "drm_minor"
-
-enum
-{
- HOTPLUG,
- DEVICE_ADDED,
- DEVICE_REMOVED,
-
- N_SIGNALS
-};
-
-static guint signals[N_SIGNALS];
-
-struct _MetaUdev
-{
- GObject parent;
-
- MetaBackendNative *backend_native;
-
- GUdevClient *gudev_client;
-
- gulong uevent_handler_id;
-};
-
-G_DEFINE_TYPE (MetaUdev, meta_udev, G_TYPE_OBJECT)
-
-gboolean
-meta_is_udev_device_platform_device (GUdevDevice *device)
-{
- g_autoptr (GUdevDevice) platform_device = NULL;
-
- platform_device = g_udev_device_get_parent_with_subsystem (device,
- "platform",
- NULL);
- return !!platform_device;
-}
-
-gboolean
-meta_is_udev_device_boot_vga (GUdevDevice *device)
-{
- g_autoptr (GUdevDevice) pci_device = NULL;
-
- pci_device = g_udev_device_get_parent_with_subsystem (device, "pci", NULL);
- if (!pci_device)
- return FALSE;
-
- return g_udev_device_get_sysfs_attr_as_int (pci_device, "boot_vga") == 1;
-}
-
-static gboolean
-meta_has_udev_device_tag (GUdevDevice *device,
- const char *tag)
-{
- const char * const * tags;
- g_autoptr (GUdevDevice) platform_device = NULL;
-
- tags = g_udev_device_get_tags (device);
- if (tags && g_strv_contains (tags, tag))
- return TRUE;
-
- platform_device = g_udev_device_get_parent_with_subsystem (device,
- "platform",
- NULL);
-
- if (platform_device)
- return meta_has_udev_device_tag (platform_device, tag);
- else
- return FALSE;
-}
-
-gboolean
-meta_is_udev_device_disable_modifiers (GUdevDevice *device)
-{
- return meta_has_udev_device_tag (device,
- "mutter-device-disable-kms-modifiers");
-}
-
-gboolean
-meta_is_udev_device_ignore (GUdevDevice *device)
-{
- return meta_has_udev_device_tag (device, "mutter-device-ignore");
-}
-
-gboolean
-meta_is_udev_device_preferred_primary (GUdevDevice *device)
-{
- const char * const * tags;
-
- tags = g_udev_device_get_tags (device);
- if (!tags)
- return FALSE;
-
- return g_strv_contains (tags, "mutter-device-preferred-primary");
-}
-
-gboolean
-meta_udev_is_drm_device (MetaUdev *udev,
- GUdevDevice *device)
-{
- const char *seat_id;
- const char *device_type;
- const char *device_seat;
-
- /* Filter out devices that are not character device, like card0-VGA-1. */
- if (g_udev_device_get_device_type (device) != G_UDEV_DEVICE_TYPE_CHAR)
- return FALSE;
-
- device_type = g_udev_device_get_property (device, "DEVTYPE");
- if (g_strcmp0 (device_type, DRM_CARD_UDEV_DEVICE_TYPE) != 0)
- return FALSE;
-
- device_seat = g_udev_device_get_property (device, "ID_SEAT");
- if (!device_seat)
- {
- /* When ID_SEAT is not set, it means seat0. */
- device_seat = "seat0";
- }
-
- /* Skip devices that do not belong to our seat. */
- seat_id = meta_backend_native_get_seat_id (udev->backend_native);
- if (g_strcmp0 (seat_id, device_seat))
- return FALSE;
-
- return TRUE;
-}
-
-GList *
-meta_udev_list_drm_devices (MetaUdev *udev,
- GError **error)
-{
- g_autoptr (GUdevEnumerator) enumerator = NULL;
- GList *devices;
- GList *l;
-
- enumerator = g_udev_enumerator_new (udev->gudev_client);
-
- g_udev_enumerator_add_match_name (enumerator, "card*");
- g_udev_enumerator_add_match_tag (enumerator, "seat");
-
- /*
- * We need to explicitly match the subsystem for now.
- * https://bugzilla.gnome.org/show_bug.cgi?id=773224
- */
- g_udev_enumerator_add_match_subsystem (enumerator, "drm");
-
- devices = g_udev_enumerator_execute (enumerator);
- if (!devices)
- return NULL;
-
- for (l = devices; l;)
- {
- GUdevDevice *device = l->data;
- GList *l_next = l->next;
-
- if (!meta_udev_is_drm_device (udev, device))
- {
- g_object_unref (device);
- devices = g_list_delete_link (devices, l);
- }
-
- l = l_next;
- }
-
- return devices;
-}
-
-static void
-on_uevent (GUdevClient *client,
- const char *action,
- GUdevDevice *device,
- gpointer user_data)
-{
- MetaUdev *udev = META_UDEV (user_data);
-
- if (!g_udev_device_get_device_file (device))
- return;
-
- if (g_str_equal (action, "add"))
- g_signal_emit (udev, signals[DEVICE_ADDED], 0, device);
- else if (g_str_equal (action, "remove"))
- g_signal_emit (udev, signals[DEVICE_REMOVED], 0, device);
-
- if (g_udev_device_get_property_as_boolean (device, "HOTPLUG"))
- g_signal_emit (udev, signals[HOTPLUG], 0);
-}
-
-MetaUdev *
-meta_udev_new (MetaBackendNative *backend_native)
-{
- MetaUdev *udev;
-
- udev = g_object_new (META_TYPE_UDEV, NULL);
- udev->backend_native = backend_native;
-
- return udev;
-}
-
-static void
-meta_udev_finalize (GObject *object)
-{
- MetaUdev *udev = META_UDEV (object);
-
- g_clear_signal_handler (&udev->uevent_handler_id, udev->gudev_client);
- g_clear_object (&udev->gudev_client);
-
- G_OBJECT_CLASS (meta_udev_parent_class)->finalize (object);
-}
-
-static void
-meta_udev_init (MetaUdev *udev)
-{
- const char *subsystems[] = { "drm", NULL };
-
- udev->gudev_client = g_udev_client_new (subsystems);
- udev->uevent_handler_id = g_signal_connect (udev->gudev_client,
- "uevent",
- G_CALLBACK (on_uevent), udev);
-}
-
-static void
-meta_udev_class_init (MetaUdevClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- object_class->finalize = meta_udev_finalize;
-
- signals[HOTPLUG] =
- g_signal_new ("hotplug",
- G_TYPE_FROM_CLASS (object_class),
- G_SIGNAL_RUN_LAST,
- 0, NULL, NULL, NULL,
- G_TYPE_NONE, 0);
- signals[DEVICE_ADDED] =
- g_signal_new ("device-added",
- G_TYPE_FROM_CLASS (object_class),
- G_SIGNAL_RUN_LAST,
- 0, NULL, NULL, NULL,
- G_TYPE_NONE, 1,
- G_UDEV_TYPE_DEVICE);
- signals[DEVICE_REMOVED] =
- g_signal_new ("device-removed",
- G_TYPE_FROM_CLASS (object_class),
- G_SIGNAL_RUN_LAST,
- 0, NULL, NULL, NULL,
- G_TYPE_NONE, 1,
- G_UDEV_TYPE_DEVICE);
-}
diff --git a/src/backends/native/meta-udev.h b/src/backends/native/meta-udev.h
deleted file mode 100644
index 7b179329e..000000000
--- a/src/backends/native/meta-udev.h
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Copyright (C) 2018 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- */
-
-#ifndef META_UDEV_H
-#define META_UDEV_H
-
-#include <gudev/gudev.h>
-
-#include "backends/native/meta-backend-native-types.h"
-
-#define META_TYPE_UDEV (meta_udev_get_type ())
-G_DECLARE_FINAL_TYPE (MetaUdev, meta_udev, META, UDEV, GObject)
-
-gboolean meta_is_udev_device_platform_device (GUdevDevice *device);
-
-gboolean meta_is_udev_device_boot_vga (GUdevDevice *device);
-
-gboolean meta_is_udev_device_disable_modifiers (GUdevDevice *device);
-
-gboolean meta_is_udev_device_ignore (GUdevDevice *device);
-
-gboolean meta_is_udev_device_preferred_primary (GUdevDevice *device);
-
-gboolean meta_udev_is_drm_device (MetaUdev *udev,
- GUdevDevice *device);
-
-GList * meta_udev_list_drm_devices (MetaUdev *udev,
- GError **error);
-
-MetaUdev * meta_udev_new (MetaBackendNative *backend_native);
-
-#endif /* META_UDEV_H */
diff --git a/src/backends/native/meta-virtual-input-device-native.c b/src/backends/native/meta-virtual-input-device-native.c
deleted file mode 100644
index d2d13748a..000000000
--- a/src/backends/native/meta-virtual-input-device-native.c
+++ /dev/null
@@ -1,1110 +0,0 @@
-/*
- * Copyright (C) 2016 Red Hat Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
- *
- * Author: Jonas Ådahl <jadahl@gmail.com>
- */
-
-#include "config.h"
-
-#include <glib-object.h>
-#include <linux/input.h>
-
-#include "backends/native/meta-input-thread.h"
-#include "backends/native/meta-seat-native.h"
-#include "backends/native/meta-virtual-input-device-native.h"
-#include "clutter/clutter-mutter.h"
-#include "meta/util.h"
-
-enum
-{
- PROP_0,
-
- PROP_SEAT,
- PROP_SLOT_BASE,
-
- PROP_LAST
-};
-
-static GParamSpec *obj_props[PROP_LAST];
-
-typedef struct _ImplState ImplState;
-
-struct _ImplState
-{
- ClutterInputDevice *device;
- int button_count[KEY_CNT];
-};
-
-struct _MetaVirtualInputDeviceNative
-{
- ClutterVirtualInputDevice parent;
-
- MetaSeatNative *seat;
- guint slot_base;
- ImplState *impl_state;
-};
-
-typedef struct
-{
- uint64_t time_us;
- double x;
- double y;
-} MetaVirtualEventMotion;
-
-typedef struct
-{
- uint64_t time_us;
- uint32_t button;
- ClutterButtonState button_state;
-} MetaVirtualEventButton;
-
-typedef struct
-{
- uint64_t time_us;
- double dx;
- double dy;
- ClutterScrollDirection direction;
- ClutterScrollSource scroll_source;
- ClutterScrollFinishFlags finish_flags;
-} MetaVirtualEventScroll;
-
-typedef struct
-{
- uint64_t time_us;
- uint32_t key;
- ClutterKeyState key_state;
-} MetaVirtualEventKey;
-
-typedef struct
-{
- uint64_t time_us;
- int device_slot;
- double x;
- double y;
-} MetaVirtualEventTouch;
-
-G_DEFINE_TYPE (MetaVirtualInputDeviceNative,
- meta_virtual_input_device_native,
- CLUTTER_TYPE_VIRTUAL_INPUT_DEVICE)
-
-typedef enum _EvdevButtonType
-{
- EVDEV_BUTTON_TYPE_NONE,
- EVDEV_BUTTON_TYPE_KEY,
- EVDEV_BUTTON_TYPE_BUTTON,
-} EvdevButtonType;
-
-static int
-update_button_count_in_impl (MetaVirtualInputDeviceNative *virtual_evdev,
- uint32_t button,
- uint32_t state)
-{
- if (state)
- return ++virtual_evdev->impl_state->button_count[button];
- else
- return --virtual_evdev->impl_state->button_count[button];
-}
-
-static EvdevButtonType
-get_button_type (uint16_t code)
-{
- switch (code)
- {
- case BTN_TOOL_PEN:
- case BTN_TOOL_RUBBER:
- case BTN_TOOL_BRUSH:
- case BTN_TOOL_PENCIL:
- case BTN_TOOL_AIRBRUSH:
- case BTN_TOOL_MOUSE:
- case BTN_TOOL_LENS:
- case BTN_TOOL_QUINTTAP:
- case BTN_TOOL_DOUBLETAP:
- case BTN_TOOL_TRIPLETAP:
- case BTN_TOOL_QUADTAP:
- case BTN_TOOL_FINGER:
- case BTN_TOUCH:
- return EVDEV_BUTTON_TYPE_NONE;
- }
-
- if (code >= KEY_ESC && code <= KEY_MICMUTE)
- return EVDEV_BUTTON_TYPE_KEY;
- if (code >= BTN_MISC && code <= BTN_GEAR_UP)
- return EVDEV_BUTTON_TYPE_BUTTON;
- if (code >= KEY_OK && code <= KEY_LIGHTS_TOGGLE)
- return EVDEV_BUTTON_TYPE_KEY;
- if (code >= BTN_DPAD_UP && code <= BTN_DPAD_RIGHT)
- return EVDEV_BUTTON_TYPE_BUTTON;
- if (code >= KEY_ALS_TOGGLE && code <= KEY_KBDINPUTASSIST_CANCEL)
- return EVDEV_BUTTON_TYPE_KEY;
- if (code >= BTN_TRIGGER_HAPPY && code <= BTN_TRIGGER_HAPPY40)
- return EVDEV_BUTTON_TYPE_BUTTON;
- return EVDEV_BUTTON_TYPE_NONE;
-}
-
-static gboolean
-release_device_in_impl (GTask *task)
-{
- ImplState *impl_state = g_task_get_task_data (task);
- MetaInputDeviceNative *device_native;
- MetaSeatImpl *seat_impl;
- int code;
- uint64_t time_us;
- ClutterEvent *device_event;
-
- device_native = META_INPUT_DEVICE_NATIVE (impl_state->device);
- seat_impl = meta_input_device_native_get_seat_impl (device_native);
- time_us = g_get_monotonic_time ();
-
- meta_topic (META_DEBUG_INPUT,
- "Releasing pressed buttons while destroying virtual input device "
- "(device %p)", device_native);
-
- for (code = 0; code < G_N_ELEMENTS (impl_state->button_count); code++)
- {
- if (impl_state->button_count[code] == 0)
- continue;
-
- switch (get_button_type (code))
- {
- case EVDEV_BUTTON_TYPE_KEY:
- meta_seat_impl_notify_key_in_impl (seat_impl,
- impl_state->device,
- time_us,
- code,
- CLUTTER_KEY_STATE_RELEASED,
- TRUE);
- break;
- case EVDEV_BUTTON_TYPE_BUTTON:
- meta_seat_impl_notify_button_in_impl (seat_impl,
- impl_state->device,
- time_us,
- code,
- CLUTTER_BUTTON_STATE_RELEASED);
- break;
- case EVDEV_BUTTON_TYPE_NONE:
- g_assert_not_reached ();
- }
- }
-
- device_event = clutter_event_new (CLUTTER_DEVICE_REMOVED);
- clutter_event_set_device (device_event, impl_state->device);
- _clutter_event_push (device_event, FALSE);
-
- g_clear_object (&impl_state->device);
- g_task_return_boolean (task, TRUE);
-
- return G_SOURCE_REMOVE;
-}
-
-static gboolean
-notify_relative_motion_in_impl (GTask *task)
-{
- MetaVirtualInputDeviceNative *virtual_evdev =
- g_task_get_source_object (task);
- MetaSeatImpl *seat = virtual_evdev->seat->impl;
- MetaVirtualEventMotion *event = g_task_get_task_data (task);
-
- if (event->time_us == CLUTTER_CURRENT_TIME)
- event->time_us = g_get_monotonic_time ();
-
- meta_seat_impl_notify_relative_motion_in_impl (seat,
- virtual_evdev->impl_state->device,
- event->time_us,
- event->x, event->y,
- event->x, event->y);
- g_task_return_boolean (task, TRUE);
- return G_SOURCE_REMOVE;
-}
-
-static void
-meta_virtual_input_device_native_notify_relative_motion (ClutterVirtualInputDevice *virtual_device,
- uint64_t time_us,
- double dx,
- double dy)
-{
- MetaVirtualEventMotion *event;
- MetaVirtualInputDeviceNative *virtual_evdev =
- META_VIRTUAL_INPUT_DEVICE_NATIVE (virtual_device);
- GTask *task;
-
- g_return_if_fail (virtual_evdev->impl_state->device != NULL);
-
- event = g_new0 (MetaVirtualEventMotion, 1);
- event->time_us = time_us;
- event->x = dx;
- event->y = dy;
-
- task = g_task_new (virtual_device, NULL, NULL, NULL);
- g_task_set_task_data (task, event, g_free);
- meta_seat_impl_run_input_task (virtual_evdev->seat->impl, task,
- (GSourceFunc) notify_relative_motion_in_impl);
- g_object_unref (task);
-}
-
-static gboolean
-notify_absolute_motion_in_impl (GTask *task)
-{
- MetaVirtualInputDeviceNative *virtual_evdev =
- g_task_get_source_object (task);
- MetaSeatImpl *seat = virtual_evdev->seat->impl;
- MetaVirtualEventMotion *event = g_task_get_task_data (task);
-
- if (event->time_us == CLUTTER_CURRENT_TIME)
- event->time_us = g_get_monotonic_time ();
-
- meta_seat_impl_notify_absolute_motion_in_impl (seat,
- virtual_evdev->impl_state->device,
- event->time_us,
- event->x, event->y,
- NULL);
- g_task_return_boolean (task, TRUE);
- return G_SOURCE_REMOVE;
-}
-
-static void
-meta_virtual_input_device_native_notify_absolute_motion (ClutterVirtualInputDevice *virtual_device,
- uint64_t time_us,
- double x,
- double y)
-{
- MetaVirtualEventMotion *event;
- MetaVirtualInputDeviceNative *virtual_evdev =
- META_VIRTUAL_INPUT_DEVICE_NATIVE (virtual_device);
- GTask *task;
-
- g_return_if_fail (virtual_evdev->impl_state->device != NULL);
-
- event = g_new0 (MetaVirtualEventMotion, 1);
- event->time_us = time_us;
- event->x = x;
- event->y = y;
-
- task = g_task_new (virtual_device, NULL, NULL, NULL);
- g_task_set_task_data (task, event, g_free);
- meta_seat_impl_run_input_task (virtual_evdev->seat->impl, task,
- (GSourceFunc) notify_absolute_motion_in_impl);
- g_object_unref (task);
-}
-
-static int
-translate_to_evdev_button (int clutter_button)
-{
- switch (clutter_button)
- {
- case CLUTTER_BUTTON_PRIMARY:
- return BTN_LEFT;
- case CLUTTER_BUTTON_SECONDARY:
- return BTN_RIGHT;
- case CLUTTER_BUTTON_MIDDLE:
- return BTN_MIDDLE;
- default:
- /*
- * For compatibility reasons, all additional buttons go after the old
- * 4-7 scroll ones.
- */
- return clutter_button + (BTN_LEFT - 1) - 4;
- }
-}
-
-static gboolean
-notify_button_in_impl (GTask *task)
-{
- MetaVirtualInputDeviceNative *virtual_evdev =
- g_task_get_source_object (task);
- MetaSeatImpl *seat = virtual_evdev->seat->impl;
- MetaVirtualEventButton *event = g_task_get_task_data (task);
- int button_count;
- int evdev_button;
-
- if (event->time_us == CLUTTER_CURRENT_TIME)
- event->time_us = g_get_monotonic_time ();
-
- evdev_button = translate_to_evdev_button (event->button);
-
- if (get_button_type (evdev_button) != EVDEV_BUTTON_TYPE_BUTTON)
- {
- g_warning ("Unknown/invalid virtual device button 0x%x pressed",
- evdev_button);
- goto out;
- }
-
- button_count = update_button_count_in_impl (virtual_evdev, evdev_button,
- event->button_state);
- if (button_count < 0 || button_count > 1)
- {
- g_warning ("Received multiple virtual 0x%x button %s (ignoring)", evdev_button,
- event->button_state == CLUTTER_BUTTON_STATE_PRESSED ?
- "presses" : "releases");
- update_button_count_in_impl (virtual_evdev, evdev_button, 1 - event->button_state);
- goto out;
- }
-
- meta_topic (META_DEBUG_INPUT,
- "Emitting virtual button-%s of button 0x%x (device %p)",
- event->button_state == CLUTTER_BUTTON_STATE_PRESSED ?
- "press" : "release",
- evdev_button, virtual_evdev);
-
- meta_seat_impl_notify_button_in_impl (seat,
- virtual_evdev->impl_state->device,
- event->time_us,
- evdev_button,
- event->button_state);
- out:
- g_task_return_boolean (task, TRUE);
- return G_SOURCE_REMOVE;
-}
-
-static void
-meta_virtual_input_device_native_notify_button (ClutterVirtualInputDevice *virtual_device,
- uint64_t time_us,
- uint32_t button,
- ClutterButtonState button_state)
-{
- MetaVirtualEventButton *event;
- MetaVirtualInputDeviceNative *virtual_evdev =
- META_VIRTUAL_INPUT_DEVICE_NATIVE (virtual_device);
- GTask *task;
-
- g_return_if_fail (virtual_evdev->impl_state->device != NULL);
-
- event = g_new0 (MetaVirtualEventButton, 1);
- event->time_us = time_us;
- event->button = button;
- event->button_state = button_state;
-
- task = g_task_new (virtual_device, NULL, NULL, NULL);
- g_task_set_task_data (task, event, g_free);
- meta_seat_impl_run_input_task (virtual_evdev->seat->impl, task,
- (GSourceFunc) notify_button_in_impl);
- g_object_unref (task);
-}
-
-static gboolean
-notify_key_in_impl (GTask *task)
-{
- MetaVirtualInputDeviceNative *virtual_evdev =
- g_task_get_source_object (task);
- MetaSeatImpl *seat = virtual_evdev->seat->impl;
- MetaVirtualEventKey *event = g_task_get_task_data (task);
- int key_count;
-
- if (event->time_us == CLUTTER_CURRENT_TIME)
- event->time_us = g_get_monotonic_time ();
-
- if (get_button_type (event->key) != EVDEV_BUTTON_TYPE_KEY)
- {
- g_warning ("Unknown/invalid virtual device key 0x%x pressed", event->key);
- goto out;
- }
-
- key_count = update_button_count_in_impl (virtual_evdev, event->key, event->key_state);
- if (key_count < 0 || key_count > 1)
- {
- g_warning ("Received multiple virtual 0x%x key %s (ignoring)", event->key,
- event->key_state == CLUTTER_KEY_STATE_PRESSED ?
- "presses" : "releases");
- update_button_count_in_impl (virtual_evdev, event->key, 1 - event->key_state);
- goto out;
- }
-
- meta_topic (META_DEBUG_INPUT,
- "Emitting virtual key-%s of key 0x%x (device %p)",
- event->key_state == CLUTTER_KEY_STATE_PRESSED ? "press" : "release",
- event->key, virtual_evdev);
-
- meta_seat_impl_notify_key_in_impl (seat,
- virtual_evdev->impl_state->device,
- event->time_us,
- event->key,
- event->key_state,
- TRUE);
-
- out:
- g_task_return_boolean (task, TRUE);
- return G_SOURCE_REMOVE;
-}
-
-static void
-meta_virtual_input_device_native_notify_key (ClutterVirtualInputDevice *virtual_device,
- uint64_t time_us,
- uint32_t key,
- ClutterKeyState key_state)
-{
- MetaVirtualEventKey *event;
- MetaVirtualInputDeviceNative *virtual_evdev =
- META_VIRTUAL_INPUT_DEVICE_NATIVE (virtual_device);
- GTask *task;
-
- g_return_if_fail (virtual_evdev->impl_state->device != NULL);
-
- event = g_new0 (MetaVirtualEventKey, 1);
- event->time_us = time_us;
- event->key = key;
- event->key_state = key_state;
-
- task = g_task_new (virtual_device, NULL, NULL, NULL);
- g_task_set_task_data (task, event, g_free);
- meta_seat_impl_run_input_task (virtual_evdev->seat->impl, task,
- (GSourceFunc) notify_key_in_impl);
- g_object_unref (task);
-}
-
-static gboolean
-pick_keycode_for_keyval_in_current_group_in_impl (ClutterVirtualInputDevice *virtual_device,
- guint keyval,
- guint *keycode_out,
- guint *level_out)
-{
- MetaVirtualInputDeviceNative *virtual_evdev =
- META_VIRTUAL_INPUT_DEVICE_NATIVE (virtual_device);
- ClutterBackend *backend;
- ClutterKeymap *keymap;
- struct xkb_keymap *xkb_keymap;
- struct xkb_state *state;
- guint keycode, layout;
- xkb_keycode_t min_keycode, max_keycode;
-
- backend = clutter_get_default_backend ();
- keymap = clutter_seat_get_keymap (clutter_backend_get_default_seat (backend));
- xkb_keymap = meta_keymap_native_get_keyboard_map_in_impl (META_KEYMAP_NATIVE (keymap));
- state = meta_seat_impl_get_xkb_state_in_impl (virtual_evdev->seat->impl);
-
- layout = xkb_state_serialize_layout (state, XKB_STATE_LAYOUT_EFFECTIVE);
- min_keycode = xkb_keymap_min_keycode (xkb_keymap);
- max_keycode = xkb_keymap_max_keycode (xkb_keymap);
- for (keycode = min_keycode; keycode < max_keycode; keycode++)
- {
- gint num_levels, level;
- num_levels = xkb_keymap_num_levels_for_key (xkb_keymap, keycode, layout);
- for (level = 0; level < num_levels; level++)
- {
- const xkb_keysym_t *syms;
- gint num_syms, sym;
- num_syms = xkb_keymap_key_get_syms_by_level (xkb_keymap, keycode, layout, level, &syms);
- for (sym = 0; sym < num_syms; sym++)
- {
- if (syms[sym] == keyval)
- {
- *keycode_out = keycode;
- if (level_out)
- *level_out = level;
- return TRUE;
- }
- }
- }
- }
-
- return FALSE;
-}
-
-static void
-apply_level_modifiers_in_impl (ClutterVirtualInputDevice *virtual_device,
- uint64_t time_us,
- uint32_t level,
- uint32_t key_state)
-{
- MetaVirtualInputDeviceNative *virtual_evdev =
- META_VIRTUAL_INPUT_DEVICE_NATIVE (virtual_device);
- guint keysym, keycode, evcode;
-
- if (level == 0)
- return;
-
- if (level == 1)
- {
- keysym = XKB_KEY_Shift_L;
- }
- else if (level == 2)
- {
- keysym = XKB_KEY_ISO_Level3_Shift;
- }
- else
- {
- g_warning ("Unhandled level: %d", level);
- return;
- }
-
- if (!pick_keycode_for_keyval_in_current_group_in_impl (virtual_device, keysym,
- &keycode, NULL))
- return;
-
- evcode = meta_xkb_keycode_to_evdev (keycode);
-
- meta_topic (META_DEBUG_INPUT,
- "Emitting virtual key-%s of modifier key 0x%x (device %p)",
- key_state == CLUTTER_KEY_STATE_PRESSED ? "press" : "release",
- evcode, virtual_device);
-
- meta_seat_impl_notify_key_in_impl (virtual_evdev->seat->impl,
- virtual_evdev->impl_state->device,
- time_us,
- evcode,
- key_state,
- TRUE);
-}
-
-static gboolean
-notify_keyval_in_impl (GTask *task)
-{
- MetaVirtualInputDeviceNative *virtual_evdev =
- g_task_get_source_object (task);
- ClutterVirtualInputDevice *virtual_device =
- CLUTTER_VIRTUAL_INPUT_DEVICE (virtual_evdev);
- MetaSeatImpl *seat = virtual_evdev->seat->impl;
- MetaVirtualEventKey *event = g_task_get_task_data (task);
- int key_count;
- guint keycode = 0, level = 0, evcode = 0;
-
- if (event->time_us == CLUTTER_CURRENT_TIME)
- event->time_us = g_get_monotonic_time ();
-
- if (!pick_keycode_for_keyval_in_current_group_in_impl (virtual_device,
- event->key,
- &keycode, &level))
- {
- g_warning ("No keycode found for keyval %x in current group", event->key);
- goto out;
- }
-
- evcode = meta_xkb_keycode_to_evdev (keycode);
-
- if (get_button_type (evcode) != EVDEV_BUTTON_TYPE_KEY)
- {
- g_warning ("Unknown/invalid virtual device key 0x%x pressed", evcode);
- goto out;
- }
-
- key_count = update_button_count_in_impl (virtual_evdev, evcode, event->key_state);
- if (key_count < 0 || key_count > 1)
- {
- g_warning ("Received multiple virtual 0x%x key %s (ignoring)", evcode,
- event->key_state == CLUTTER_KEY_STATE_PRESSED ?
- "presses" : "releases");
- update_button_count_in_impl (virtual_evdev, evcode, 1 - event->key_state);
- goto out;
- }
-
- meta_topic (META_DEBUG_INPUT,
- "Emitting virtual key-%s of key 0x%x with modifier level %d, "
- "press count %d (device %p)",
- event->key_state == CLUTTER_KEY_STATE_PRESSED ? "press" : "release",
- evcode, level, key_count, virtual_evdev);
-
- if (event->key_state)
- {
- apply_level_modifiers_in_impl (virtual_device, event->time_us,
- level, event->key_state);
- }
-
- meta_seat_impl_notify_key_in_impl (seat,
- virtual_evdev->impl_state->device,
- event->time_us,
- evcode,
- event->key_state,
- TRUE);
-
- if (!event->key_state)
- {
- apply_level_modifiers_in_impl (virtual_device, event->time_us,
- level, event->key_state);
- }
-
- out:
- g_task_return_boolean (task, TRUE);
- return G_SOURCE_REMOVE;
-}
-
-static void
-meta_virtual_input_device_native_notify_keyval (ClutterVirtualInputDevice *virtual_device,
- uint64_t time_us,
- uint32_t keyval,
- ClutterKeyState key_state)
-{
- MetaVirtualEventKey *event;
- MetaVirtualInputDeviceNative *virtual_evdev =
- META_VIRTUAL_INPUT_DEVICE_NATIVE (virtual_device);
- GTask *task;
-
- g_return_if_fail (virtual_evdev->impl_state->device != NULL);
-
- event = g_new0 (MetaVirtualEventKey, 1);
- event->time_us = time_us;
- event->key = keyval;
- event->key_state = key_state;
-
- task = g_task_new (virtual_device, NULL, NULL, NULL);
- g_task_set_task_data (task, event, g_free);
- meta_seat_impl_run_input_task (virtual_evdev->seat->impl, task,
- (GSourceFunc) notify_keyval_in_impl);
- g_object_unref (task);
-}
-
-static void
-direction_to_discrete (ClutterScrollDirection direction,
- double *discrete_dx,
- double *discrete_dy)
-{
- switch (direction)
- {
- case CLUTTER_SCROLL_UP:
- *discrete_dx = 0.0;
- *discrete_dy = -1.0;
- break;
- case CLUTTER_SCROLL_DOWN:
- *discrete_dx = 0.0;
- *discrete_dy = 1.0;
- break;
- case CLUTTER_SCROLL_LEFT:
- *discrete_dx = -1.0;
- *discrete_dy = 0.0;
- break;
- case CLUTTER_SCROLL_RIGHT:
- *discrete_dx = 1.0;
- *discrete_dy = 0.0;
- break;
- case CLUTTER_SCROLL_SMOOTH:
- g_assert_not_reached ();
- break;
- }
-}
-
-static gboolean
-notify_discrete_scroll_in_impl (GTask *task)
-{
- MetaVirtualInputDeviceNative *virtual_evdev =
- g_task_get_source_object (task);
- MetaSeatImpl *seat = virtual_evdev->seat->impl;
- MetaVirtualEventScroll *event = g_task_get_task_data (task);
- double discrete_dx = 0.0, discrete_dy = 0.0;
-
- if (event->time_us == CLUTTER_CURRENT_TIME)
- event->time_us = g_get_monotonic_time ();
-
- direction_to_discrete (event->direction, &discrete_dx, &discrete_dy);
-
- meta_seat_impl_notify_discrete_scroll_in_impl (seat,
- virtual_evdev->impl_state->device,
- event->time_us,
- discrete_dx, discrete_dy,
- event->scroll_source);
-
- g_task_return_boolean (task, TRUE);
- return G_SOURCE_REMOVE;
-}
-
-static void
-meta_virtual_input_device_native_notify_discrete_scroll (ClutterVirtualInputDevice *virtual_device,
- uint64_t time_us,
- ClutterScrollDirection direction,
- ClutterScrollSource scroll_source)
-{
- MetaVirtualEventScroll *event;
- MetaVirtualInputDeviceNative *virtual_evdev =
- META_VIRTUAL_INPUT_DEVICE_NATIVE (virtual_device);
- GTask *task;
-
- g_return_if_fail (virtual_evdev->impl_state->device != NULL);
-
- event = g_new0 (MetaVirtualEventScroll, 1);
- event->time_us = time_us;
- event->direction = direction;
- event->scroll_source = scroll_source;
-
- task = g_task_new (virtual_device, NULL, NULL, NULL);
- g_task_set_task_data (task, event, g_free);
- meta_seat_impl_run_input_task (virtual_evdev->seat->impl, task,
- (GSourceFunc) notify_discrete_scroll_in_impl);
- g_object_unref (task);
-}
-
-static gboolean
-notify_scroll_continuous_in_impl (GTask *task)
-{
- MetaVirtualInputDeviceNative *virtual_evdev =
- g_task_get_source_object (task);
- MetaSeatImpl *seat = virtual_evdev->seat->impl;
- MetaVirtualEventScroll *event = g_task_get_task_data (task);
-
- if (event->time_us == CLUTTER_CURRENT_TIME)
- event->time_us = g_get_monotonic_time ();
-
- meta_seat_impl_notify_scroll_continuous_in_impl (seat,
- virtual_evdev->impl_state->device,
- event->time_us,
- event->dx, event->dy,
- event->scroll_source,
- CLUTTER_SCROLL_FINISHED_NONE);
- g_task_return_boolean (task, TRUE);
- return G_SOURCE_REMOVE;
-}
-
-static void
-meta_virtual_input_device_native_notify_scroll_continuous (ClutterVirtualInputDevice *virtual_device,
- uint64_t time_us,
- double dx,
- double dy,
- ClutterScrollSource scroll_source,
- ClutterScrollFinishFlags finish_flags)
-{
- MetaVirtualEventScroll *event;
- MetaVirtualInputDeviceNative *virtual_evdev =
- META_VIRTUAL_INPUT_DEVICE_NATIVE (virtual_device);
- GTask *task;
-
- g_return_if_fail (virtual_evdev->impl_state->device != NULL);
-
- event = g_new0 (MetaVirtualEventScroll, 1);
- event->time_us = time_us;
- event->dx = dx;
- event->dy = dy;
- event->scroll_source = scroll_source;
- event->finish_flags = finish_flags;
-
- task = g_task_new (virtual_device, NULL, NULL, NULL);
- g_task_set_task_data (task, event, g_free);
- meta_seat_impl_run_input_task (virtual_evdev->seat->impl, task,
- (GSourceFunc) notify_scroll_continuous_in_impl);
- g_object_unref (task);
-}
-
-static gboolean
-notify_touch_down_in_impl (GTask *task)
-{
- MetaVirtualInputDeviceNative *virtual_evdev =
- g_task_get_source_object (task);
- MetaSeatImpl *seat = virtual_evdev->seat->impl;
- MetaVirtualEventTouch *event = g_task_get_task_data (task);
- MetaTouchState *touch_state;
-
- if (event->time_us == CLUTTER_CURRENT_TIME)
- event->time_us = g_get_monotonic_time ();
-
- touch_state = meta_seat_impl_acquire_touch_state_in_impl (seat,
- event->device_slot);
- if (!touch_state)
- goto out;
-
- touch_state->coords.x = event->x;
- touch_state->coords.y = event->y;
-
- meta_seat_impl_notify_touch_event_in_impl (seat,
- virtual_evdev->impl_state->device,
- CLUTTER_TOUCH_BEGIN,
- event->time_us,
- touch_state->seat_slot,
- touch_state->coords.x,
- touch_state->coords.y);
-
- out:
- g_task_return_boolean (task, TRUE);
- return G_SOURCE_REMOVE;
-}
-
-static void
-meta_virtual_input_device_native_notify_touch_down (ClutterVirtualInputDevice *virtual_device,
- uint64_t time_us,
- int device_slot,
- double x,
- double y)
-{
- MetaVirtualEventTouch *event;
- MetaVirtualInputDeviceNative *virtual_evdev =
- META_VIRTUAL_INPUT_DEVICE_NATIVE (virtual_device);
- GTask *task;
-
- g_return_if_fail (virtual_evdev->impl_state->device != NULL);
-
- event = g_new0 (MetaVirtualEventTouch, 1);
- event->time_us = time_us;
- event->device_slot = virtual_evdev->slot_base + (guint) device_slot;
- event->x = x;
- event->y = y;
-
- task = g_task_new (virtual_device, NULL, NULL, NULL);
- g_task_set_task_data (task, event, g_free);
- meta_seat_impl_run_input_task (virtual_evdev->seat->impl, task,
- (GSourceFunc) notify_touch_down_in_impl);
- g_object_unref (task);
-}
-
-static gboolean
-notify_touch_motion_in_impl (GTask *task)
-{
- MetaVirtualInputDeviceNative *virtual_evdev =
- g_task_get_source_object (task);
- MetaSeatImpl *seat = virtual_evdev->seat->impl;
- MetaVirtualEventTouch *event = g_task_get_task_data (task);
- MetaTouchState *touch_state;
-
- if (event->time_us == CLUTTER_CURRENT_TIME)
- event->time_us = g_get_monotonic_time ();
-
- touch_state = meta_seat_impl_lookup_touch_state_in_impl (seat,
- event->device_slot);
- if (!touch_state)
- goto out;
-
- touch_state->coords.x = event->x;
- touch_state->coords.y = event->y;
-
- meta_seat_impl_notify_touch_event_in_impl (seat,
- virtual_evdev->impl_state->device,
- CLUTTER_TOUCH_UPDATE,
- event->time_us,
- touch_state->seat_slot,
- touch_state->coords.x,
- touch_state->coords.y);
-
- out:
- g_task_return_boolean (task, TRUE);
- return G_SOURCE_REMOVE;
-}
-
-static void
-meta_virtual_input_device_native_notify_touch_motion (ClutterVirtualInputDevice *virtual_device,
- uint64_t time_us,
- int device_slot,
- double x,
- double y)
-{
- MetaVirtualEventTouch *event;
- MetaVirtualInputDeviceNative *virtual_evdev =
- META_VIRTUAL_INPUT_DEVICE_NATIVE (virtual_device);
- GTask *task;
-
- g_return_if_fail (virtual_evdev->impl_state->device != NULL);
-
- event = g_new0 (MetaVirtualEventTouch, 1);
- event->time_us = time_us;
- event->device_slot = virtual_evdev->slot_base + (guint) device_slot;
- event->x = x;
- event->y = y;
-
- task = g_task_new (virtual_device, NULL, NULL, NULL);
- g_task_set_task_data (task, event, g_free);
- meta_seat_impl_run_input_task (virtual_evdev->seat->impl, task,
- (GSourceFunc) notify_touch_motion_in_impl);
- g_object_unref (task);
-}
-
-static gboolean
-notify_touch_up_in_impl (GTask *task)
-{
- MetaVirtualInputDeviceNative *virtual_evdev =
- g_task_get_source_object (task);
- MetaSeatImpl *seat = virtual_evdev->seat->impl;
- MetaVirtualEventTouch *event = g_task_get_task_data (task);
- MetaTouchState *touch_state;
-
- if (event->time_us == CLUTTER_CURRENT_TIME)
- event->time_us = g_get_monotonic_time ();
-
- touch_state = meta_seat_impl_lookup_touch_state_in_impl (seat,
- event->device_slot);
- if (!touch_state)
- goto out;
-
- meta_seat_impl_notify_touch_event_in_impl (seat,
- virtual_evdev->impl_state->device,
- CLUTTER_TOUCH_END,
- event->time_us,
- touch_state->seat_slot,
- touch_state->coords.x,
- touch_state->coords.y);
-
- meta_seat_impl_release_touch_state_in_impl (virtual_evdev->seat->impl,
- touch_state->seat_slot);
-
- out:
- g_task_return_boolean (task, TRUE);
- return G_SOURCE_REMOVE;
-}
-
-static void
-meta_virtual_input_device_native_notify_touch_up (ClutterVirtualInputDevice *virtual_device,
- uint64_t time_us,
- int device_slot)
-{
- MetaVirtualEventTouch *event;
- MetaVirtualInputDeviceNative *virtual_evdev =
- META_VIRTUAL_INPUT_DEVICE_NATIVE (virtual_device);
- GTask *task;
-
- g_return_if_fail (virtual_evdev->impl_state->device != NULL);
-
- event = g_new0 (MetaVirtualEventTouch, 1);
- event->time_us = time_us;
- event->device_slot = virtual_evdev->slot_base + (guint) device_slot;
-
- task = g_task_new (virtual_device, NULL, NULL, NULL);
- g_task_set_task_data (task, event, g_free);
- meta_seat_impl_run_input_task (virtual_evdev->seat->impl, task,
- (GSourceFunc) notify_touch_up_in_impl);
- g_object_unref (task);
-}
-
-static void
-meta_virtual_input_device_native_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- MetaVirtualInputDeviceNative *virtual_evdev =
- META_VIRTUAL_INPUT_DEVICE_NATIVE (object);
-
- switch (prop_id)
- {
- case PROP_SEAT:
- g_value_set_pointer (value, virtual_evdev->seat);
- break;
- case PROP_SLOT_BASE:
- g_value_set_uint (value, virtual_evdev->slot_base);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-
-static void
-meta_virtual_input_device_native_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- MetaVirtualInputDeviceNative *virtual_evdev =
- META_VIRTUAL_INPUT_DEVICE_NATIVE (object);
-
- switch (prop_id)
- {
- case PROP_SEAT:
- virtual_evdev->seat = g_value_get_pointer (value);
- break;
- case PROP_SLOT_BASE:
- virtual_evdev->slot_base = g_value_get_uint (value);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-
-static void
-meta_virtual_input_device_native_constructed (GObject *object)
-{
- ClutterVirtualInputDevice *virtual_device =
- CLUTTER_VIRTUAL_INPUT_DEVICE (object);
- MetaVirtualInputDeviceNative *virtual_evdev =
- META_VIRTUAL_INPUT_DEVICE_NATIVE (object);
- ClutterInputDeviceType device_type;
- ClutterEvent *device_event = NULL;
-
- device_type = clutter_virtual_input_device_get_device_type (virtual_device);
-
- meta_topic (META_DEBUG_INPUT,
- "Creating new virtual input device of type %d (%p)",
- device_type, virtual_device);
-
- virtual_evdev->impl_state = g_new0 (ImplState, 1);
- virtual_evdev->impl_state->device =
- meta_input_device_native_new_virtual (virtual_evdev->seat->impl,
- device_type,
- CLUTTER_INPUT_MODE_PHYSICAL);
-
- device_event = clutter_event_new (CLUTTER_DEVICE_ADDED);
- clutter_event_set_device (device_event, virtual_evdev->impl_state->device);
- _clutter_event_push (device_event, FALSE);
-}
-
-static void
-impl_state_free (ImplState *impl_state)
-{
- g_warn_if_fail (!impl_state->device);
- g_free (impl_state);
-}
-
-static void
-meta_virtual_input_device_native_dispose (GObject *object)
-{
- ClutterVirtualInputDevice *virtual_device =
- CLUTTER_VIRTUAL_INPUT_DEVICE (object);
- MetaVirtualInputDeviceNative *virtual_evdev =
- META_VIRTUAL_INPUT_DEVICE_NATIVE (object);
- GObjectClass *object_class =
- G_OBJECT_CLASS (meta_virtual_input_device_native_parent_class);
-
- if (virtual_evdev->impl_state)
- {
- GTask *task;
-
- task = g_task_new (virtual_device, NULL, NULL, NULL);
- g_task_set_task_data (task, virtual_evdev->impl_state,
- (GDestroyNotify) impl_state_free);
- meta_seat_impl_run_input_task (virtual_evdev->seat->impl, task,
- (GSourceFunc) release_device_in_impl);
- g_object_unref (task);
-
- virtual_evdev->impl_state = NULL;
- }
-
- meta_seat_native_release_touch_slots (virtual_evdev->seat,
- virtual_evdev->slot_base);
-
- object_class->dispose (object);
-}
-
-static void
-meta_virtual_input_device_native_init (MetaVirtualInputDeviceNative *virtual_device_evdev)
-{
-}
-
-static void
-meta_virtual_input_device_native_class_init (MetaVirtualInputDeviceNativeClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
- ClutterVirtualInputDeviceClass *virtual_input_device_class =
- CLUTTER_VIRTUAL_INPUT_DEVICE_CLASS (klass);
-
- object_class->get_property = meta_virtual_input_device_native_get_property;
- object_class->set_property = meta_virtual_input_device_native_set_property;
- object_class->constructed = meta_virtual_input_device_native_constructed;
- object_class->dispose = meta_virtual_input_device_native_dispose;
-
- virtual_input_device_class->notify_relative_motion = meta_virtual_input_device_native_notify_relative_motion;
- virtual_input_device_class->notify_absolute_motion = meta_virtual_input_device_native_notify_absolute_motion;
- virtual_input_device_class->notify_button = meta_virtual_input_device_native_notify_button;
- virtual_input_device_class->notify_key = meta_virtual_input_device_native_notify_key;
- virtual_input_device_class->notify_keyval = meta_virtual_input_device_native_notify_keyval;
- virtual_input_device_class->notify_discrete_scroll = meta_virtual_input_device_native_notify_discrete_scroll;
- virtual_input_device_class->notify_scroll_continuous = meta_virtual_input_device_native_notify_scroll_continuous;
- virtual_input_device_class->notify_touch_down = meta_virtual_input_device_native_notify_touch_down;
- virtual_input_device_class->notify_touch_motion = meta_virtual_input_device_native_notify_touch_motion;
- virtual_input_device_class->notify_touch_up = meta_virtual_input_device_native_notify_touch_up;
-
- obj_props[PROP_SEAT] = g_param_spec_pointer ("seat",
- "Seat",
- "Seat",
- CLUTTER_PARAM_READWRITE |
- G_PARAM_CONSTRUCT_ONLY);
- obj_props[PROP_SLOT_BASE] = g_param_spec_uint ("slot-base",
- "Slot base",
- "Base for touch slots",
- 0, G_MAXUINT, 0,
- CLUTTER_PARAM_READWRITE |
- G_PARAM_CONSTRUCT_ONLY);
- g_object_class_install_properties (object_class, PROP_LAST, obj_props);
-}
diff --git a/src/backends/native/meta-virtual-input-device-native.h b/src/backends/native/meta-virtual-input-device-native.h
deleted file mode 100644
index 28d218abb..000000000
--- a/src/backends/native/meta-virtual-input-device-native.h
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * Copyright (C) 2016 Red Hat Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
- *
- * Author: Jonas Ådahl <jadahl@gmail.com>
- */
-
-#ifndef META_VIRTUAL_INPUT_DEVICE_NATIVE_H
-#define META_VIRTUAL_INPUT_DEVICE_NATIVE_H
-
-#include "clutter/clutter-virtual-input-device.h"
-
-#define META_TYPE_VIRTUAL_INPUT_DEVICE_NATIVE (meta_virtual_input_device_native_get_type ())
-G_DECLARE_FINAL_TYPE (MetaVirtualInputDeviceNative,
- meta_virtual_input_device_native,
- META, VIRTUAL_INPUT_DEVICE_NATIVE,
- ClutterVirtualInputDevice)
-
-#endif /* META_VIRTUAL_INPUT_DEVICE_NATIVE_H */
diff --git a/src/backends/native/meta-virtual-monitor-native.c b/src/backends/native/meta-virtual-monitor-native.c
deleted file mode 100644
index 3f81f4180..000000000
--- a/src/backends/native/meta-virtual-monitor-native.c
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * Copyright (C) 2021 Red Hat Inc.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- */
-
-#include "config.h"
-
-#include "backends/native/meta-virtual-monitor-native.h"
-
-#include "backends/native/meta-crtc-mode-virtual.h"
-#include "backends/native/meta-crtc-virtual.h"
-#include "backends/native/meta-output-virtual.h"
-
-struct _MetaVirtualMonitorNative
-{
- MetaVirtualMonitor parent;
-
- uint64_t id;
-};
-
-#define VIRTUAL_OUTPUT_ID_BIT (((uint64_t) 1) << 63)
-
-G_DEFINE_TYPE (MetaVirtualMonitorNative, meta_virtual_monitor_native,
- META_TYPE_VIRTUAL_MONITOR)
-
-uint64_t
-meta_virtual_monitor_native_get_id (MetaVirtualMonitorNative *virtual_monitor_native)
-{
- return virtual_monitor_native->id;
-}
-
-MetaVirtualMonitorNative *
-meta_virtual_monitor_native_new (uint64_t id,
- const MetaVirtualMonitorInfo *info)
-{
- MetaVirtualMonitorNative *virtual_monitor_native;
- MetaCrtcVirtual *crtc_virtual;
- MetaCrtcModeVirtual *crtc_mode_virtual;
- MetaOutputVirtual *output_virtual;
-
- crtc_virtual = meta_crtc_virtual_new (id);
- crtc_mode_virtual = meta_crtc_mode_virtual_new (id, info);
- output_virtual = meta_output_virtual_new (id, info,
- crtc_virtual,
- crtc_mode_virtual);
-
- virtual_monitor_native = g_object_new (META_TYPE_VIRTUAL_MONITOR_NATIVE,
- "crtc", crtc_virtual,
- "crtc-mode", crtc_mode_virtual,
- "output", output_virtual,
- NULL);
- virtual_monitor_native->id = id;
-
- return virtual_monitor_native;
-}
-
-static void
-meta_virtual_monitor_native_init (MetaVirtualMonitorNative *virtual_monitor_native)
-{
-}
-
-static void
-meta_virtual_monitor_native_class_init (MetaVirtualMonitorNativeClass *klass)
-{
-}
diff --git a/src/backends/native/meta-virtual-monitor-native.h b/src/backends/native/meta-virtual-monitor-native.h
deleted file mode 100644
index d1a0ced64..000000000
--- a/src/backends/native/meta-virtual-monitor-native.h
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Copyright (C) 2021 Red Hat Inc.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- */
-
-#ifndef META_VIRTUAL_MONITOR_NATIVE_H
-#define META_VIRTUAL_MONITOR_NATIVE_H
-
-#include <stdint.h>
-
-#include "backends/meta-virtual-monitor.h"
-#include "backends/meta-backend-types.h"
-
-#define META_TYPE_VIRTUAL_MONITOR_NATIVE (meta_virtual_monitor_native_get_type ())
-G_DECLARE_FINAL_TYPE (MetaVirtualMonitorNative, meta_virtual_monitor_native,
- META, VIRTUAL_MONITOR_NATIVE,
- MetaVirtualMonitor)
-
-uint64_t meta_virtual_monitor_native_get_id (MetaVirtualMonitorNative *virtual_monitor_native);
-
-MetaCrtcMode * meta_virtual_monitor_native_get_crtc_mode (MetaVirtualMonitorNative *virtual_monitor_native);
-
-MetaCrtc * meta_virtual_monitor_native_get_crtc (MetaVirtualMonitorNative *virtual_monitor_native);
-
-MetaOutput * meta_virtual_monitor_native_get_output (MetaVirtualMonitorNative *virtual_monitor_native);
-
-MetaVirtualMonitorNative * meta_virtual_monitor_native_new (uint64_t id,
- const MetaVirtualMonitorInfo *info);
-
-#endif /* META_VIRTUAL_MONITOR_NATIVE_H */
diff --git a/src/backends/native/meta-xkb-utils.c b/src/backends/native/meta-xkb-utils.c
deleted file mode 100644
index 45f89bec7..000000000
--- a/src/backends/native/meta-xkb-utils.c
+++ /dev/null
@@ -1,137 +0,0 @@
-/*
- * Copyright (C) 2010 Intel Corporation.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
-
- * Authors:
- * Kristian Høgsberg
- * Damien Lespiau <damien.lespiau@intel.com>
- */
-
-#include "config.h"
-
-#include "backends/native/meta-xkb-utils.h"
-#include "clutter/clutter-keysyms.h"
-#include "clutter/clutter-mutter.h"
-
-/*
- * _clutter_event_new_from_evdev: Create a new Clutter ClutterKeyEvent
- * @device: a ClutterInputDevice
- * @xkb: XKB rules to translate the event
- * @_time: timestamp of the event
- * @key: a key code coming from a Linux input device
- * @state: TRUE if a press event, FALSE if a release event
- * @modifer_state: in/out
- *
- * Translate @key to a #ClutterKeyEvent using rules from xbbcommon.
- *
- * Return value: the new #ClutterEvent
- */
-ClutterEvent *
-meta_key_event_new_from_evdev (ClutterInputDevice *device,
- ClutterInputDevice *core_device,
- struct xkb_state *xkb_state,
- uint32_t button_state,
- uint32_t _time,
- xkb_keycode_t key,
- uint32_t state)
-{
- ClutterEvent *event;
- xkb_keysym_t sym;
- const xkb_keysym_t *syms;
- char buffer[8];
- int n;
-
- if (state)
- event = clutter_event_new (CLUTTER_KEY_PRESS);
- else
- event = clutter_event_new (CLUTTER_KEY_RELEASE);
-
- /* We use a fixed offset of 8 because evdev starts KEY_* numbering from
- * 0, whereas X11's minimum keycode, for really stupid reasons, is 8.
- * So the evdev XKB rules are based on the keycodes all being shifted
- * upwards by 8. */
- key = meta_xkb_evdev_to_keycode (key);
-
- n = xkb_key_get_syms (xkb_state, key, &syms);
- if (n == 1)
- sym = syms[0];
- else
- sym = XKB_KEY_NoSymbol;
-
- event->key.time = _time;
- meta_xkb_translate_state (event, xkb_state, button_state);
- event->key.hardware_keycode = key;
- event->key.keyval = sym;
- clutter_event_set_device (event, core_device);
- clutter_event_set_source_device (event, device);
-
- n = xkb_keysym_to_utf8 (sym, buffer, sizeof (buffer));
-
- if (n == 0)
- {
- /* not printable */
- event->key.unicode_value = (gunichar) '\0';
- }
- else
- {
- event->key.unicode_value = g_utf8_get_char_validated (buffer, n);
- if (event->key.unicode_value == -1 || event->key.unicode_value == -2)
- event->key.unicode_value = (gunichar) '\0';
- }
-
- return event;
-}
-
-void
-meta_xkb_translate_state (ClutterEvent *event,
- struct xkb_state *state,
- uint32_t button_state)
-{
- _clutter_event_set_state_full (event,
- button_state,
- xkb_state_serialize_mods (state, XKB_STATE_MODS_DEPRESSED),
- xkb_state_serialize_mods (state, XKB_STATE_MODS_LATCHED),
- xkb_state_serialize_mods (state, XKB_STATE_MODS_LOCKED),
- xkb_state_serialize_mods (state, XKB_STATE_MODS_EFFECTIVE) | button_state);
-}
-
-ClutterModifierType
-meta_xkb_translate_modifiers (struct xkb_state *state,
- ClutterModifierType button_state)
-{
- ClutterModifierType modifiers;
-
- modifiers = xkb_state_serialize_mods (state, XKB_STATE_MODS_EFFECTIVE);
- modifiers |= button_state;
-
- return modifiers;
-}
-
-uint32_t
-meta_xkb_keycode_to_evdev (uint32_t xkb_keycode)
-{
- /* The keycodes from the evdev backend are almost evdev
- * keycodes: we use the evdev keycode file, but xkb rules have an
- * offset by 8. See the comment in _clutter_key_event_new_from_evdev()
- */
- return xkb_keycode - 8;
-}
-
-uint32_t
-meta_xkb_evdev_to_keycode (uint32_t evcode)
-{
- /* The inverse of meta_xkb_keycode_to_evdev */
- return evcode + 8;
-}
diff --git a/src/backends/native/meta-xkb-utils.h b/src/backends/native/meta-xkb-utils.h
deleted file mode 100644
index d605813e6..000000000
--- a/src/backends/native/meta-xkb-utils.h
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright (C) 2010 Intel Corporation.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
-
- * Authors:
- * Damien Lespiau <damien.lespiau@intel.com>
- */
-
-#ifndef META_XKB_UTILS_H
-#define META_XKB_UTILS_H
-
-#include <xkbcommon/xkbcommon.h>
-
-#include "clutter/clutter.h"
-
-ClutterEvent * meta_key_event_new_from_evdev (ClutterInputDevice *device,
- ClutterInputDevice *core_keyboard,
- struct xkb_state *xkb_state,
- uint32_t button_state,
- uint32_t _time,
- uint32_t key,
- uint32_t state);
-void meta_xkb_translate_state (ClutterEvent *event,
- struct xkb_state *xkb_state,
- uint32_t button_state);
-ClutterModifierType meta_xkb_translate_modifiers (struct xkb_state *state,
- ClutterModifierType button_state);
-uint32_t meta_xkb_keycode_to_evdev (uint32_t hardware_keycode);
-uint32_t meta_xkb_evdev_to_keycode (uint32_t evcode);
-
-#endif /* META_XKB_UTILS_H */
diff --git a/src/backends/x11/cm/meta-backend-x11-cm.c b/src/backends/x11/cm/meta-backend-x11-cm.c
deleted file mode 100644
index ed2b7bb8b..000000000
--- a/src/backends/x11/cm/meta-backend-x11-cm.c
+++ /dev/null
@@ -1,550 +0,0 @@
-/*
- * Copyright (C) 2017 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-
-#include "config.h"
-
-#include "backends/x11/cm/meta-backend-x11-cm.h"
-
-#include <stdlib.h>
-#include <X11/XKBlib.h>
-#include <X11/extensions/XKBrules.h>
-#include <xkbcommon/xkbcommon-x11.h>
-
-#include "backends/meta-backend-private.h"
-#include "backends/meta-dnd-private.h"
-#include "backends/x11/meta-cursor-renderer-x11.h"
-#include "backends/x11/meta-cursor-tracker-x11.h"
-#include "backends/x11/meta-gpu-xrandr.h"
-#include "backends/x11/meta-input-settings-x11.h"
-#include "backends/x11/meta-monitor-manager-xrandr.h"
-#include "backends/x11/cm/meta-renderer-x11-cm.h"
-#include "compositor/meta-compositor-x11.h"
-#include "core/display-private.h"
-
-enum
-{
- PROP_0,
-
- PROP_DISPLAY_NAME,
-
- N_PROPS
-};
-
-static GParamSpec *obj_props[N_PROPS];
-
-struct _MetaBackendX11Cm
-{
- MetaBackendX11 parent;
-
- char *display_name;
-
- MetaCursorRenderer *cursor_renderer;
- char *keymap_layouts;
- char *keymap_variants;
- char *keymap_options;
- int locked_group;
-
- MetaInputSettings *input_settings;
-};
-
-G_DEFINE_TYPE (MetaBackendX11Cm, meta_backend_x11_cm, META_TYPE_BACKEND_X11)
-
-static void
-apply_keymap (MetaBackendX11 *x11);
-
-static void
-take_touch_grab (MetaBackend *backend)
-{
- MetaBackendX11 *x11 = META_BACKEND_X11 (backend);
- Display *xdisplay = meta_backend_x11_get_xdisplay (x11);
- unsigned char mask_bits[XIMaskLen (XI_LASTEVENT)] = { 0 };
- XIEventMask mask = { META_VIRTUAL_CORE_POINTER_ID, sizeof (mask_bits), mask_bits };
- XIGrabModifiers mods = { XIAnyModifier, 0 };
-
- XISetMask (mask.mask, XI_TouchBegin);
- XISetMask (mask.mask, XI_TouchUpdate);
- XISetMask (mask.mask, XI_TouchEnd);
-
- XIGrabTouchBegin (xdisplay, META_VIRTUAL_CORE_POINTER_ID,
- DefaultRootWindow (xdisplay),
- False, &mask, 1, &mods);
-}
-
-static void
-on_device_added (ClutterSeat *seat,
- ClutterInputDevice *device,
- gpointer user_data)
-{
- MetaBackendX11 *x11 = META_BACKEND_X11 (user_data);
-
- if (clutter_input_device_get_device_type (device) == CLUTTER_KEYBOARD_DEVICE)
- apply_keymap (x11);
-}
-
-static void
-meta_backend_x11_cm_post_init (MetaBackend *backend)
-{
- MetaBackendClass *parent_backend_class =
- META_BACKEND_CLASS (meta_backend_x11_cm_parent_class);
- MetaBackendX11Cm *x11_cm = META_BACKEND_X11_CM (backend);
- ClutterSeat *seat;
-
- seat = clutter_backend_get_default_seat (clutter_get_default_backend ());
- g_signal_connect_object (seat, "device-added",
- G_CALLBACK (on_device_added), backend, 0);
-
- x11_cm->input_settings = g_object_new (META_TYPE_INPUT_SETTINGS_X11, NULL);
-
- parent_backend_class->post_init (backend);
- take_touch_grab (backend);
-}
-
-static MetaRenderer *
-meta_backend_x11_cm_create_renderer (MetaBackend *backend,
- GError **error)
-{
- return g_object_new (META_TYPE_RENDERER_X11_CM,
- "backend", backend,
- NULL);
-}
-
-static MetaMonitorManager *
-meta_backend_x11_cm_create_monitor_manager (MetaBackend *backend,
- GError **error)
-{
- return g_object_new (META_TYPE_MONITOR_MANAGER_XRANDR,
- "backend", backend,
- NULL);
-}
-
-static MetaCursorRenderer *
-meta_backend_x11_cm_get_cursor_renderer (MetaBackend *backend,
- ClutterInputDevice *device)
-{
- MetaBackendX11Cm *x11_cm = META_BACKEND_X11_CM (backend);
-
- if (!x11_cm->cursor_renderer)
- {
- x11_cm->cursor_renderer =
- g_object_new (META_TYPE_CURSOR_RENDERER_X11,
- "backend", backend,
- "device", device,
- NULL);
- }
-
- return x11_cm->cursor_renderer;
-}
-
-static MetaCursorTracker *
-meta_backend_x11_cm_create_cursor_tracker (MetaBackend *backend)
-{
- return g_object_new (META_TYPE_CURSOR_TRACKER_X11,
- "backend", backend,
- NULL);
-}
-
-static MetaInputSettings *
-meta_backend_x11_cm_get_input_settings (MetaBackend *backend)
-{
- MetaBackendX11Cm *x11_cm = META_BACKEND_X11_CM (backend);
-
- return x11_cm->input_settings;
-}
-
-static void
-meta_backend_x11_cm_update_screen_size (MetaBackend *backend,
- int width,
- int height)
-{
- MetaBackendX11 *x11 = META_BACKEND_X11 (backend);
- Display *xdisplay = meta_backend_x11_get_xdisplay (x11);
- Window xwin = meta_backend_x11_get_xwindow (x11);
-
- XResizeWindow (xdisplay, xwin, width, height);
-}
-
-static void
-meta_backend_x11_cm_select_stage_events (MetaBackend *backend)
-{
- MetaBackendX11 *x11 = META_BACKEND_X11 (backend);
- Display *xdisplay = meta_backend_x11_get_xdisplay (x11);
- Window xwin = meta_backend_x11_get_xwindow (x11);
- unsigned char mask_bits[XIMaskLen (XI_LASTEVENT)] = { 0 };
- XIEventMask mask = { XIAllMasterDevices, sizeof (mask_bits), mask_bits };
-
- XISetMask (mask.mask, XI_KeyPress);
- XISetMask (mask.mask, XI_KeyRelease);
- XISetMask (mask.mask, XI_ButtonPress);
- XISetMask (mask.mask, XI_ButtonRelease);
- XISetMask (mask.mask, XI_Enter);
- XISetMask (mask.mask, XI_Leave);
- XISetMask (mask.mask, XI_FocusIn);
- XISetMask (mask.mask, XI_FocusOut);
- XISetMask (mask.mask, XI_Motion);
-
- XISelectEvents (xdisplay, xwin, &mask, 1);
-}
-
-static void
-get_xkbrf_var_defs (Display *xdisplay,
- const char *layouts,
- const char *variants,
- const char *options,
- char **rules_p,
- XkbRF_VarDefsRec *var_defs)
-{
- char *rules = NULL;
-
- /* Get it from the X property or fallback on defaults */
- if (!XkbRF_GetNamesProp (xdisplay, &rules, var_defs) || !rules)
- {
- rules = strdup (DEFAULT_XKB_RULES_FILE);
- var_defs->model = strdup (DEFAULT_XKB_MODEL);
- var_defs->layout = NULL;
- var_defs->variant = NULL;
- var_defs->options = NULL;
- }
-
- /* Swap in our new options... */
- free (var_defs->layout);
- var_defs->layout = strdup (layouts);
- free (var_defs->variant);
- var_defs->variant = strdup (variants);
- free (var_defs->options);
- var_defs->options = strdup (options);
-
- /* Sometimes, the property is a file path, and sometimes it's
- not. Normalize it so it's always a file path. */
- if (rules[0] == '/')
- *rules_p = g_strdup (rules);
- else
- *rules_p = g_build_filename (XKB_BASE, "rules", rules, NULL);
-
- free (rules);
-}
-
-static void
-free_xkbrf_var_defs (XkbRF_VarDefsRec *var_defs)
-{
- free (var_defs->model);
- free (var_defs->layout);
- free (var_defs->variant);
- free (var_defs->options);
-}
-
-static void
-free_xkb_component_names (XkbComponentNamesRec *p)
-{
- free (p->keymap);
- free (p->keycodes);
- free (p->types);
- free (p->compat);
- free (p->symbols);
- free (p->geometry);
-}
-
-static void
-upload_xkb_description (Display *xdisplay,
- const gchar *rules_file_path,
- XkbRF_VarDefsRec *var_defs,
- XkbComponentNamesRec *comp_names)
-{
- XkbDescRec *xkb_desc;
- gchar *rules_file;
-
- /* Upload it to the X server using the same method as setxkbmap */
- xkb_desc = XkbGetKeyboardByName (xdisplay,
- XkbUseCoreKbd,
- comp_names,
- XkbGBN_AllComponentsMask,
- XkbGBN_AllComponentsMask &
- (~XkbGBN_GeometryMask), True);
- if (!xkb_desc)
- {
- g_warning ("Couldn't upload new XKB keyboard description");
- return;
- }
-
- XkbFreeKeyboard (xkb_desc, 0, True);
-
- rules_file = g_path_get_basename (rules_file_path);
-
- if (!XkbRF_SetNamesProp (xdisplay, rules_file, var_defs))
- g_warning ("Couldn't update the XKB root window property");
-
- g_free (rules_file);
-}
-
-static void
-apply_keymap (MetaBackendX11 *x11)
-{
- MetaBackendX11Cm *x11_cm = META_BACKEND_X11_CM (x11);
- Display *xdisplay = meta_backend_x11_get_xdisplay (x11);
- XkbRF_RulesRec *xkb_rules;
- XkbRF_VarDefsRec xkb_var_defs = { 0 };
- char *rules_file_path;
-
- if (!x11_cm->keymap_layouts ||
- !x11_cm->keymap_variants ||
- !x11_cm->keymap_options)
- return;
-
- get_xkbrf_var_defs (xdisplay,
- x11_cm->keymap_layouts,
- x11_cm->keymap_variants,
- x11_cm->keymap_options,
- &rules_file_path,
- &xkb_var_defs);
-
- xkb_rules = XkbRF_Load (rules_file_path, NULL, True, True);
- if (xkb_rules)
- {
- XkbComponentNamesRec xkb_comp_names = { 0 };
-
- XkbRF_GetComponents (xkb_rules, &xkb_var_defs, &xkb_comp_names);
- upload_xkb_description (xdisplay, rules_file_path, &xkb_var_defs, &xkb_comp_names);
-
- free_xkb_component_names (&xkb_comp_names);
- XkbRF_Free (xkb_rules, True);
- }
- else
- {
- g_warning ("Couldn't load XKB rules");
- }
-
- free_xkbrf_var_defs (&xkb_var_defs);
- g_free (rules_file_path);
-}
-
-static void
-meta_backend_x11_cm_set_keymap (MetaBackend *backend,
- const char *layouts,
- const char *variants,
- const char *options)
-{
- MetaBackendX11 *x11 = META_BACKEND_X11 (backend);
- MetaBackendX11Cm *x11_cm = META_BACKEND_X11_CM (x11);
-
- g_free (x11_cm->keymap_layouts);
- x11_cm->keymap_layouts = g_strdup (layouts);
- g_free (x11_cm->keymap_variants);
- x11_cm->keymap_variants = g_strdup (variants);
- g_free (x11_cm->keymap_options);
- x11_cm->keymap_options = g_strdup (options);
-
- apply_keymap (x11);
-}
-
-static void
-meta_backend_x11_cm_lock_layout_group (MetaBackend *backend,
- guint idx)
-{
- MetaBackendX11 *x11 = META_BACKEND_X11 (backend);
- MetaBackendX11Cm *x11_cm = META_BACKEND_X11_CM (x11);
- Display *xdisplay = meta_backend_x11_get_xdisplay (x11);
-
- x11_cm->locked_group = idx;
- XkbLockGroup (xdisplay, XkbUseCoreKbd, idx);
-}
-
-static gboolean
-meta_backend_x11_cm_handle_host_xevent (MetaBackendX11 *backend_x11,
- XEvent *event)
-{
- MetaBackend *backend = META_BACKEND (backend_x11);
- MetaBackendX11 *x11 = META_BACKEND_X11 (backend);
- MetaBackendX11Cm *x11_cm = META_BACKEND_X11_CM (x11);
- MetaMonitorManager *monitor_manager =
- meta_backend_get_monitor_manager (backend);
- MetaMonitorManagerXrandr *monitor_manager_xrandr =
- META_MONITOR_MANAGER_XRANDR (monitor_manager);
- Display *xdisplay = meta_backend_x11_get_xdisplay (x11);
- gboolean bypass_clutter = FALSE;
- MetaDisplay *display;
-
- display = meta_get_display ();
- if (display)
- {
- MetaCompositor *compositor = display->compositor;
- MetaCompositorX11 *compositor_x11 = META_COMPOSITOR_X11 (compositor);
- Display *xdisplay = meta_backend_x11_get_xdisplay (x11);
-
- if (meta_dnd_handle_xdnd_event (backend, compositor_x11,
- xdisplay, event))
- bypass_clutter = TRUE;
- }
-
- if (event->type == meta_backend_x11_get_xkb_event_base (x11))
- {
- XkbEvent *xkb_ev = (XkbEvent *) event;
-
- if (xkb_ev->any.device == META_VIRTUAL_CORE_KEYBOARD_ID)
- {
- switch (xkb_ev->any.xkb_type)
- {
- case XkbStateNotify:
- if (xkb_ev->state.changed & XkbGroupLockMask)
- {
- if (x11_cm->locked_group != xkb_ev->state.locked_group)
- XkbLockGroup (xdisplay, XkbUseCoreKbd,
- x11_cm->locked_group);
- }
- break;
- default:
- break;
- }
- }
- }
-
- bypass_clutter |=
- meta_monitor_manager_xrandr_handle_xevent (monitor_manager_xrandr, event);
-
- return bypass_clutter;
-}
-
-static void
-meta_backend_x11_cm_translate_device_event (MetaBackendX11 *x11,
- XIDeviceEvent *device_event)
-{
- Window stage_window = meta_backend_x11_get_xwindow (x11);
-
- if (device_event->event != stage_window)
- {
- device_event->event = stage_window;
-
- /* As an X11 compositor, the stage window is always at 0,0, so
- * using root coordinates will give us correct stage coordinates
- * as well... */
- device_event->event_x = device_event->root_x;
- device_event->event_y = device_event->root_y;
- }
-}
-
-static void
-meta_backend_x11_cm_translate_crossing_event (MetaBackendX11 *x11,
- XIEnterEvent *enter_event)
-{
- Window stage_window = meta_backend_x11_get_xwindow (x11);
-
- if (enter_event->event != stage_window)
- {
- enter_event->event = stage_window;
- enter_event->event_x = enter_event->root_x;
- enter_event->event_y = enter_event->root_y;
- }
-}
-
-static void
-meta_backend_x11_cm_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- MetaBackendX11Cm *backend_x11_cm = META_BACKEND_X11_CM (object);
-
- switch (prop_id)
- {
- case PROP_DISPLAY_NAME:
- backend_x11_cm->display_name = g_value_dup_string (value);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-
-static void
-meta_backend_x11_cm_finalize (GObject *object)
-{
- MetaBackendX11Cm *x11_cm = META_BACKEND_X11_CM (object);
-
- g_clear_pointer (&x11_cm->display_name, g_free);
-
- G_OBJECT_CLASS (meta_backend_x11_cm_parent_class)->finalize (object);
-}
-
-static void
-meta_backend_x11_cm_constructed (GObject *object)
-{
- MetaBackendX11Cm *x11_cm = META_BACKEND_X11_CM (object);
- const char *display_name;
-
- if (x11_cm->display_name)
- display_name = (const char *) x11_cm->display_name;
- else
- display_name = g_getenv ("MUTTER_DISPLAY");
-
- if (display_name)
- g_setenv ("DISPLAY", display_name, TRUE);
-
- G_OBJECT_CLASS (meta_backend_x11_cm_parent_class)->constructed (object);
-}
-
-static void
-meta_backend_x11_cm_init (MetaBackendX11Cm *backend_x11_cm)
-{
- MetaGpuXrandr *gpu_xrandr;
-
- /*
- * The X server deals with multiple GPUs for us, so we just see what the X
- * server gives us as one single GPU, even though it may actually be backed
- * by multiple.
- */
- gpu_xrandr = meta_gpu_xrandr_new (META_BACKEND_X11 (backend_x11_cm));
- meta_backend_add_gpu (META_BACKEND (backend_x11_cm),
- META_GPU (gpu_xrandr));
-}
-
-static void
-meta_backend_x11_cm_class_init (MetaBackendX11CmClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
- MetaBackendClass *backend_class = META_BACKEND_CLASS (klass);
- MetaBackendX11Class *backend_x11_class = META_BACKEND_X11_CLASS (klass);
-
- object_class->set_property = meta_backend_x11_cm_set_property;
- object_class->finalize = meta_backend_x11_cm_finalize;
- object_class->constructed = meta_backend_x11_cm_constructed;
-
- backend_class->post_init = meta_backend_x11_cm_post_init;
- backend_class->create_renderer = meta_backend_x11_cm_create_renderer;
- backend_class->create_monitor_manager = meta_backend_x11_cm_create_monitor_manager;
- backend_class->get_cursor_renderer = meta_backend_x11_cm_get_cursor_renderer;
- backend_class->create_cursor_tracker = meta_backend_x11_cm_create_cursor_tracker;
- backend_class->get_input_settings = meta_backend_x11_cm_get_input_settings;
- backend_class->update_screen_size = meta_backend_x11_cm_update_screen_size;
- backend_class->select_stage_events = meta_backend_x11_cm_select_stage_events;
- backend_class->lock_layout_group = meta_backend_x11_cm_lock_layout_group;
- backend_class->set_keymap = meta_backend_x11_cm_set_keymap;
-
- backend_x11_class->handle_host_xevent = meta_backend_x11_cm_handle_host_xevent;
- backend_x11_class->translate_device_event = meta_backend_x11_cm_translate_device_event;
- backend_x11_class->translate_crossing_event = meta_backend_x11_cm_translate_crossing_event;
-
- obj_props[PROP_DISPLAY_NAME] =
- g_param_spec_string ("display-name",
- "display name",
- "X11 display name",
- NULL,
- G_PARAM_WRITABLE |
- G_PARAM_CONSTRUCT_ONLY |
- G_PARAM_STATIC_STRINGS);
- g_object_class_install_properties (object_class, N_PROPS, obj_props);
-}
-
diff --git a/src/backends/x11/cm/meta-backend-x11-cm.h b/src/backends/x11/cm/meta-backend-x11-cm.h
deleted file mode 100644
index 5332da13d..000000000
--- a/src/backends/x11/cm/meta-backend-x11-cm.h
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * Copyright (C) 2017 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-
-#ifndef META_BACKEND_X11_CM_H
-#define META_BACKEND_X11_CM_H
-
-#include <glib-object.h>
-
-#include "backends/x11/meta-backend-x11.h"
-
-#define META_TYPE_BACKEND_X11_CM (meta_backend_x11_cm_get_type ())
-G_DECLARE_FINAL_TYPE (MetaBackendX11Cm, meta_backend_x11_cm,
- META, BACKEND_X11_CM, MetaBackendX11)
-
-#endif /* META_BACKEND_X11_CM_H */
diff --git a/src/backends/x11/cm/meta-cursor-sprite-xfixes.c b/src/backends/x11/cm/meta-cursor-sprite-xfixes.c
deleted file mode 100644
index 0c524668e..000000000
--- a/src/backends/x11/cm/meta-cursor-sprite-xfixes.c
+++ /dev/null
@@ -1,231 +0,0 @@
-/*
- * Copyright 2013, 2018 Red Hat, Inc.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-#include "config.h"
-
-#include "backends/x11/cm/meta-cursor-sprite-xfixes.h"
-
-#include <X11/extensions/Xfixes.h>
-
-#include "core/display-private.h"
-#include "meta/meta-x11-display.h"
-
-enum
-{
- PROP_0,
-
- PROP_DISPLAY,
-
- N_PROPS
-};
-
-static GParamSpec *obj_props[N_PROPS];
-
-struct _MetaCursorSpriteXfixes
-{
- MetaCursorSprite parent;
-
- MetaDisplay *display;
-};
-
-static void
-meta_screen_cast_xfixes_init_initable_iface (GInitableIface *iface);
-
-G_DEFINE_TYPE_WITH_CODE (MetaCursorSpriteXfixes,
- meta_cursor_sprite_xfixes,
- META_TYPE_CURSOR_SPRITE,
- G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE,
- meta_screen_cast_xfixes_init_initable_iface))
-
-static void
-meta_cursor_sprite_xfixes_realize_texture (MetaCursorSprite *sprite)
-{
-}
-
-static gboolean
-meta_cursor_sprite_xfixes_is_animated (MetaCursorSprite *sprite)
-{
- return FALSE;
-}
-
-static void
-meta_cursor_sprite_xfixes_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- MetaCursorSpriteXfixes *sprite_xfixes = META_CURSOR_SPRITE_XFIXES (object);
-
- switch (prop_id)
- {
- case PROP_DISPLAY:
- g_value_set_object (value, sprite_xfixes->display);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-
-static void
-meta_cursor_sprite_xfixes_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- MetaCursorSpriteXfixes *sprite_xfixes = META_CURSOR_SPRITE_XFIXES (object);
-
- switch (prop_id)
- {
- case PROP_DISPLAY:
- sprite_xfixes->display = g_value_get_object (value);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-
-MetaCursorSpriteXfixes *
-meta_cursor_sprite_xfixes_new (MetaDisplay *display,
- GError **error)
-{
- return g_initable_new (META_TYPE_CURSOR_SPRITE_XFIXES,
- NULL, error,
- "display", display,
- NULL);
-}
-
-static gboolean
-meta_cursor_sprite_xfixes_initable_init (GInitable *initable,
- GCancellable *cancellable,
- GError **error)
-{
- MetaCursorSpriteXfixes *sprite_xfixes =
- META_CURSOR_SPRITE_XFIXES (initable);
- MetaCursorSprite *sprite = META_CURSOR_SPRITE (sprite_xfixes);
- MetaX11Display *x11_display;
- Display *xdisplay;
- XFixesCursorImage *cursor_image;
- CoglTexture2D *texture;
- uint8_t *cursor_data;
- gboolean free_cursor_data;
- ClutterBackend *clutter_backend;
- CoglContext *cogl_context;
-
- x11_display = meta_display_get_x11_display (sprite_xfixes->display);
- xdisplay = meta_x11_display_get_xdisplay (x11_display);
- cursor_image = XFixesGetCursorImage (xdisplay);
- if (!cursor_image)
- {
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- "Failed to get cursor image");
- return FALSE;
- }
-
- /*
- * Like all X APIs, XFixesGetCursorImage() returns arrays of 32-bit
- * quantities as arrays of long; we need to convert on 64 bit
- */
- if (sizeof (long) == 4)
- {
- cursor_data = (uint8_t *) cursor_image->pixels;
- free_cursor_data = FALSE;
- }
- else
- {
- int i, j;
- uint32_t *cursor_words;
- unsigned long *p;
- uint32_t *q;
-
- cursor_words = g_new (uint32_t,
- cursor_image->width * cursor_image->height);
- cursor_data = (uint8_t *) cursor_words;
-
- p = cursor_image->pixels;
- q = cursor_words;
- for (j = 0; j < cursor_image->height; j++)
- {
- for (i = 0; i < cursor_image->width; i++)
- *(q++) = *(p++);
- }
-
- free_cursor_data = TRUE;
- }
-
- clutter_backend = clutter_get_default_backend ();
- cogl_context = clutter_backend_get_cogl_context (clutter_backend);
- texture = cogl_texture_2d_new_from_data (cogl_context,
- cursor_image->width,
- cursor_image->height,
- CLUTTER_CAIRO_FORMAT_ARGB32,
- cursor_image->width * 4, /* stride */
- cursor_data,
- error);
-
- if (free_cursor_data)
- g_free (cursor_data);
-
- if (!sprite)
- return FALSE;
-
- meta_cursor_sprite_set_texture (sprite,
- COGL_TEXTURE (texture),
- cursor_image->xhot,
- cursor_image->yhot);
- cogl_object_unref (texture);
- XFree (cursor_image);
-
- return TRUE;
-}
-
-static void
-meta_screen_cast_xfixes_init_initable_iface (GInitableIface *iface)
-{
- iface->init = meta_cursor_sprite_xfixes_initable_init;
-}
-
-static void
-meta_cursor_sprite_xfixes_init (MetaCursorSpriteXfixes *sprite_xfixes)
-{
-}
-
-static void
-meta_cursor_sprite_xfixes_class_init (MetaCursorSpriteXfixesClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
- MetaCursorSpriteClass *cursor_sprite_class = META_CURSOR_SPRITE_CLASS (klass);
-
- object_class->get_property = meta_cursor_sprite_xfixes_get_property;
- object_class->set_property = meta_cursor_sprite_xfixes_set_property;
-
- cursor_sprite_class->realize_texture =
- meta_cursor_sprite_xfixes_realize_texture;
- cursor_sprite_class->is_animated = meta_cursor_sprite_xfixes_is_animated;
-
- obj_props[PROP_DISPLAY] =
- g_param_spec_object ("display",
- "display",
- "MetaDisplay",
- META_TYPE_DISPLAY,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT_ONLY |
- G_PARAM_STATIC_STRINGS);
- g_object_class_install_properties (object_class, N_PROPS, obj_props);
-}
diff --git a/src/backends/x11/cm/meta-cursor-sprite-xfixes.h b/src/backends/x11/cm/meta-cursor-sprite-xfixes.h
deleted file mode 100644
index c7073fc2c..000000000
--- a/src/backends/x11/cm/meta-cursor-sprite-xfixes.h
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright 2013, 2018 Red Hat, Inc.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-#ifndef META_CURSOR_SPRITE_XFIXES_H
-#define META_CURSOR_SPRITE_XFIXES_H
-
-#include <glib-object.h>
-
-#include "backends/meta-cursor.h"
-#include "meta/types.h"
-
-#define META_TYPE_CURSOR_SPRITE_XFIXES (meta_cursor_sprite_xfixes_get_type ())
-G_DECLARE_FINAL_TYPE (MetaCursorSpriteXfixes,
- meta_cursor_sprite_xfixes,
- META, CURSOR_SPRITE_XFIXES,
- MetaCursorSprite)
-
-MetaCursorSpriteXfixes * meta_cursor_sprite_xfixes_new (MetaDisplay *display,
- GError **error);
-
-#endif /* META_CURSOR_SPRITE_XFIXES_H */
diff --git a/src/backends/x11/cm/meta-renderer-x11-cm.c b/src/backends/x11/cm/meta-renderer-x11-cm.c
deleted file mode 100644
index afed2e377..000000000
--- a/src/backends/x11/cm/meta-renderer-x11-cm.c
+++ /dev/null
@@ -1,113 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2016 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- */
-
-#include "config.h"
-
-#include "backends/x11/cm/meta-renderer-x11-cm.h"
-
-#include "backends/meta-renderer-view.h"
-
-struct _MetaRendererX11Cm
-{
- MetaRendererX11 parent;
-
- MetaRendererView *screen_view;
-};
-
-G_DEFINE_TYPE (MetaRendererX11Cm, meta_renderer_x11_cm,
- META_TYPE_RENDERER_X11)
-
-void
-meta_renderer_x11_cm_init_screen_view (MetaRendererX11Cm *renderer_x11_cm,
- CoglOnscreen *onscreen,
- int width,
- int height)
-{
- MetaRenderer *renderer = META_RENDERER (renderer_x11_cm);
- MetaBackend *backend = meta_renderer_get_backend (renderer);
- ClutterActor *stage = meta_backend_get_stage (backend);
- cairo_rectangle_int_t view_layout;
-
- g_return_if_fail (!renderer_x11_cm->screen_view);
-
- view_layout = (cairo_rectangle_int_t) {
- .width = width,
- .height = height,
- };
- renderer_x11_cm->screen_view = g_object_new (META_TYPE_RENDERER_VIEW,
- "name", "X11 screen",
- "stage", stage,
- "layout", &view_layout,
- "framebuffer", onscreen,
- NULL);
- meta_renderer_add_view (META_RENDERER (renderer_x11_cm),
- renderer_x11_cm->screen_view);
-}
-
-void
-meta_renderer_x11_cm_resize (MetaRendererX11Cm *renderer_x11_cm,
- int width,
- int height)
-{
- cairo_rectangle_int_t view_layout;
-
- view_layout = (cairo_rectangle_int_t) {
- .width = width,
- .height = height,
- };
-
- g_object_set (G_OBJECT (renderer_x11_cm->screen_view),
- "layout", &view_layout,
- NULL);
-}
-
-static void
-meta_renderer_x11_cm_rebuild_views (MetaRenderer *renderer)
-{
- MetaRendererX11Cm *renderer_x11_cm = META_RENDERER_X11_CM (renderer);
-
- g_return_if_fail (!meta_renderer_get_views (renderer));
-
- meta_renderer_add_view (renderer, renderer_x11_cm->screen_view);
-}
-
-static GList *
-meta_renderer_x11_cm_get_views_for_monitor (MetaRenderer *renderer,
- MetaMonitor *monitor)
-{
- return g_list_prepend (NULL, meta_renderer_get_views (renderer)->data);
-}
-
-static void
-meta_renderer_x11_cm_init (MetaRendererX11Cm *renderer_x11_cm)
-{
-}
-
-static void
-meta_renderer_x11_cm_class_init (MetaRendererX11CmClass *klass)
-{
- MetaRendererClass *renderer_class = META_RENDERER_CLASS (klass);
-
- renderer_class->rebuild_views = meta_renderer_x11_cm_rebuild_views;
- renderer_class->get_views_for_monitor =
- meta_renderer_x11_cm_get_views_for_monitor;
-}
diff --git a/src/backends/x11/cm/meta-renderer-x11-cm.h b/src/backends/x11/cm/meta-renderer-x11-cm.h
deleted file mode 100644
index 7ddb3445d..000000000
--- a/src/backends/x11/cm/meta-renderer-x11-cm.h
+++ /dev/null
@@ -1,42 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2016 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- */
-
-#ifndef META_RENDERER_X11_CM_H
-#define META_RENDERER_X11_CM_H
-
-#include "backends/x11/meta-renderer-x11.h"
-
-#define META_TYPE_RENDERER_X11_CM (meta_renderer_x11_cm_get_type ())
-G_DECLARE_FINAL_TYPE (MetaRendererX11Cm, meta_renderer_x11_cm,
- META, RENDERER_X11_CM,
- MetaRendererX11)
-
-void meta_renderer_x11_cm_init_screen_view (MetaRendererX11Cm *renderer_x11_cm,
- CoglOnscreen *onscreen,
- int width,
- int height);
-
-void meta_renderer_x11_cm_resize (MetaRendererX11Cm *renderer_x11_cm,
- int width,
- int height);
-
-#endif /* META_RENDERER_X11_CM_H */
diff --git a/src/backends/x11/meta-backend-x11.c b/src/backends/x11/meta-backend-x11.c
deleted file mode 100644
index 09a13505d..000000000
--- a/src/backends/x11/meta-backend-x11.c
+++ /dev/null
@@ -1,996 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2014 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Written by:
- * Jasper St. Pierre <jstpierre@mecheye.net>
- */
-
-/**
- * SECTION:meta-backend-x11
- * @title: MetaBackendX11
- * @short_description: A X11 MetaBackend
- *
- * MetaBackendX11 is an implementation of #MetaBackend using X and X
- * extensions, like XInput and XKB.
- */
-
-#include "config.h"
-
-#include "backends/x11/meta-backend-x11.h"
-
-#include <X11/XKBlib.h>
-#include <X11/Xlib-xcb.h>
-#include <X11/extensions/sync.h>
-#include <stdlib.h>
-#include <string.h>
-#include <xkbcommon/xkbcommon-x11.h>
-
-#include "backends/meta-idle-monitor-private.h"
-#include "backends/meta-keymap-utils.h"
-#include "backends/meta-stage-private.h"
-#include "backends/x11/meta-clutter-backend-x11.h"
-#include "backends/x11/meta-event-x11.h"
-#include "backends/x11/meta-seat-x11.h"
-#include "backends/x11/meta-stage-x11.h"
-#include "backends/x11/meta-renderer-x11.h"
-#include "backends/x11/meta-xkb-a11y-x11.h"
-#include "clutter/clutter.h"
-#include "compositor/compositor-private.h"
-#include "core/display-private.h"
-#include "meta/meta-cursor-tracker.h"
-#include "meta/util.h"
-
-struct _MetaBackendX11Private
-{
- /* The host X11 display */
- Display *xdisplay;
- xcb_connection_t *xcb;
- GSource *source;
-
- int xsync_event_base;
- int xsync_error_base;
- XSyncAlarm user_active_alarm;
- XSyncCounter counter;
-
- int current_touch_replay_sync_serial;
- int pending_touch_replay_sync_serial;
- Atom touch_replay_sync_atom;
-
- int xinput_opcode;
- int xinput_event_base;
- int xinput_error_base;
- Time latest_evtime;
-
- uint8_t xkb_event_base;
- uint8_t xkb_error_base;
-
- gulong keymap_state_changed_id;
-
- struct xkb_keymap *keymap;
- xkb_layout_index_t keymap_layout_group;
-
- MetaLogicalMonitor *cached_current_logical_monitor;
-};
-typedef struct _MetaBackendX11Private MetaBackendX11Private;
-
-static GInitableIface *initable_parent_iface;
-
-static void
-initable_iface_init (GInitableIface *initable_iface);
-
-G_DEFINE_TYPE_WITH_CODE (MetaBackendX11, meta_backend_x11, META_TYPE_BACKEND,
- G_ADD_PRIVATE (MetaBackendX11)
- G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE,
- initable_iface_init));
-
-
-static void
-uint64_to_xsync_value (uint64_t value,
- XSyncValue *xsync_value)
-{
- XSyncIntsToValue (xsync_value, value & 0xffffffff, value >> 32);
-}
-
-static XSyncAlarm
-xsync_user_active_alarm_set (MetaBackendX11Private *priv)
-{
- XSyncAlarmAttributes attr;
- XSyncValue delta;
- unsigned long flags;
-
- flags = (XSyncCACounter | XSyncCAValueType | XSyncCATestType |
- XSyncCAValue | XSyncCADelta | XSyncCAEvents);
-
- XSyncIntToValue (&delta, 0);
- attr.trigger.counter = priv->counter;
- attr.trigger.value_type = XSyncAbsolute;
- attr.delta = delta;
- attr.events = TRUE;
-
- uint64_to_xsync_value (1, &attr.trigger.wait_value);
-
- attr.trigger.test_type = XSyncNegativeTransition;
- return XSyncCreateAlarm (priv->xdisplay, flags, &attr);
-}
-
-static XSyncCounter
-find_idletime_counter (MetaBackendX11Private *priv)
-{
- int i;
- int n_counters;
- XSyncSystemCounter *counters;
- XSyncCounter counter = None;
-
- counters = XSyncListSystemCounters (priv->xdisplay, &n_counters);
- for (i = 0; i < n_counters; i++)
- {
- if (g_strcmp0 (counters[i].name, "IDLETIME") == 0)
- {
- counter = counters[i].counter;
- break;
- }
- }
- XSyncFreeSystemCounterList (counters);
-
- return counter;
-}
-
-static void
-handle_alarm_notify (MetaBackend *backend,
- XSyncAlarmNotifyEvent *alarm_event)
-{
- MetaBackendX11 *x11 = META_BACKEND_X11 (backend);
- MetaBackendX11Private *priv = meta_backend_x11_get_instance_private (x11);
- MetaIdleMonitor *idle_monitor;
- XSyncAlarmAttributes attr;
- ClutterBackend *clutter_backend;
- ClutterSeat *seat;
- ClutterInputDevice *pointer;
-
- if (alarm_event->state != XSyncAlarmActive ||
- alarm_event->alarm != priv->user_active_alarm)
- return;
-
- attr.events = TRUE;
- XSyncChangeAlarm (priv->xdisplay, priv->user_active_alarm,
- XSyncCAEvents, &attr);
-
- clutter_backend = meta_backend_get_clutter_backend (backend);
- seat = clutter_backend_get_default_seat (clutter_backend);
- pointer = clutter_seat_get_pointer (seat);
- idle_monitor = meta_backend_get_idle_monitor (backend, pointer);
- meta_idle_monitor_reset_idletime (idle_monitor);
-}
-
-static void
-meta_backend_x11_translate_device_event (MetaBackendX11 *x11,
- XIDeviceEvent *device_event)
-{
- MetaBackendX11Class *backend_x11_class =
- META_BACKEND_X11_GET_CLASS (x11);
-
- backend_x11_class->translate_device_event (x11, device_event);
-}
-
-static void
-maybe_translate_touch_replay_pointer_event (MetaBackendX11 *x11,
- XIDeviceEvent *device_event)
-{
- MetaBackendX11Private *priv = meta_backend_x11_get_instance_private (x11);
-
- if (!device_event->send_event &&
- device_event->time != META_CURRENT_TIME &&
- priv->current_touch_replay_sync_serial !=
- priv->pending_touch_replay_sync_serial &&
- XSERVER_TIME_IS_BEFORE (device_event->time, priv->latest_evtime))
- {
- /* Emulated pointer events received after XIRejectTouch is received
- * on a passive touch grab will contain older timestamps, update those
- * so we dont get InvalidTime at grabs.
- */
- device_event->time = priv->latest_evtime;
- }
-}
-
-static void
-translate_device_event (MetaBackendX11 *x11,
- XIDeviceEvent *device_event)
-{
- MetaBackendX11Private *priv = meta_backend_x11_get_instance_private (x11);
-
- meta_backend_x11_translate_device_event (x11, device_event);
-
- if (!device_event->send_event && device_event->time != META_CURRENT_TIME)
- priv->latest_evtime = device_event->time;
-}
-
-static void
-meta_backend_x11_translate_crossing_event (MetaBackendX11 *x11,
- XIEnterEvent *enter_event)
-{
- MetaBackendX11Class *backend_x11_class =
- META_BACKEND_X11_GET_CLASS (x11);
-
- if (backend_x11_class->translate_crossing_event)
- backend_x11_class->translate_crossing_event (x11, enter_event);
-}
-
-static void
-translate_crossing_event (MetaBackendX11 *x11,
- XIEnterEvent *enter_event)
-{
- /* Throw out weird events generated by grabs. */
- if (enter_event->mode == XINotifyGrab ||
- enter_event->mode == XINotifyUngrab)
- {
- enter_event->event = None;
- return;
- }
-
- meta_backend_x11_translate_crossing_event (x11, enter_event);
-}
-
-static void
-handle_device_change (MetaBackendX11 *x11,
- XIEvent *event)
-{
- XIDeviceChangedEvent *device_changed;
- ClutterInputDevice *device;
- ClutterBackend *backend;
- ClutterSeat *seat;
-
- if (event->evtype != XI_DeviceChanged)
- return;
-
- device_changed = (XIDeviceChangedEvent *) event;
-
- if (device_changed->reason != XISlaveSwitch)
- return;
-
- backend = meta_backend_get_clutter_backend (META_BACKEND (x11));
- seat = clutter_backend_get_default_seat (backend);
- device = meta_seat_x11_lookup_device_id (META_SEAT_X11 (seat),
- device_changed->sourceid);
- meta_backend_update_last_device (META_BACKEND (x11), device);
-}
-
-/* Clutter makes the assumption that there is only one X window
- * per stage, which is a valid assumption to make for a generic
- * application toolkit. As such, it will ignore any events sent
- * to the a stage that isn't its X window.
- *
- * When running as an X window manager, we need to respond to
- * events from lots of windows. Trick Clutter into translating
- * these events by pretending we got an event on the stage window.
- */
-static void
-maybe_spoof_event_as_stage_event (MetaBackendX11 *x11,
- XIEvent *input_event)
-{
- switch (input_event->evtype)
- {
- case XI_Motion:
- case XI_ButtonPress:
- case XI_ButtonRelease:
- maybe_translate_touch_replay_pointer_event (x11,
- (XIDeviceEvent *) input_event);
- G_GNUC_FALLTHROUGH;
- case XI_KeyPress:
- case XI_KeyRelease:
- case XI_TouchBegin:
- case XI_TouchUpdate:
- case XI_TouchEnd:
- translate_device_event (x11, (XIDeviceEvent *) input_event);
- break;
- case XI_Enter:
- case XI_Leave:
- translate_crossing_event (x11, (XIEnterEvent *) input_event);
- break;
- default:
- break;
- }
-}
-
-static void
-handle_input_event (MetaBackendX11 *x11,
- XEvent *event)
-{
- MetaBackendX11Private *priv = meta_backend_x11_get_instance_private (x11);
-
- if (event->type == GenericEvent &&
- event->xcookie.extension == priv->xinput_opcode)
- {
- XIEvent *input_event = (XIEvent *) event->xcookie.data;
-
- if (input_event->evtype == XI_DeviceChanged)
- handle_device_change (x11, input_event);
- else
- maybe_spoof_event_as_stage_event (x11, input_event);
- }
-}
-
-static void
-keymap_changed (MetaBackend *backend)
-{
- MetaBackendX11 *x11 = META_BACKEND_X11 (backend);
- MetaBackendX11Private *priv = meta_backend_x11_get_instance_private (x11);
-
- if (priv->keymap)
- {
- xkb_keymap_unref (priv->keymap);
- priv->keymap = NULL;
- }
-
- g_signal_emit_by_name (backend, "keymap-changed", 0);
-}
-
-static gboolean
-meta_backend_x11_handle_host_xevent (MetaBackendX11 *backend_x11,
- XEvent *event)
-{
- MetaBackendX11Class *backend_x11_class =
- META_BACKEND_X11_GET_CLASS (backend_x11);
-
- return backend_x11_class->handle_host_xevent (backend_x11, event);
-}
-
-static void
-handle_host_xevent (MetaBackend *backend,
- XEvent *event)
-{
- MetaBackendX11 *x11 = META_BACKEND_X11 (backend);
- MetaBackendX11Private *priv = meta_backend_x11_get_instance_private (x11);
- gboolean bypass_clutter = FALSE;
- MetaDisplay *display;
-
- switch (event->type)
- {
- case ClientMessage:
- if (event->xclient.window == meta_backend_x11_get_xwindow (x11) &&
- event->xclient.message_type == priv->touch_replay_sync_atom)
- priv->current_touch_replay_sync_serial = event->xclient.data.l[0];
- break;
- default:
- break;
- }
-
- XGetEventData (priv->xdisplay, &event->xcookie);
-
- display = meta_get_display ();
- if (display)
- {
- MetaCompositor *compositor = display->compositor;
- MetaPluginManager *plugin_mgr =
- meta_compositor_get_plugin_manager (compositor);
-
- if (meta_plugin_manager_xevent_filter (plugin_mgr, event))
- bypass_clutter = TRUE;
- }
-
- bypass_clutter = (meta_backend_x11_handle_host_xevent (x11, event) ||
- bypass_clutter);
-
- if (event->type == (priv->xsync_event_base + XSyncAlarmNotify))
- handle_alarm_notify (backend, (XSyncAlarmNotifyEvent *) event);
-
- if (event->type == priv->xkb_event_base)
- {
- XkbEvent *xkb_ev = (XkbEvent *) event;
-
- if (xkb_ev->any.device == META_VIRTUAL_CORE_KEYBOARD_ID)
- {
- switch (xkb_ev->any.xkb_type)
- {
- case XkbNewKeyboardNotify:
- case XkbMapNotify:
- keymap_changed (backend);
- break;
- case XkbStateNotify:
- if (xkb_ev->state.changed & XkbGroupLockMask)
- {
- int layout_group;
- gboolean layout_group_changed;
-
- layout_group = xkb_ev->state.locked_group;
- layout_group_changed =
- (int) priv->keymap_layout_group != layout_group;
- priv->keymap_layout_group = layout_group;
-
- if (layout_group_changed)
- meta_backend_notify_keymap_layout_group_changed (backend,
- layout_group);
- }
- break;
- default:
- break;
- }
- }
- }
-
- if (!bypass_clutter)
- {
- handle_input_event (x11, event);
- meta_x11_handle_event (event);
- }
-
- XFreeEventData (priv->xdisplay, &event->xcookie);
-}
-
-typedef struct {
- GSource base;
- GPollFD event_poll_fd;
- MetaBackend *backend;
-} XEventSource;
-
-static gboolean
-x_event_source_prepare (GSource *source,
- int *timeout)
-{
- XEventSource *x_source = (XEventSource *) source;
- MetaBackend *backend = x_source->backend;
- MetaBackendX11 *x11 = META_BACKEND_X11 (backend);
- MetaBackendX11Private *priv = meta_backend_x11_get_instance_private (x11);
-
- *timeout = -1;
-
- return XPending (priv->xdisplay);
-}
-
-static gboolean
-x_event_source_check (GSource *source)
-{
- XEventSource *x_source = (XEventSource *) source;
- MetaBackend *backend = x_source->backend;
- MetaBackendX11 *x11 = META_BACKEND_X11 (backend);
- MetaBackendX11Private *priv = meta_backend_x11_get_instance_private (x11);
-
- return XPending (priv->xdisplay);
-}
-
-static gboolean
-x_event_source_dispatch (GSource *source,
- GSourceFunc callback,
- gpointer user_data)
-{
- XEventSource *x_source = (XEventSource *) source;
- MetaBackend *backend = x_source->backend;
- MetaBackendX11 *x11 = META_BACKEND_X11 (backend);
- MetaBackendX11Private *priv = meta_backend_x11_get_instance_private (x11);
-
- while (XPending (priv->xdisplay))
- {
- XEvent event;
-
- XNextEvent (priv->xdisplay, &event);
-
- handle_host_xevent (backend, &event);
- }
-
- return TRUE;
-}
-
-static GSourceFuncs x_event_funcs = {
- x_event_source_prepare,
- x_event_source_check,
- x_event_source_dispatch,
-};
-
-static GSource *
-x_event_source_new (MetaBackend *backend)
-{
- MetaBackendX11 *x11 = META_BACKEND_X11 (backend);
- MetaBackendX11Private *priv = meta_backend_x11_get_instance_private (x11);
- GSource *source;
- XEventSource *x_source;
-
- source = g_source_new (&x_event_funcs, sizeof (XEventSource));
- x_source = (XEventSource *) source;
- x_source->backend = backend;
- x_source->event_poll_fd.fd = ConnectionNumber (priv->xdisplay);
- x_source->event_poll_fd.events = G_IO_IN;
- g_source_add_poll (source, &x_source->event_poll_fd);
-
- g_source_attach (source, NULL);
- return source;
-}
-
-static void
-on_monitors_changed (MetaMonitorManager *manager,
- MetaBackend *backend)
-{
- MetaBackendX11 *x11 = META_BACKEND_X11 (backend);
- MetaBackendX11Private *priv = meta_backend_x11_get_instance_private (x11);
-
- priv->cached_current_logical_monitor = NULL;
-}
-
-static void
-on_kbd_a11y_changed (MetaInputSettings *input_settings,
- MetaKbdA11ySettings *a11y_settings,
- MetaBackend *backend)
-{
- ClutterBackend *clutter_backend = meta_backend_get_clutter_backend (backend);
- ClutterSeat *seat = clutter_backend_get_default_seat (clutter_backend);
-
- meta_seat_x11_apply_kbd_a11y_settings (seat, a11y_settings);
-}
-
-static void
-meta_backend_x11_post_init (MetaBackend *backend)
-{
- MetaBackendX11 *x11 = META_BACKEND_X11 (backend);
- MetaBackendX11Private *priv = meta_backend_x11_get_instance_private (x11);
- MetaMonitorManager *monitor_manager;
- ClutterBackend *clutter_backend;
- ClutterSeat *seat;
- MetaInputSettings *input_settings;
- int major, minor;
- gboolean has_xi = FALSE;
-
- priv->source = x_event_source_new (backend);
-
- if (!XSyncQueryExtension (priv->xdisplay, &priv->xsync_event_base, &priv->xsync_error_base) ||
- !XSyncInitialize (priv->xdisplay, &major, &minor))
- meta_fatal ("Could not initialize XSync");
-
- priv->counter = find_idletime_counter (priv);
- if (priv->counter == None)
- meta_fatal ("Could not initialize XSync counter");
-
- priv->user_active_alarm = xsync_user_active_alarm_set (priv);
-
- if (XQueryExtension (priv->xdisplay,
- "XInputExtension",
- &priv->xinput_opcode,
- &priv->xinput_error_base,
- &priv->xinput_event_base))
- {
- major = 2; minor = 3;
- if (XIQueryVersion (priv->xdisplay, &major, &minor) == Success)
- {
- int version = (major * 10) + minor;
- if (version >= 22)
- has_xi = TRUE;
- }
- }
-
- if (!has_xi)
- meta_fatal ("X server doesn't have the XInput extension, version 2.2 or newer");
-
- if (!xkb_x11_setup_xkb_extension (priv->xcb,
- XKB_X11_MIN_MAJOR_XKB_VERSION,
- XKB_X11_MIN_MINOR_XKB_VERSION,
- XKB_X11_SETUP_XKB_EXTENSION_NO_FLAGS,
- NULL, NULL,
- &priv->xkb_event_base,
- &priv->xkb_error_base))
- meta_fatal ("X server doesn't have the XKB extension, version %d.%d or newer",
- XKB_X11_MIN_MAJOR_XKB_VERSION, XKB_X11_MIN_MINOR_XKB_VERSION);
-
- META_BACKEND_CLASS (meta_backend_x11_parent_class)->post_init (backend);
-
- monitor_manager = meta_backend_get_monitor_manager (backend);
- g_signal_connect (monitor_manager, "monitors-changed-internal",
- G_CALLBACK (on_monitors_changed), backend);
-
- priv->touch_replay_sync_atom = XInternAtom (priv->xdisplay,
- "_MUTTER_TOUCH_SEQUENCE_SYNC",
- False);
-
- clutter_backend = meta_backend_get_clutter_backend (backend);
- seat = clutter_backend_get_default_seat (clutter_backend);
- meta_seat_x11_notify_devices (META_SEAT_X11 (seat),
- CLUTTER_STAGE (meta_backend_get_stage (backend)));
-
- input_settings = meta_backend_get_input_settings (backend);
-
- if (input_settings)
- {
- g_signal_connect_object (meta_backend_get_input_settings (backend),
- "kbd-a11y-changed",
- G_CALLBACK (on_kbd_a11y_changed), backend, 0);
-
- if (meta_input_settings_maybe_restore_numlock_state (input_settings))
- {
- unsigned int num_mask;
-
- num_mask = XkbKeysymToModifiers (priv->xdisplay, XK_Num_Lock);
- XkbLockModifiers (priv->xdisplay, XkbUseCoreKbd, num_mask, num_mask);
- }
- }
-}
-
-static ClutterBackend *
-meta_backend_x11_create_clutter_backend (MetaBackend *backend)
-{
- return g_object_new (META_TYPE_CLUTTER_BACKEND_X11, NULL);
-}
-
-static ClutterSeat *
-meta_backend_x11_create_default_seat (MetaBackend *backend,
- GError **error)
-{
- MetaBackendX11 *x11 = META_BACKEND_X11 (backend);
- MetaBackendX11Private *priv = meta_backend_x11_get_instance_private (x11);
- int event_base, first_event, first_error;
- int major, minor;
- MetaSeatX11 *seat_x11;
-
- if (!XQueryExtension (priv->xdisplay,
- "XInputExtension",
- &event_base,
- &first_event,
- &first_error))
- {
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- "Failed to query XInputExtension");
- return NULL;
- }
-
- major = 2;
- minor = 3;
- if (XIQueryVersion (priv->xdisplay, &major, &minor) == BadRequest)
- {
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- "Incompatible XInputExtension version");
- return NULL;
- }
-
- seat_x11 = meta_seat_x11_new (event_base,
- META_VIRTUAL_CORE_POINTER_ID,
- META_VIRTUAL_CORE_KEYBOARD_ID);
- return CLUTTER_SEAT (seat_x11);
-}
-
-static gboolean
-meta_backend_x11_grab_device (MetaBackend *backend,
- int device_id,
- uint32_t timestamp)
-{
- MetaBackendX11 *x11 = META_BACKEND_X11 (backend);
- MetaBackendX11Private *priv = meta_backend_x11_get_instance_private (x11);
- unsigned char mask_bits[XIMaskLen (XI_LASTEVENT)] = { 0 };
- XIEventMask mask = { XIAllMasterDevices, sizeof (mask_bits), mask_bits };
- int ret;
-
- if (timestamp != META_CURRENT_TIME &&
- XSERVER_TIME_IS_BEFORE (timestamp, priv->latest_evtime))
- timestamp = priv->latest_evtime;
-
- XISetMask (mask.mask, XI_ButtonPress);
- XISetMask (mask.mask, XI_ButtonRelease);
- XISetMask (mask.mask, XI_Enter);
- XISetMask (mask.mask, XI_Leave);
- XISetMask (mask.mask, XI_Motion);
- XISetMask (mask.mask, XI_KeyPress);
- XISetMask (mask.mask, XI_KeyRelease);
-
- ret = XIGrabDevice (priv->xdisplay, device_id,
- meta_backend_x11_get_xwindow (x11),
- timestamp,
- None,
- XIGrabModeAsync, XIGrabModeAsync,
- False, /* owner_events */
- &mask);
-
- return (ret == Success);
-}
-
-static gboolean
-meta_backend_x11_ungrab_device (MetaBackend *backend,
- int device_id,
- uint32_t timestamp)
-{
- MetaBackendX11 *x11 = META_BACKEND_X11 (backend);
- MetaBackendX11Private *priv = meta_backend_x11_get_instance_private (x11);
- int ret;
-
- ret = XIUngrabDevice (priv->xdisplay, device_id, timestamp);
- XFlush (priv->xdisplay);
-
- return (ret == Success);
-}
-
-static void
-meta_backend_x11_finish_touch_sequence (MetaBackend *backend,
- ClutterEventSequence *sequence,
- MetaSequenceState state)
-{
- MetaBackendX11 *x11 = META_BACKEND_X11 (backend);
- MetaBackendX11Private *priv = meta_backend_x11_get_instance_private (x11);
- int event_mode;
-
- if (state == META_SEQUENCE_ACCEPTED)
- event_mode = XIAcceptTouch;
- else if (state == META_SEQUENCE_REJECTED)
- event_mode = XIRejectTouch;
- else
- g_return_if_reached ();
-
- XIAllowTouchEvents (priv->xdisplay,
- META_VIRTUAL_CORE_POINTER_ID,
- clutter_event_sequence_get_slot (sequence),
- DefaultRootWindow (priv->xdisplay), event_mode);
-
- if (state == META_SEQUENCE_REJECTED)
- {
- XClientMessageEvent ev;
-
- ev = (XClientMessageEvent) {
- .type = ClientMessage,
- .window = meta_backend_x11_get_xwindow (x11),
- .message_type = priv->touch_replay_sync_atom,
- .format = 32,
- .data.l[0] = ++priv->pending_touch_replay_sync_serial,
- };
- XSendEvent (priv->xdisplay, meta_backend_x11_get_xwindow (x11),
- False, 0, (XEvent *) &ev);
- }
-}
-
-static MetaLogicalMonitor *
-meta_backend_x11_get_current_logical_monitor (MetaBackend *backend)
-{
- MetaBackendX11 *x11 = META_BACKEND_X11 (backend);
- MetaBackendX11Private *priv = meta_backend_x11_get_instance_private (x11);
- MetaCursorTracker *cursor_tracker;
- graphene_point_t point;
- MetaMonitorManager *monitor_manager;
- MetaLogicalMonitor *logical_monitor;
-
- if (priv->cached_current_logical_monitor)
- return priv->cached_current_logical_monitor;
-
- cursor_tracker = meta_backend_get_cursor_tracker (backend);
- meta_cursor_tracker_get_pointer (cursor_tracker, &point, NULL);
- monitor_manager = meta_backend_get_monitor_manager (backend);
- logical_monitor =
- meta_monitor_manager_get_logical_monitor_at (monitor_manager,
- point.x, point.y);
-
- if (!logical_monitor && monitor_manager->logical_monitors)
- logical_monitor = monitor_manager->logical_monitors->data;
-
- priv->cached_current_logical_monitor = logical_monitor;
- return priv->cached_current_logical_monitor;
-}
-
-static struct xkb_keymap *
-meta_backend_x11_get_keymap (MetaBackend *backend)
-{
- MetaBackendX11 *x11 = META_BACKEND_X11 (backend);
- MetaBackendX11Private *priv = meta_backend_x11_get_instance_private (x11);
-
- if (priv->keymap == NULL)
- {
- struct xkb_context *context = meta_create_xkb_context ();
- priv->keymap = xkb_x11_keymap_new_from_device (context,
- priv->xcb,
- xkb_x11_get_core_keyboard_device_id (priv->xcb),
- XKB_KEYMAP_COMPILE_NO_FLAGS);
- if (priv->keymap == NULL)
- priv->keymap = xkb_keymap_new_from_names (context, NULL, XKB_KEYMAP_COMPILE_NO_FLAGS);
-
- xkb_context_unref (context);
- }
-
- return priv->keymap;
-}
-
-static xkb_layout_index_t
-meta_backend_x11_get_keymap_layout_group (MetaBackend *backend)
-{
- MetaBackendX11 *x11 = META_BACKEND_X11 (backend);
- MetaBackendX11Private *priv = meta_backend_x11_get_instance_private (x11);
-
- return priv->keymap_layout_group;
-}
-
-void
-meta_backend_x11_handle_event (MetaBackendX11 *x11,
- XEvent *xevent)
-{
- MetaBackendX11Private *priv = meta_backend_x11_get_instance_private (x11);
-
- priv->cached_current_logical_monitor = NULL;
-}
-
-uint8_t
-meta_backend_x11_get_xkb_event_base (MetaBackendX11 *x11)
-{
- MetaBackendX11Private *priv = meta_backend_x11_get_instance_private (x11);
-
- return priv->xkb_event_base;
-}
-
-static void
-init_xkb_state (MetaBackendX11 *x11)
-{
- MetaBackendX11Private *priv = meta_backend_x11_get_instance_private (x11);
- struct xkb_keymap *keymap;
- int32_t device_id;
- struct xkb_state *state;
-
- keymap = meta_backend_get_keymap (META_BACKEND (x11));
-
- device_id = xkb_x11_get_core_keyboard_device_id (priv->xcb);
- state = xkb_x11_state_new_from_device (keymap, priv->xcb, device_id);
-
- priv->keymap_layout_group =
- xkb_state_serialize_layout (state, XKB_STATE_LAYOUT_LOCKED);
-
- xkb_state_unref (state);
-}
-
-static gboolean
-meta_backend_x11_initable_init (GInitable *initable,
- GCancellable *cancellable,
- GError **error)
-{
- MetaBackendX11 *x11 = META_BACKEND_X11 (initable);
- MetaBackendX11Private *priv = meta_backend_x11_get_instance_private (x11);
- Display *xdisplay;
- const char *xdisplay_name;
-
- xdisplay_name = g_getenv ("DISPLAY");
- if (!xdisplay_name)
- {
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- "Unable to open display, DISPLAY not set");
- return FALSE;
- }
-
- xdisplay = XOpenDisplay (xdisplay_name);
- if (!xdisplay)
- {
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- "Unable to open display '%s'", xdisplay_name);
- return FALSE;
- }
-
- priv->xdisplay = xdisplay;
- priv->xcb = XGetXCBConnection (priv->xdisplay);
- meta_clutter_x11_set_display (xdisplay);
-
- init_xkb_state (x11);
-
- return initable_parent_iface->init (initable, cancellable, error);
-}
-
-static void
-initable_iface_init (GInitableIface *initable_iface)
-{
- initable_parent_iface = g_type_interface_peek_parent (initable_iface);
-
- initable_iface->init = meta_backend_x11_initable_init;
-}
-
-static void
-meta_backend_x11_dispose (GObject *object)
-{
- MetaBackend *backend = META_BACKEND (object);
- MetaBackendX11 *x11 = META_BACKEND_X11 (object);
- MetaBackendX11Private *priv = meta_backend_x11_get_instance_private (x11);
-
- if (priv->keymap_state_changed_id)
- {
- ClutterBackend *clutter_backend = meta_backend_get_clutter_backend (backend);
- ClutterSeat *seat = clutter_backend_get_default_seat (clutter_backend);
- ClutterKeymap *keymap;
-
- seat = clutter_backend_get_default_seat (clutter_backend);
- keymap = clutter_seat_get_keymap (seat);
- g_clear_signal_handler (&priv->keymap_state_changed_id, keymap);
- }
-
- if (priv->user_active_alarm != None)
- {
- XSyncDestroyAlarm (priv->xdisplay, priv->user_active_alarm);
- priv->user_active_alarm = None;
- }
-
- G_OBJECT_CLASS (meta_backend_x11_parent_class)->dispose (object);
-}
-
-static void
-meta_backend_x11_finalize (GObject *object)
-{
- MetaBackendX11 *x11 = META_BACKEND_X11 (object);
- MetaBackendX11Private *priv = meta_backend_x11_get_instance_private (x11);
-
- g_clear_pointer (&priv->keymap, xkb_keymap_unref);
-
- G_OBJECT_CLASS (meta_backend_x11_parent_class)->finalize (object);
-}
-
-static void
-meta_backend_x11_class_init (MetaBackendX11Class *klass)
-{
- MetaBackendClass *backend_class = META_BACKEND_CLASS (klass);
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- object_class->dispose = meta_backend_x11_dispose;
- object_class->finalize = meta_backend_x11_finalize;
- backend_class->create_clutter_backend = meta_backend_x11_create_clutter_backend;
- backend_class->create_default_seat = meta_backend_x11_create_default_seat;
- backend_class->post_init = meta_backend_x11_post_init;
- backend_class->grab_device = meta_backend_x11_grab_device;
- backend_class->ungrab_device = meta_backend_x11_ungrab_device;
- backend_class->finish_touch_sequence = meta_backend_x11_finish_touch_sequence;
- backend_class->get_current_logical_monitor = meta_backend_x11_get_current_logical_monitor;
- backend_class->get_keymap = meta_backend_x11_get_keymap;
- backend_class->get_keymap_layout_group = meta_backend_x11_get_keymap_layout_group;
-}
-
-static void
-meta_backend_x11_init (MetaBackendX11 *x11)
-{
- XInitThreads ();
-}
-
-Display *
-meta_backend_x11_get_xdisplay (MetaBackendX11 *x11)
-{
- MetaBackendX11Private *priv = meta_backend_x11_get_instance_private (x11);
-
- return priv->xdisplay;
-}
-
-Window
-meta_backend_x11_get_xwindow (MetaBackendX11 *x11)
-{
- ClutterActor *stage = meta_backend_get_stage (META_BACKEND (x11));
- return meta_x11_get_stage_window (CLUTTER_STAGE (stage));
-}
-
-void
-meta_backend_x11_reload_cursor (MetaBackendX11 *x11)
-{
- MetaBackend *backend = META_BACKEND (x11);
- MetaCursorRenderer *cursor_renderer =
- meta_backend_get_cursor_renderer (backend);
-
- meta_cursor_renderer_force_update (cursor_renderer);
-}
-
-void
-meta_backend_x11_sync_pointer (MetaBackendX11 *backend_x11)
-{
- MetaBackend *backend = META_BACKEND (backend_x11);
- ClutterBackend *clutter_backend = meta_backend_get_clutter_backend (backend);
- ClutterSeat *seat = clutter_backend_get_default_seat (clutter_backend);
- ClutterInputDevice *pointer = clutter_seat_get_pointer (seat);
- ClutterStage *stage = CLUTTER_STAGE (meta_backend_get_stage (backend));
- ClutterModifierType modifiers;
- ClutterEvent *event;
- graphene_point_t pos;
-
- event = clutter_event_new (CLUTTER_MOTION);
- clutter_seat_query_state (seat, pointer, NULL, &pos, &modifiers);
- clutter_event_set_flags (event, CLUTTER_EVENT_FLAG_SYNTHETIC);
- clutter_event_set_coords (event, pos.x, pos.y);
- clutter_event_set_device (event, pointer);
- clutter_event_set_state (event, modifiers);
- clutter_event_set_source_device (event, NULL);
- clutter_event_set_stage (event, stage);
-
- clutter_event_put (event);
- clutter_event_free (event);
-}
diff --git a/src/backends/x11/meta-backend-x11.h b/src/backends/x11/meta-backend-x11.h
deleted file mode 100644
index 2815015d1..000000000
--- a/src/backends/x11/meta-backend-x11.h
+++ /dev/null
@@ -1,63 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2014 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Written by:
- * Jasper St. Pierre <jstpierre@mecheye.net>
- */
-
-#ifndef META_BACKEND_X11_H
-#define META_BACKEND_X11_H
-
-#include <stdint.h>
-#include <X11/Xlib.h>
-
-#include "backends/meta-backend-private.h"
-#include "backends/x11/meta-clutter-backend-x11.h"
-
-#define META_TYPE_BACKEND_X11 (meta_backend_x11_get_type ())
-G_DECLARE_DERIVABLE_TYPE (MetaBackendX11, meta_backend_x11,
- META, BACKEND_X11, MetaBackend)
-
-struct _MetaBackendX11Class
-{
- MetaBackendClass parent_class;
-
- gboolean (* handle_host_xevent) (MetaBackendX11 *x11,
- XEvent *event);
- void (* translate_device_event) (MetaBackendX11 *x11,
- XIDeviceEvent *device_event);
- void (* translate_crossing_event) (MetaBackendX11 *x11,
- XIEnterEvent *enter_event);
-};
-
-Display * meta_backend_x11_get_xdisplay (MetaBackendX11 *backend);
-
-Window meta_backend_x11_get_xwindow (MetaBackendX11 *backend);
-
-void meta_backend_x11_handle_event (MetaBackendX11 *x11,
- XEvent *xevent);
-
-uint8_t meta_backend_x11_get_xkb_event_base (MetaBackendX11 *x11);
-
-void meta_backend_x11_reload_cursor (MetaBackendX11 *x11);
-
-void meta_backend_x11_sync_pointer (MetaBackendX11 *backend_x11);
-
-#endif /* META_BACKEND_X11_H */
diff --git a/src/backends/x11/meta-barrier-x11.c b/src/backends/x11/meta-barrier-x11.c
deleted file mode 100644
index 998aefb38..000000000
--- a/src/backends/x11/meta-barrier-x11.c
+++ /dev/null
@@ -1,212 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2014-2015 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Written by:
- * Jasper St. Pierre <jstpierre@mecheye.net>
- * Jonas Ådahl <jadahl@gmail.com>
- */
-
-/**
- * SECTION:barrier-x11
- * @Title: MetaBarrierImplX11
- * @Short_Description: Pointer barriers implementation for X11
- */
-
-#include "config.h"
-
-#include <glib-object.h>
-#include <X11/extensions/XInput2.h>
-#include <X11/extensions/Xfixes.h>
-
-#include "backends/x11/meta-barrier-x11.h"
-#include "core/display-private.h"
-#include "meta/barrier.h"
-#include "x11/meta-x11-display-private.h"
-
-struct _MetaBarrierImplX11
-{
- MetaBarrierImpl parent;
-
- MetaBarrier *barrier;
- PointerBarrier xbarrier;
-};
-
-G_DEFINE_TYPE (MetaBarrierImplX11,
- meta_barrier_impl_x11,
- META_TYPE_BARRIER_IMPL)
-
-static gboolean
-_meta_barrier_impl_x11_is_active (MetaBarrierImpl *impl)
-{
- MetaBarrierImplX11 *self = META_BARRIER_IMPL_X11 (impl);
-
- return self->xbarrier != 0;
-}
-
-static void
-_meta_barrier_impl_x11_release (MetaBarrierImpl *impl,
- MetaBarrierEvent *event)
-{
- MetaBarrierImplX11 *self = META_BARRIER_IMPL_X11 (impl);
- MetaDisplay *display = self->barrier->priv->display;
- Display *dpy = meta_x11_display_get_xdisplay (display->x11_display);
-
- if (META_X11_DISPLAY_HAS_XINPUT_23 (display->x11_display))
- {
- XIBarrierReleasePointer (dpy,
- META_VIRTUAL_CORE_POINTER_ID,
- self->xbarrier, event->event_id);
- }
-}
-
-static void
-_meta_barrier_impl_x11_destroy (MetaBarrierImpl *impl)
-{
- MetaBarrierImplX11 *self = META_BARRIER_IMPL_X11 (impl);
- MetaDisplay *display = self->barrier->priv->display;
- Display *dpy;
-
- if (display == NULL)
- return;
-
- dpy = meta_x11_display_get_xdisplay (display->x11_display);
-
- if (!meta_barrier_is_active (self->barrier))
- return;
-
- XFixesDestroyPointerBarrier (dpy, self->xbarrier);
- g_hash_table_remove (display->x11_display->xids, &self->xbarrier);
- self->xbarrier = 0;
-}
-
-MetaBarrierImpl *
-meta_barrier_impl_x11_new (MetaBarrier *barrier)
-{
- MetaBarrierImplX11 *self;
- MetaDisplay *display = barrier->priv->display;
- Display *dpy;
- Window root;
- unsigned int allowed_motion_dirs;
-
- if (display == NULL)
- {
- g_warning ("A display must be provided when constructing a barrier.");
- return NULL;
- }
-
- self = g_object_new (META_TYPE_BARRIER_IMPL_X11, NULL);
- self->barrier = barrier;
-
- dpy = meta_x11_display_get_xdisplay (display->x11_display);
- root = DefaultRootWindow (dpy);
-
- allowed_motion_dirs =
- meta_border_get_allows_directions (&barrier->priv->border);
- self->xbarrier = XFixesCreatePointerBarrier (dpy, root,
- barrier->priv->border.line.a.x,
- barrier->priv->border.line.a.y,
- barrier->priv->border.line.b.x,
- barrier->priv->border.line.b.y,
- allowed_motion_dirs,
- 0, NULL);
-
- g_hash_table_insert (display->x11_display->xids, &self->xbarrier, barrier);
-
- return META_BARRIER_IMPL (self);
-}
-
-static void
-meta_barrier_fire_xevent (MetaBarrier *barrier,
- XIBarrierEvent *xevent)
-{
- MetaBarrierEvent *event = g_new0 (MetaBarrierEvent, 1);
-
- event->ref_count = 1;
- event->event_id = xevent->eventid;
- event->time = xevent->time;
- event->dt = xevent->dtime;
-
- event->x = xevent->root_x;
- event->y = xevent->root_y;
- event->dx = xevent->dx;
- event->dy = xevent->dy;
-
- event->released = (xevent->flags & XIBarrierPointerReleased) != 0;
- event->grabbed = (xevent->flags & XIBarrierDeviceIsGrabbed) != 0;
-
- switch (xevent->evtype)
- {
- case XI_BarrierHit:
- _meta_barrier_emit_hit_signal (barrier, event);
- break;
- case XI_BarrierLeave:
- _meta_barrier_emit_left_signal (barrier, event);
- break;
- default:
- g_assert_not_reached ();
- }
-
- meta_barrier_event_unref (event);
-}
-
-gboolean
-meta_x11_display_process_barrier_xevent (MetaX11Display *x11_display,
- XIEvent *event)
-{
- MetaBarrier *barrier;
- XIBarrierEvent *xev;
-
- if (event == NULL)
- return FALSE;
-
- switch (event->evtype)
- {
- case XI_BarrierHit:
- case XI_BarrierLeave:
- break;
- default:
- return FALSE;
- }
-
- xev = (XIBarrierEvent *) event;
- barrier = g_hash_table_lookup (x11_display->xids, &xev->barrier);
- if (barrier != NULL)
- {
- meta_barrier_fire_xevent (barrier, xev);
- return TRUE;
- }
-
- return FALSE;
-}
-
-static void
-meta_barrier_impl_x11_class_init (MetaBarrierImplX11Class *klass)
-{
- MetaBarrierImplClass *impl_class = META_BARRIER_IMPL_CLASS (klass);
-
- impl_class->is_active = _meta_barrier_impl_x11_is_active;
- impl_class->release = _meta_barrier_impl_x11_release;
- impl_class->destroy = _meta_barrier_impl_x11_destroy;
-}
-
-static void
-meta_barrier_impl_x11_init (MetaBarrierImplX11 *self)
-{
-}
diff --git a/src/backends/x11/meta-barrier-x11.h b/src/backends/x11/meta-barrier-x11.h
deleted file mode 100644
index 3562d106f..000000000
--- a/src/backends/x11/meta-barrier-x11.h
+++ /dev/null
@@ -1,42 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2015 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Written by:
- * Jonas Ådahl <jadahl@gmail.com>
- */
-
-#ifndef META_BARRIER_X11_H
-#define META_BARRIER_X11_H
-
-#include "backends/meta-barrier-private.h"
-
-G_BEGIN_DECLS
-
-#define META_TYPE_BARRIER_IMPL_X11 (meta_barrier_impl_x11_get_type ())
-G_DECLARE_FINAL_TYPE (MetaBarrierImplX11,
- meta_barrier_impl_x11,
- META, BARRIER_IMPL_X11,
- MetaBarrierImpl)
-
-MetaBarrierImpl *meta_barrier_impl_x11_new (MetaBarrier *barrier);
-
-G_END_DECLS
-
-#endif /* META_BARRIER_X11_H1 */
diff --git a/src/backends/x11/meta-clutter-backend-x11.c b/src/backends/x11/meta-clutter-backend-x11.c
deleted file mode 100644
index d94987879..000000000
--- a/src/backends/x11/meta-clutter-backend-x11.c
+++ /dev/null
@@ -1,745 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2016 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Written by:
- * Jonas Ådahl <jadahl@gmail.com>
- */
-
-#include "config.h"
-
-#include <glib-object.h>
-
-#include "backends/meta-backend-private.h"
-#include "backends/meta-renderer.h"
-#include "backends/x11/meta-clutter-backend-x11.h"
-#include "backends/x11/meta-keymap-x11.h"
-#include "backends/x11/meta-seat-x11.h"
-#include "backends/x11/meta-xkb-a11y-x11.h"
-#include "backends/x11/nested/meta-stage-x11-nested.h"
-#include "clutter/clutter-mutter.h"
-#include "clutter/clutter.h"
-#include "cogl/cogl-xlib.h"
-#include "core/bell.h"
-#include "meta/meta-backend.h"
-
-typedef struct _MetaX11EventFilter MetaX11EventFilter;
-
-struct _MetaX11EventFilter
-{
- MetaX11FilterFunc func;
- gpointer data;
-};
-
-G_DEFINE_TYPE (MetaClutterBackendX11, meta_clutter_backend_x11,
- CLUTTER_TYPE_BACKEND)
-
-
-/* atoms; remember to add the code that assigns the atom value to
- * the member of the MetaClutterBackendX11 structure if you add an
- * atom name here. do not change the order!
- */
-static const gchar *atom_names[] = {
- "_NET_WM_PID",
- "_NET_WM_PING",
- "_NET_WM_STATE",
- "_NET_WM_USER_TIME",
- "WM_PROTOCOLS",
- "WM_DELETE_WINDOW",
- "_XEMBED",
- "_XEMBED_INFO",
- "_NET_WM_NAME",
- "UTF8_STRING",
-};
-
-#define N_ATOM_NAMES G_N_ELEMENTS (atom_names)
-
-/* various flags corresponding to pre init setup calls */
-static gboolean clutter_enable_xinput = TRUE;
-static gboolean clutter_enable_stereo = FALSE;
-static Display *_foreign_dpy = NULL;
-
-/* options */
-static gchar *clutter_display_name = NULL;
-static gint clutter_screen = -1;
-static gboolean clutter_synchronise = FALSE;
-
-/* X error trap */
-static int TrappedErrorCode = 0;
-static int (* old_error_handler) (Display *, XErrorEvent *);
-
-static MetaX11FilterReturn
-cogl_xlib_filter (XEvent *xevent,
- ClutterEvent *event,
- gpointer data)
-{
- ClutterBackend *backend = data;
- MetaX11FilterReturn retval;
- CoglFilterReturn ret;
-
- ret = cogl_xlib_renderer_handle_event (backend->cogl_renderer, xevent);
- switch (ret)
- {
- case COGL_FILTER_REMOVE:
- retval = META_X11_FILTER_REMOVE;
- break;
-
- case COGL_FILTER_CONTINUE:
- default:
- retval = META_X11_FILTER_CONTINUE;
- break;
- }
-
- return retval;
-}
-
-static gboolean
-meta_clutter_backend_x11_pre_parse (ClutterBackend *backend,
- GError **error)
-{
- const gchar *env_string;
-
- /* we don't fail here if DISPLAY is not set, as the user
- * might pass the --display command line switch
- */
- env_string = g_getenv ("DISPLAY");
- if (env_string)
- {
- clutter_display_name = g_strdup (env_string);
- env_string = NULL;
- }
-
- env_string = g_getenv ("CLUTTER_DISABLE_XINPUT");
- if (env_string)
- {
- clutter_enable_xinput = FALSE;
- env_string = NULL;
- }
-
- return TRUE;
-}
-
-static gboolean
-meta_clutter_backend_x11_post_parse (ClutterBackend *backend,
- GError **error)
-{
- MetaClutterBackendX11 *backend_x11 = META_CLUTTER_BACKEND_X11 (backend);
- Atom atoms[N_ATOM_NAMES];
-
- if (_foreign_dpy)
- backend_x11->xdisplay = _foreign_dpy;
-
- /* Only open connection if not already set by prior call to
- * clutter_x11_set_display()
- */
- if (backend_x11->xdisplay == NULL)
- {
- if (clutter_display_name != NULL &&
- *clutter_display_name != '\0')
- {
- g_debug ("XOpenDisplay on '%s'", clutter_display_name);
-
- backend_x11->xdisplay = XOpenDisplay (clutter_display_name);
- if (backend_x11->xdisplay == NULL)
- {
- g_set_error (error, CLUTTER_INIT_ERROR,
- CLUTTER_INIT_ERROR_BACKEND,
- "Unable to open display '%s'",
- clutter_display_name);
- return FALSE;
- }
- }
- else
- {
- g_set_error_literal (error, CLUTTER_INIT_ERROR,
- CLUTTER_INIT_ERROR_BACKEND,
- "Unable to open display. You have to set the "
- "DISPLAY environment variable, or use the "
- "--display command line argument");
- return FALSE;
- }
- }
-
- g_assert (backend_x11->xdisplay != NULL);
-
- g_debug ("Getting the X screen");
-
- /* add event filter for Cogl events */
- meta_clutter_x11_add_filter (cogl_xlib_filter, backend);
-
- if (clutter_screen == -1)
- backend_x11->xscreen = DefaultScreenOfDisplay (backend_x11->xdisplay);
- else
- backend_x11->xscreen = ScreenOfDisplay (backend_x11->xdisplay,
- clutter_screen);
-
- backend_x11->xscreen_num = XScreenNumberOfScreen (backend_x11->xscreen);
- backend_x11->xscreen_width = WidthOfScreen (backend_x11->xscreen);
- backend_x11->xscreen_height = HeightOfScreen (backend_x11->xscreen);
-
- backend_x11->xwin_root = RootWindow (backend_x11->xdisplay,
- backend_x11->xscreen_num);
-
- backend_x11->display_name = g_strdup (clutter_display_name);
-
- if (clutter_synchronise)
- XSynchronize (backend_x11->xdisplay, True);
-
- XInternAtoms (backend_x11->xdisplay,
- (char **) atom_names, N_ATOM_NAMES,
- False, atoms);
-
- backend_x11->atom_NET_WM_PID = atoms[0];
- backend_x11->atom_NET_WM_PING = atoms[1];
- backend_x11->atom_NET_WM_STATE = atoms[2];
- backend_x11->atom_NET_WM_USER_TIME = atoms[3];
- backend_x11->atom_WM_PROTOCOLS = atoms[4];
- backend_x11->atom_WM_DELETE_WINDOW = atoms[5];
- backend_x11->atom_XEMBED = atoms[6];
- backend_x11->atom_XEMBED_INFO = atoms[7];
- backend_x11->atom_NET_WM_NAME = atoms[8];
- backend_x11->atom_UTF8_STRING = atoms[9];
-
- g_free (clutter_display_name);
-
- g_debug ("X Display '%s'[%p] opened (screen:%d, root:%u, dpi:%f)",
- backend_x11->display_name,
- backend_x11->xdisplay,
- backend_x11->xscreen_num,
- (unsigned int) backend_x11->xwin_root,
- clutter_backend_get_resolution (backend));
-
- return TRUE;
-}
-
-static const GOptionEntry entries[] =
-{
- {
- "display", 0,
- G_OPTION_FLAG_IN_MAIN,
- G_OPTION_ARG_STRING, &clutter_display_name,
- N_("X display to use"), "DISPLAY"
- },
- {
- "screen", 0,
- G_OPTION_FLAG_IN_MAIN,
- G_OPTION_ARG_INT, &clutter_screen,
- N_("X screen to use"), "SCREEN"
- },
- { "synch", 0,
- 0,
- G_OPTION_ARG_NONE, &clutter_synchronise,
- N_("Make X calls synchronous"), NULL
- },
- {
- "disable-xinput", 0,
- G_OPTION_FLAG_REVERSE,
- G_OPTION_ARG_NONE, &clutter_enable_xinput,
- N_("Disable XInput support"), NULL
- },
- { NULL }
-};
-
-static void
-meta_clutter_backend_x11_add_options (ClutterBackend *backend,
- GOptionGroup *group)
-{
- g_option_group_add_entries (group, entries);
-}
-
-static void
-meta_clutter_backend_x11_finalize (GObject *gobject)
-{
- MetaClutterBackendX11 *backend_x11 = META_CLUTTER_BACKEND_X11 (gobject);
-
- g_free (backend_x11->display_name);
-
- meta_clutter_x11_remove_filter (cogl_xlib_filter, gobject);
-
- XCloseDisplay (backend_x11->xdisplay);
-
- G_OBJECT_CLASS (meta_clutter_backend_x11_parent_class)->finalize (gobject);
-}
-
-static ClutterFeatureFlags
-meta_clutter_backend_x11_get_features (ClutterBackend *backend)
-{
- ClutterFeatureFlags flags = CLUTTER_FEATURE_STAGE_CURSOR;
-
- flags |=
- CLUTTER_BACKEND_CLASS (meta_clutter_backend_x11_parent_class)->get_features (backend);
-
- return flags;
-}
-
-static void
-update_last_event_time (MetaClutterBackendX11 *backend_x11,
- XEvent *xevent)
-{
- Time current_time = CurrentTime;
- Time last_time = backend_x11->last_event_time;
-
- switch (xevent->type)
- {
- case KeyPress:
- case KeyRelease:
- current_time = xevent->xkey.time;
- break;
-
- case ButtonPress:
- case ButtonRelease:
- current_time = xevent->xbutton.time;
- break;
-
- case MotionNotify:
- current_time = xevent->xmotion.time;
- break;
-
- case EnterNotify:
- case LeaveNotify:
- current_time = xevent->xcrossing.time;
- break;
-
- case PropertyNotify:
- current_time = xevent->xproperty.time;
- break;
-
- default:
- break;
- }
-
- /* only change the current event time if it's after the previous event
- * time, or if it is at least 30 seconds earlier - in case the system
- * clock was changed
- */
- if ((current_time != CurrentTime) &&
- (current_time > last_time || (last_time - current_time > (30 * 1000))))
- backend_x11->last_event_time = current_time;
-}
-
-static gboolean
-check_onscreen_template (CoglRenderer *renderer,
- CoglOnscreenTemplate *onscreen_template,
- gboolean enable_stereo,
- GError **error)
-{
- GError *internal_error = NULL;
-
- cogl_onscreen_template_set_stereo_enabled (onscreen_template,
- clutter_enable_stereo);
-
- /* cogl_renderer_check_onscreen_template() is actually just a
- * shorthand for creating a CoglDisplay, and calling
- * cogl_display_setup() on it, then throwing the display away. If we
- * could just return that display, then it would be more efficient
- * not to use cogl_renderer_check_onscreen_template(). However, the
- * backend API requires that we return an CoglDisplay that has not
- * yet been setup, so one way or the other we'll have to discard the
- * first display and make a new fresh one.
- */
- if (cogl_renderer_check_onscreen_template (renderer, onscreen_template, &internal_error))
- {
- clutter_enable_stereo = enable_stereo;
-
- return TRUE;
- }
- else
- {
- g_set_error_literal (error, CLUTTER_INIT_ERROR,
- CLUTTER_INIT_ERROR_BACKEND,
- internal_error != NULL
- ? internal_error->message
- : "Creation of a CoglDisplay failed");
-
- g_clear_error (&internal_error);
-
- return FALSE;
- }
-}
-
-static CoglDisplay *
-meta_clutter_backend_x11_get_display (ClutterBackend *backend,
- CoglRenderer *renderer,
- CoglSwapChain *swap_chain,
- GError **error)
-{
- CoglOnscreenTemplate *onscreen_template;
- CoglDisplay *display = NULL;
- gboolean res = FALSE;
-
- onscreen_template = cogl_onscreen_template_new (swap_chain);
-
- /* It's possible that the current renderer doesn't support transparency
- * or doesn't support stereo, so we try the different combinations.
- */
- if (clutter_enable_stereo)
- res = check_onscreen_template (renderer, onscreen_template,
- TRUE, error);
-
- if (!res)
- res = check_onscreen_template (renderer, onscreen_template,
- FALSE, error);
-
- if (res)
- display = cogl_display_new (renderer, onscreen_template);
-
- cogl_object_unref (onscreen_template);
-
- return display;
-}
-
-static CoglRenderer *
-meta_clutter_backend_x11_get_renderer (ClutterBackend *clutter_backend,
- GError **error)
-{
- MetaBackend *backend = meta_get_backend ();
- MetaRenderer *renderer = meta_backend_get_renderer (backend);
-
- return meta_renderer_create_cogl_renderer (renderer);
-}
-
-static ClutterStageWindow *
-meta_clutter_backend_x11_create_stage (ClutterBackend *backend,
- ClutterStage *wrapper,
- GError **error)
-{
- ClutterStageWindow *stage;
- GType stage_type;
-
- if (meta_is_wayland_compositor ())
- stage_type = META_TYPE_STAGE_X11_NESTED;
- else
- stage_type = META_TYPE_STAGE_X11;
-
- stage = g_object_new (stage_type,
- "backend", backend,
- "wrapper", wrapper,
- NULL);
- return stage;
-}
-
-static gboolean
-meta_clutter_backend_x11_process_event_filters (MetaClutterBackendX11 *backend_x11,
- gpointer native,
- ClutterEvent *event)
-{
- XEvent *xevent = native;
-
- /* X11 filter functions have a higher priority */
- if (backend_x11->event_filters != NULL)
- {
- GSList *node = backend_x11->event_filters;
-
- while (node != NULL)
- {
- MetaX11EventFilter *filter = node->data;
-
- switch (filter->func (xevent, event, filter->data))
- {
- case META_X11_FILTER_CONTINUE:
- break;
-
- case META_X11_FILTER_TRANSLATE:
- return TRUE;
-
- case META_X11_FILTER_REMOVE:
- return FALSE;
-
- default:
- break;
- }
-
- node = node->next;
- }
- }
-
- return FALSE;
-}
-
-static gboolean
-meta_clutter_backend_x11_translate_event (ClutterBackend *clutter_backend,
- gpointer native,
- ClutterEvent *event)
-{
- MetaClutterBackendX11 *backend_x11 =
- META_CLUTTER_BACKEND_X11 (clutter_backend);
- MetaBackend *backend = meta_get_backend ();
- MetaStageX11 *stage_x11;
- ClutterSeat *seat;
-
- if (meta_clutter_backend_x11_process_event_filters (backend_x11,
- native,
- event))
- return TRUE;
-
- /* we update the event time only for events that can
- * actually reach Clutter's event queue
- */
- update_last_event_time (backend_x11, native);
-
- stage_x11 =
- META_STAGE_X11 (clutter_backend_get_stage_window (clutter_backend));
- if (meta_stage_x11_translate_event (stage_x11, native, event))
- return TRUE;
-
- seat = meta_backend_get_default_seat (backend);
- if (meta_seat_x11_translate_event (META_SEAT_X11 (seat), native, event))
- return TRUE;
-
- return FALSE;
-}
-
-static ClutterSeat *
-meta_clutter_backend_x11_get_default_seat (ClutterBackend *clutter_backend)
-{
- MetaBackend *backend = meta_get_backend ();
-
- return meta_backend_get_default_seat (backend);
-}
-
-static gboolean
-meta_clutter_backend_x11_is_display_server (ClutterBackend *backend)
-{
- return meta_is_wayland_compositor ();
-}
-
-static void
-meta_clutter_backend_x11_init (MetaClutterBackendX11 *clutter_backend_x11)
-{
- clutter_backend_x11->last_event_time = CurrentTime;
-}
-
-static void
-meta_clutter_backend_x11_class_init (MetaClutterBackendX11Class *klass)
-{
- GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
- ClutterBackendClass *clutter_backend_class = CLUTTER_BACKEND_CLASS (klass);
-
- gobject_class->finalize = meta_clutter_backend_x11_finalize;
-
- clutter_backend_class->pre_parse = meta_clutter_backend_x11_pre_parse;
- clutter_backend_class->post_parse = meta_clutter_backend_x11_post_parse;
- clutter_backend_class->add_options = meta_clutter_backend_x11_add_options;
- clutter_backend_class->get_features = meta_clutter_backend_x11_get_features;
-
- clutter_backend_class->get_display = meta_clutter_backend_x11_get_display;
- clutter_backend_class->get_renderer = meta_clutter_backend_x11_get_renderer;
- clutter_backend_class->create_stage = meta_clutter_backend_x11_create_stage;
- clutter_backend_class->translate_event = meta_clutter_backend_x11_translate_event;
- clutter_backend_class->get_default_seat = meta_clutter_backend_x11_get_default_seat;
- clutter_backend_class->is_display_server = meta_clutter_backend_x11_is_display_server;
-}
-
-static int
-error_handler (Display *xdisplay,
- XErrorEvent *error)
-{
- TrappedErrorCode = error->error_code;
- return 0;
-}
-
-void
-meta_clutter_x11_trap_x_errors (void)
-{
- TrappedErrorCode = 0;
- old_error_handler = XSetErrorHandler (error_handler);
-}
-
-gint
-meta_clutter_x11_untrap_x_errors (void)
-{
- XSetErrorHandler (old_error_handler);
-
- return TrappedErrorCode;
-}
-
-Display *
-meta_clutter_x11_get_default_display (void)
-{
- ClutterBackend *backend = clutter_get_default_backend ();
-
- if (backend == NULL)
- {
- g_critical ("The Clutter backend has not been initialised");
- return NULL;
- }
-
- if (!META_IS_CLUTTER_BACKEND_X11 (backend))
- {
- g_critical ("The Clutter backend is not a X11 backend");
- return NULL;
- }
-
- return META_CLUTTER_BACKEND_X11 (backend)->xdisplay;
-}
-
-void
-meta_clutter_x11_set_display (Display *xdisplay)
-{
- if (_clutter_context_is_initialized ())
- {
- g_warning ("%s() can only be used before calling clutter_init()",
- G_STRFUNC);
- return;
- }
-
- _foreign_dpy= xdisplay;
-}
-
-int
-meta_clutter_x11_get_default_screen (void)
-{
- ClutterBackend *backend = clutter_get_default_backend ();
-
- if (backend == NULL)
- {
- g_critical ("The Clutter backend has not been initialised");
- return 0;
- }
-
- if (!META_IS_CLUTTER_BACKEND_X11 (backend))
- {
- g_critical ("The Clutter backend is not a X11 backend");
- return 0;
- }
-
- return META_CLUTTER_BACKEND_X11 (backend)->xscreen_num;
-}
-
-Window
-meta_clutter_x11_get_root_window (void)
-{
- ClutterBackend *backend = clutter_get_default_backend ();
-
- if (backend == NULL)
- {
- g_critical ("The Clutter backend has not been initialised");
- return None;
- }
-
- if (!META_IS_CLUTTER_BACKEND_X11 (backend))
- {
- g_critical ("The Clutter backend is not a X11 backend");
- return None;
- }
-
- return META_CLUTTER_BACKEND_X11 (backend)->xwin_root;
-}
-
-void
-meta_clutter_x11_add_filter (MetaX11FilterFunc func,
- gpointer data)
-{
- MetaX11EventFilter *filter;
- ClutterBackend *backend = clutter_get_default_backend ();
- MetaClutterBackendX11 *backend_x11;
-
- g_return_if_fail (func != NULL);
-
- if (backend == NULL)
- {
- g_critical ("The Clutter backend has not been initialised");
- return;
- }
-
- if (!META_IS_CLUTTER_BACKEND_X11 (backend))
- {
- g_critical ("The Clutter backend is not a X11 backend");
- return;
- }
-
- backend_x11 = META_CLUTTER_BACKEND_X11 (backend);
-
- filter = g_new0 (MetaX11EventFilter, 1);
- filter->func = func;
- filter->data = data;
-
- backend_x11->event_filters =
- g_slist_append (backend_x11->event_filters, filter);
-
- return;
-}
-
-void
-meta_clutter_x11_remove_filter (MetaX11FilterFunc func,
- gpointer data)
-{
- GSList *tmp_list, *this;
- MetaX11EventFilter *filter;
- ClutterBackend *backend = clutter_get_default_backend ();
- MetaClutterBackendX11 *backend_x11;
-
- g_return_if_fail (func != NULL);
-
- if (backend == NULL)
- {
- g_critical ("The Clutter backend has not been initialised");
- return;
- }
-
- if (!META_IS_CLUTTER_BACKEND_X11 (backend))
- {
- g_critical ("The Clutter backend is not a X11 backend");
- return;
- }
-
- backend_x11 = META_CLUTTER_BACKEND_X11 (backend);
-
- tmp_list = backend_x11->event_filters;
-
- while (tmp_list)
- {
- filter = tmp_list->data;
- this = tmp_list;
- tmp_list = tmp_list->next;
-
- if (filter->func == func && filter->data == data)
- {
- backend_x11->event_filters =
- g_slist_remove_link (backend_x11->event_filters, this);
-
- g_slist_free_1 (this);
- g_free (filter);
-
- return;
- }
- }
-}
-
-void
-meta_clutter_x11_set_use_stereo_stage (gboolean use_stereo)
-{
- if (_clutter_context_is_initialized ())
- {
- g_warning ("%s() can only be used before calling clutter_init()",
- G_STRFUNC);
- return;
- }
-
- g_debug ("STEREO stages are %s",
- use_stereo ? "enabled" : "disabled");
-
- clutter_enable_stereo = use_stereo;
-}
-
-gboolean
-meta_clutter_x11_get_use_stereo_stage (void)
-{
- return clutter_enable_stereo;
-}
diff --git a/src/backends/x11/meta-clutter-backend-x11.h b/src/backends/x11/meta-clutter-backend-x11.h
deleted file mode 100644
index d91a2f3af..000000000
--- a/src/backends/x11/meta-clutter-backend-x11.h
+++ /dev/null
@@ -1,96 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2016 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Written by:
- * Jonas Ådahl <jadahl@gmail.com>
- */
-
-#ifndef META_CLUTTER_BACKEND_X11_H
-#define META_CLUTTER_BACKEND_X11_H
-
-#include <glib-object.h>
-
-#include "clutter/clutter-mutter.h"
-
-struct _MetaClutterBackendX11
-{
- ClutterBackend parent_instance;
-
- Display *xdisplay;
- char *display_name;
-
- Screen *xscreen;
- int xscreen_num;
- int xscreen_width;
- int xscreen_height;
-
- Window xwin_root;
-
- /* event source */
- GSList *event_filters;
-
- /* props */
- Atom atom_NET_WM_PID;
- Atom atom_NET_WM_PING;
- Atom atom_NET_WM_STATE;
- Atom atom_NET_WM_USER_TIME;
- Atom atom_WM_PROTOCOLS;
- Atom atom_WM_DELETE_WINDOW;
- Atom atom_XEMBED;
- Atom atom_XEMBED_INFO;
- Atom atom_NET_WM_NAME;
- Atom atom_UTF8_STRING;
-
- Time last_event_time;
-};
-
-#define META_TYPE_CLUTTER_BACKEND_X11 (meta_clutter_backend_x11_get_type ())
-G_DECLARE_FINAL_TYPE (MetaClutterBackendX11, meta_clutter_backend_x11,
- META, CLUTTER_BACKEND_X11,
- ClutterBackend)
-
-typedef enum
-{
- META_X11_FILTER_CONTINUE,
- META_X11_FILTER_TRANSLATE,
- META_X11_FILTER_REMOVE
-} MetaX11FilterReturn;
-
-typedef MetaX11FilterReturn (*MetaX11FilterFunc) (XEvent *xev,
- ClutterEvent *cev,
- gpointer data);
-
-void meta_clutter_x11_trap_x_errors (void);
-gint meta_clutter_x11_untrap_x_errors (void);
-
-Display *meta_clutter_x11_get_default_display (void);
-int meta_clutter_x11_get_default_screen (void);
-Window meta_clutter_x11_get_root_window (void);
-void meta_clutter_x11_set_display (Display * xdpy);
-
-void meta_clutter_x11_add_filter (MetaX11FilterFunc func,
- gpointer data);
-void meta_clutter_x11_remove_filter (MetaX11FilterFunc func,
- gpointer data);
-
-void meta_clutter_x11_set_use_stereo_stage (gboolean use_stereo);
-gboolean meta_clutter_x11_get_use_stereo_stage (void);
-
-#endif /* META_CLUTTER_BACKEND_X11_H */
diff --git a/src/backends/x11/meta-crtc-xrandr.c b/src/backends/x11/meta-crtc-xrandr.c
deleted file mode 100644
index e06448b6e..000000000
--- a/src/backends/x11/meta-crtc-xrandr.c
+++ /dev/null
@@ -1,308 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2001, 2002 Havoc Pennington
- * Copyright (C) 2001, 2002 Havoc Pennington
- * Copyright (C) 2002, 2003 Red Hat Inc.
- * Some ICCCM manager selection code derived from fvwm2,
- * Copyright (C) 2001 Dominik Vogt, Matthias Clasen, and fvwm2 team
- * Copyright (C) 2003 Rob Adams
- * Copyright (C) 2004-2006 Elijah Newren
- * Copyright (C) 2002, 2003 Red Hat Inc.
- * Some ICCCM manager selection code derived from fvwm2,
- * Copyright (C) 2001 Dominik Vogt, Matthias Clasen, and fvwm2 team
- * Copyright (C) 2003 Rob Adams
- * Copyright (C) 2004-2006 Elijah Newren
- * Copyright (C) 2013-2017 Red Hat Inc.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-
-#include "config.h"
-
-#include "backends/x11/meta-crtc-xrandr.h"
-
-#include <X11/Xlib-xcb.h>
-#include <stdlib.h>
-#include <xcb/randr.h>
-
-#include "backends/meta-backend-private.h"
-#include "backends/meta-crtc.h"
-#include "backends/meta-output.h"
-#include "backends/x11/meta-crtc-xrandr.h"
-#include "backends/x11/meta-gpu-xrandr.h"
-#include "backends/x11/meta-monitor-manager-xrandr.h"
-
-struct _MetaCrtcXrandr
-{
- MetaCrtc parent;
-
- MetaRectangle rect;
- MetaMonitorTransform transform;
- MetaCrtcMode *current_mode;
-};
-
-G_DEFINE_TYPE (MetaCrtcXrandr, meta_crtc_xrandr, META_TYPE_CRTC)
-
-gboolean
-meta_crtc_xrandr_set_config (MetaCrtcXrandr *crtc_xrandr,
- xcb_randr_crtc_t xrandr_crtc,
- xcb_timestamp_t timestamp,
- int x,
- int y,
- xcb_randr_mode_t mode,
- xcb_randr_rotation_t rotation,
- xcb_randr_output_t *outputs,
- int n_outputs,
- xcb_timestamp_t *out_timestamp)
-{
- MetaGpu *gpu = meta_crtc_get_gpu (META_CRTC (crtc_xrandr));
- MetaGpuXrandr *gpu_xrandr = META_GPU_XRANDR (gpu);
- MetaBackend *backend = meta_gpu_get_backend (gpu);
- MetaMonitorManager *monitor_manager =
- meta_backend_get_monitor_manager (backend);
- MetaMonitorManagerXrandr *monitor_manager_xrandr =
- META_MONITOR_MANAGER_XRANDR (monitor_manager);
- Display *xdisplay;
- XRRScreenResources *resources;
- xcb_connection_t *xcb_conn;
- xcb_timestamp_t config_timestamp;
- xcb_randr_set_crtc_config_cookie_t cookie;
- xcb_randr_set_crtc_config_reply_t *reply;
- xcb_generic_error_t *xcb_error = NULL;
-
- xdisplay = meta_monitor_manager_xrandr_get_xdisplay (monitor_manager_xrandr);
- xcb_conn = XGetXCBConnection (xdisplay);
- resources = meta_gpu_xrandr_get_resources (gpu_xrandr);
- config_timestamp = resources->configTimestamp;
- cookie = xcb_randr_set_crtc_config (xcb_conn,
- xrandr_crtc,
- timestamp,
- config_timestamp,
- x, y,
- mode,
- rotation,
- n_outputs,
- outputs);
- reply = xcb_randr_set_crtc_config_reply (xcb_conn,
- cookie,
- &xcb_error);
- if (xcb_error || !reply)
- {
- free (xcb_error);
- free (reply);
- return FALSE;
- }
-
- *out_timestamp = reply->timestamp;
- free (reply);
-
- return TRUE;
-}
-
-static MetaMonitorTransform
-meta_monitor_transform_from_xrandr (Rotation rotation)
-{
- static const MetaMonitorTransform y_reflected_map[4] = {
- META_MONITOR_TRANSFORM_FLIPPED_180,
- META_MONITOR_TRANSFORM_FLIPPED_90,
- META_MONITOR_TRANSFORM_FLIPPED,
- META_MONITOR_TRANSFORM_FLIPPED_270
- };
- MetaMonitorTransform ret;
-
- switch (rotation & 0x7F)
- {
- default:
- case RR_Rotate_0:
- ret = META_MONITOR_TRANSFORM_NORMAL;
- break;
- case RR_Rotate_90:
- ret = META_MONITOR_TRANSFORM_90;
- break;
- case RR_Rotate_180:
- ret = META_MONITOR_TRANSFORM_180;
- break;
- case RR_Rotate_270:
- ret = META_MONITOR_TRANSFORM_270;
- break;
- }
-
- if (rotation & RR_Reflect_X)
- return ret + 4;
- else if (rotation & RR_Reflect_Y)
- return y_reflected_map[ret];
- else
- return ret;
-}
-
-#define ALL_ROTATIONS (RR_Rotate_0 | RR_Rotate_90 | RR_Rotate_180 | RR_Rotate_270)
-
-static MetaMonitorTransform
-meta_monitor_transform_from_xrandr_all (Rotation rotation)
-{
- unsigned ret;
-
- /* Handle the common cases first (none or all) */
- if (rotation == 0 || rotation == RR_Rotate_0)
- return (1 << META_MONITOR_TRANSFORM_NORMAL);
-
- /* All rotations and one reflection -> all of them by composition */
- if ((rotation & ALL_ROTATIONS) &&
- ((rotation & RR_Reflect_X) || (rotation & RR_Reflect_Y)))
- return META_MONITOR_ALL_TRANSFORMS;
-
- ret = 1 << META_MONITOR_TRANSFORM_NORMAL;
- if (rotation & RR_Rotate_90)
- ret |= 1 << META_MONITOR_TRANSFORM_90;
- if (rotation & RR_Rotate_180)
- ret |= 1 << META_MONITOR_TRANSFORM_180;
- if (rotation & RR_Rotate_270)
- ret |= 1 << META_MONITOR_TRANSFORM_270;
- if (rotation & (RR_Rotate_0 | RR_Reflect_X))
- ret |= 1 << META_MONITOR_TRANSFORM_FLIPPED;
- if (rotation & (RR_Rotate_90 | RR_Reflect_X))
- ret |= 1 << META_MONITOR_TRANSFORM_FLIPPED_90;
- if (rotation & (RR_Rotate_180 | RR_Reflect_X))
- ret |= 1 << META_MONITOR_TRANSFORM_FLIPPED_180;
- if (rotation & (RR_Rotate_270 | RR_Reflect_X))
- ret |= 1 << META_MONITOR_TRANSFORM_FLIPPED_270;
-
- return ret;
-}
-
-gboolean
-meta_crtc_xrandr_is_assignment_changed (MetaCrtcXrandr *crtc_xrandr,
- MetaCrtcAssignment *crtc_assignment)
-{
- unsigned int i;
-
- if (crtc_xrandr->current_mode != crtc_assignment->mode)
- return TRUE;
-
- if (crtc_xrandr->rect.x != (int) roundf (crtc_assignment->layout.origin.x))
- return TRUE;
-
- if (crtc_xrandr->rect.y != (int) roundf (crtc_assignment->layout.origin.y))
- return TRUE;
-
- if (crtc_xrandr->transform != crtc_assignment->transform)
- return TRUE;
-
- for (i = 0; i < crtc_assignment->outputs->len; i++)
- {
- MetaOutput *output = ((MetaOutput**) crtc_assignment->outputs->pdata)[i];
- MetaCrtc *assigned_crtc;
-
- assigned_crtc = meta_output_get_assigned_crtc (output);
- if (assigned_crtc != META_CRTC (crtc_xrandr))
- return TRUE;
- }
-
- return FALSE;
-}
-
-MetaCrtcMode *
-meta_crtc_xrandr_get_current_mode (MetaCrtcXrandr *crtc_xrandr)
-{
- return crtc_xrandr->current_mode;
-}
-
-MetaCrtcXrandr *
-meta_crtc_xrandr_new (MetaGpuXrandr *gpu_xrandr,
- XRRCrtcInfo *xrandr_crtc,
- RRCrtc crtc_id,
- XRRScreenResources *resources)
-{
- MetaGpu *gpu = META_GPU (gpu_xrandr);
- MetaBackend *backend = meta_gpu_get_backend (gpu);
- MetaMonitorManager *monitor_manager =
- meta_backend_get_monitor_manager (backend);
- MetaMonitorManagerXrandr *monitor_manager_xrandr =
- META_MONITOR_MANAGER_XRANDR (monitor_manager);
- Display *xdisplay =
- meta_monitor_manager_xrandr_get_xdisplay (monitor_manager_xrandr);
- MetaMonitorTransform all_transforms;
- MetaCrtcXrandr *crtc_xrandr;
- XRRPanning *panning;
- unsigned int i;
- GList *modes;
-
- all_transforms =
- meta_monitor_transform_from_xrandr_all (xrandr_crtc->rotations);
- crtc_xrandr = g_object_new (META_TYPE_CRTC_XRANDR,
- "id", (uint64_t) crtc_id,
- "gpu", gpu,
- "all-transforms", all_transforms,
- NULL);
-
- crtc_xrandr->transform =
- meta_monitor_transform_from_xrandr (xrandr_crtc->rotation);
-
- panning = XRRGetPanning (xdisplay, resources, crtc_id);
- if (panning && panning->width > 0 && panning->height > 0)
- {
- crtc_xrandr->rect = (MetaRectangle) {
- .x = panning->left,
- .y = panning->top,
- .width = panning->width,
- .height = panning->height,
- };
- }
- else
- {
- crtc_xrandr->rect = (MetaRectangle) {
- .x = xrandr_crtc->x,
- .y = xrandr_crtc->y,
- .width = xrandr_crtc->width,
- .height = xrandr_crtc->height,
- };
- }
- XRRFreePanning (panning);
-
- modes = meta_gpu_get_modes (gpu);
- for (i = 0; i < (unsigned int) resources->nmode; i++)
- {
- if (resources->modes[i].id == xrandr_crtc->mode)
- {
- crtc_xrandr->current_mode = g_list_nth_data (modes, i);
- break;
- }
- }
-
- if (crtc_xrandr->current_mode)
- {
- meta_crtc_set_config (META_CRTC (crtc_xrandr),
- &GRAPHENE_RECT_INIT (crtc_xrandr->rect.x,
- crtc_xrandr->rect.y,
- crtc_xrandr->rect.width,
- crtc_xrandr->rect.height),
- crtc_xrandr->current_mode,
- crtc_xrandr->transform);
- }
-
- return crtc_xrandr;
-}
-
-static void
-meta_crtc_xrandr_init (MetaCrtcXrandr *crtc_xrandr)
-{
-}
-
-static void
-meta_crtc_xrandr_class_init (MetaCrtcXrandrClass *klass)
-{
-}
diff --git a/src/backends/x11/meta-crtc-xrandr.h b/src/backends/x11/meta-crtc-xrandr.h
deleted file mode 100644
index dbf5da0c6..000000000
--- a/src/backends/x11/meta-crtc-xrandr.h
+++ /dev/null
@@ -1,57 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2017 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-
-#ifndef META_CRTC_XRANDR_H
-#define META_CRTC_XRANDR_H
-
-#include <X11/extensions/Xrandr.h>
-#include <xcb/randr.h>
-
-#include "backends/meta-crtc.h"
-#include "backends/x11/meta-gpu-xrandr.h"
-
-#define META_TYPE_CRTC_XRANDR (meta_crtc_xrandr_get_type ())
-G_DECLARE_FINAL_TYPE (MetaCrtcXrandr, meta_crtc_xrandr,
- META, CRTC_XRANDR,
- MetaCrtc)
-
-gboolean meta_crtc_xrandr_set_config (MetaCrtcXrandr *crtc_xrandr,
- xcb_randr_crtc_t xrandr_crtc,
- xcb_timestamp_t timestamp,
- int x,
- int y,
- xcb_randr_mode_t mode,
- xcb_randr_rotation_t rotation,
- xcb_randr_output_t *outputs,
- int n_outputs,
- xcb_timestamp_t *out_timestamp);
-
-gboolean meta_crtc_xrandr_is_assignment_changed (MetaCrtcXrandr *crtc_xrandr,
- MetaCrtcAssignment *crtc_assignment);
-
-MetaCrtcMode * meta_crtc_xrandr_get_current_mode (MetaCrtcXrandr *crtc_xrandr);
-
-MetaCrtcXrandr * meta_crtc_xrandr_new (MetaGpuXrandr *gpu_xrandr,
- XRRCrtcInfo *xrandr_crtc,
- RRCrtc crtc_id,
- XRRScreenResources *resources);
-
-#endif /* META_CRTC_XRANDR_H */
diff --git a/src/backends/x11/meta-cursor-renderer-x11.c b/src/backends/x11/meta-cursor-renderer-x11.c
deleted file mode 100644
index 4d81f8027..000000000
--- a/src/backends/x11/meta-cursor-renderer-x11.c
+++ /dev/null
@@ -1,114 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2014 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Written by:
- * Jasper St. Pierre <jstpierre@mecheye.net>
- */
-
-#include "config.h"
-
-#include "backends/x11/meta-cursor-renderer-x11.h"
-
-#include <X11/extensions/Xfixes.h>
-
-#include "backends/meta-cursor-sprite-xcursor.h"
-#include "backends/meta-stage-private.h"
-#include "backends/x11/meta-backend-x11.h"
-
-struct _MetaCursorRendererX11Private
-{
- gboolean server_cursor_visible;
-};
-typedef struct _MetaCursorRendererX11Private MetaCursorRendererX11Private;
-
-G_DEFINE_TYPE_WITH_PRIVATE (MetaCursorRendererX11, meta_cursor_renderer_x11, META_TYPE_CURSOR_RENDERER);
-
-static gboolean
-meta_cursor_renderer_x11_update_cursor (MetaCursorRenderer *renderer,
- MetaCursorSprite *cursor_sprite)
-{
- MetaCursorRendererX11 *x11 = META_CURSOR_RENDERER_X11 (renderer);
- MetaCursorRendererX11Private *priv = meta_cursor_renderer_x11_get_instance_private (x11);
-
- MetaBackendX11 *backend = META_BACKEND_X11 (meta_get_backend ());
- Window xwindow = meta_backend_x11_get_xwindow (backend);
- Display *xdisplay = meta_backend_x11_get_xdisplay (backend);
-
- if (xwindow == None)
- {
- if (cursor_sprite)
- meta_cursor_sprite_realize_texture (cursor_sprite);
- return FALSE;
- }
-
- gboolean has_server_cursor = FALSE;
-
- if (cursor_sprite && META_IS_CURSOR_SPRITE_XCURSOR (cursor_sprite))
- {
- MetaCursorSpriteXcursor *sprite_xcursor =
- META_CURSOR_SPRITE_XCURSOR (cursor_sprite);
- MetaCursor cursor;
-
- cursor = meta_cursor_sprite_xcursor_get_cursor (sprite_xcursor);
- if (cursor != META_CURSOR_NONE)
- {
- Cursor xcursor;
-
- xcursor = meta_create_x_cursor (xdisplay, cursor);
- XDefineCursor (xdisplay, xwindow, xcursor);
- XFlush (xdisplay);
- XFreeCursor (xdisplay, xcursor);
-
- has_server_cursor = TRUE;
- }
- }
-
- if (has_server_cursor != priv->server_cursor_visible)
- {
- if (has_server_cursor)
- XFixesShowCursor (xdisplay, xwindow);
- else
- XFixesHideCursor (xdisplay, xwindow);
-
- priv->server_cursor_visible = has_server_cursor;
- }
-
- if (cursor_sprite)
- meta_cursor_sprite_realize_texture (cursor_sprite);
-
- return priv->server_cursor_visible;
-}
-
-static void
-meta_cursor_renderer_x11_class_init (MetaCursorRendererX11Class *klass)
-{
- MetaCursorRendererClass *renderer_class = META_CURSOR_RENDERER_CLASS (klass);
-
- renderer_class->update_cursor = meta_cursor_renderer_x11_update_cursor;
-}
-
-static void
-meta_cursor_renderer_x11_init (MetaCursorRendererX11 *x11)
-{
- MetaCursorRendererX11Private *priv = meta_cursor_renderer_x11_get_instance_private (x11);
-
- /* XFixes has no way to retrieve the current cursor visibility. */
- priv->server_cursor_visible = TRUE;
-}
diff --git a/src/backends/x11/meta-cursor-renderer-x11.h b/src/backends/x11/meta-cursor-renderer-x11.h
deleted file mode 100644
index b52834375..000000000
--- a/src/backends/x11/meta-cursor-renderer-x11.h
+++ /dev/null
@@ -1,52 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2014 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Written by:
- * Jasper St. Pierre <jstpierre@mecheye.net>
- */
-
-#ifndef META_CURSOR_RENDERER_X11_H
-#define META_CURSOR_RENDERER_X11_H
-
-#include "backends/meta-cursor-renderer.h"
-
-#define META_TYPE_CURSOR_RENDERER_X11 (meta_cursor_renderer_x11_get_type ())
-#define META_CURSOR_RENDERER_X11(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), META_TYPE_CURSOR_RENDERER_X11, MetaCursorRendererX11))
-#define META_CURSOR_RENDERER_X11_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), META_TYPE_CURSOR_RENDERER_X11, MetaCursorRendererX11Class))
-#define META_IS_CURSOR_RENDERER_X11(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), META_TYPE_CURSOR_RENDERER_X11))
-#define META_IS_CURSOR_RENDERER_X11_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), META_TYPE_CURSOR_RENDERER_X11))
-#define META_CURSOR_RENDERER_X11_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), META_TYPE_CURSOR_RENDERER_X11, MetaCursorRendererX11Class))
-
-typedef struct _MetaCursorRendererX11 MetaCursorRendererX11;
-typedef struct _MetaCursorRendererX11Class MetaCursorRendererX11Class;
-
-struct _MetaCursorRendererX11
-{
- MetaCursorRenderer parent;
-};
-
-struct _MetaCursorRendererX11Class
-{
- MetaCursorRendererClass parent_class;
-};
-
-GType meta_cursor_renderer_x11_get_type (void) G_GNUC_CONST;
-
-#endif /* META_CURSOR_RENDERER_X11_H */
diff --git a/src/backends/x11/meta-cursor-tracker-x11.c b/src/backends/x11/meta-cursor-tracker-x11.c
deleted file mode 100644
index 7355f828e..000000000
--- a/src/backends/x11/meta-cursor-tracker-x11.c
+++ /dev/null
@@ -1,186 +0,0 @@
-/*
- * Copyright (C) 2020 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- */
-
-#include "config.h"
-
-#include "backends/x11/meta-cursor-tracker-x11.h"
-
-#include "backends/x11/cm/meta-cursor-sprite-xfixes.h"
-#include "clutter/clutter-private.h"
-#include "meta/meta-x11-errors.h"
-#include "x11/meta-x11-display-private.h"
-
-#define UPDATE_POSITION_TIMEOUT_MS (ms (100))
-
-struct _MetaCursorTrackerX11
-{
- MetaCursorTracker parent;
-
- gboolean is_force_track_position_enabled;
- guint update_position_timeout_id;
-
- MetaCursorSpriteXfixes *xfixes_cursor;
-};
-
-G_DEFINE_TYPE (MetaCursorTrackerX11, meta_cursor_tracker_x11,
- META_TYPE_CURSOR_TRACKER)
-
-static gboolean
-ensure_xfixes_cursor (MetaCursorTrackerX11 *tracker_x11);
-
-gboolean
-meta_cursor_tracker_x11_handle_xevent (MetaCursorTrackerX11 *tracker_x11,
- XEvent *xevent)
-{
- MetaX11Display *x11_display = meta_get_display ()->x11_display;
- XFixesCursorNotifyEvent *notify_event;
-
- if (xevent->xany.type != x11_display->xfixes_event_base + XFixesCursorNotify)
- return FALSE;
-
- notify_event = (XFixesCursorNotifyEvent *)xevent;
- if (notify_event->subtype != XFixesDisplayCursorNotify)
- return FALSE;
-
- g_clear_object (&tracker_x11->xfixes_cursor);
- meta_cursor_tracker_notify_cursor_changed (META_CURSOR_TRACKER (tracker_x11));
-
- return TRUE;
-}
-
-static void
-update_position (MetaCursorTrackerX11 *tracker_x11)
-{
- MetaCursorTracker *tracker = META_CURSOR_TRACKER (tracker_x11);
-
- meta_cursor_tracker_invalidate_position (tracker);
-}
-
-static gboolean
-ensure_xfixes_cursor (MetaCursorTrackerX11 *tracker_x11)
-{
- MetaDisplay *display = meta_get_display ();
- g_autoptr (GError) error = NULL;
-
- if (tracker_x11->xfixes_cursor)
- return FALSE;
-
- tracker_x11->xfixes_cursor = meta_cursor_sprite_xfixes_new (display, &error);
- if (!tracker_x11->xfixes_cursor)
- g_warning ("Failed to create XFIXES cursor: %s", error->message);
-
- return TRUE;
-}
-
-static gboolean
-update_cursor_timeout (gpointer user_data)
-{
- MetaCursorTrackerX11 *tracker_x11 = user_data;
- MetaCursorTracker *tracker = META_CURSOR_TRACKER (tracker_x11);
- MetaBackend *backend = meta_cursor_tracker_get_backend (tracker);
- MetaCursorRenderer *cursor_renderer =
- meta_backend_get_cursor_renderer (backend);
- gboolean cursor_changed;
- MetaCursorSprite *cursor_sprite;
-
- update_position (tracker_x11);
-
- cursor_changed = ensure_xfixes_cursor (tracker_x11);
-
- if (tracker_x11->xfixes_cursor)
- cursor_sprite = META_CURSOR_SPRITE (tracker_x11->xfixes_cursor);
- else
- cursor_sprite = NULL;
-
- meta_cursor_renderer_update_stage_overlay (cursor_renderer, cursor_sprite);
-
- if (cursor_changed)
- meta_cursor_tracker_notify_cursor_changed (tracker);
-
- return G_SOURCE_CONTINUE;
-}
-
-static void
-meta_cursor_tracker_x11_set_force_track_position (MetaCursorTracker *tracker,
- gboolean is_enabled)
-{
- MetaCursorTrackerX11 *tracker_x11 = META_CURSOR_TRACKER_X11 (tracker);
-
- if (tracker_x11->is_force_track_position_enabled == is_enabled)
- return;
-
- tracker_x11->is_force_track_position_enabled = is_enabled;
-
- if (is_enabled)
- {
- tracker_x11->update_position_timeout_id =
- g_timeout_add (UPDATE_POSITION_TIMEOUT_MS,
- update_cursor_timeout,
- tracker_x11);
- update_position (tracker_x11);
- }
- else
- {
- g_clear_handle_id (&tracker_x11->update_position_timeout_id,
- g_source_remove);
- }
-}
-
-static MetaCursorSprite *
-meta_cursor_tracker_x11_get_sprite (MetaCursorTracker *tracker)
-{
- MetaCursorTrackerX11 *tracker_x11 = META_CURSOR_TRACKER_X11 (tracker);
-
- ensure_xfixes_cursor (META_CURSOR_TRACKER_X11 (tracker));
- if (tracker_x11->xfixes_cursor)
- return META_CURSOR_SPRITE (tracker_x11->xfixes_cursor);
- else
- return NULL;
-}
-
-static void
-meta_cursor_tracker_x11_dispose (GObject *object)
-{
- MetaCursorTrackerX11 *tracker_x11 = META_CURSOR_TRACKER_X11 (object);
-
- g_clear_handle_id (&tracker_x11->update_position_timeout_id, g_source_remove);
- g_clear_object (&tracker_x11->xfixes_cursor);
-
- G_OBJECT_CLASS (meta_cursor_tracker_x11_parent_class)->dispose (object);
-}
-
-static void
-meta_cursor_tracker_x11_init (MetaCursorTrackerX11 *tracker_x11)
-{
-}
-
-static void
-meta_cursor_tracker_x11_class_init (MetaCursorTrackerX11Class *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
- MetaCursorTrackerClass *tracker_class = META_CURSOR_TRACKER_CLASS (klass);
-
- object_class->dispose = meta_cursor_tracker_x11_dispose;
-
- tracker_class->set_force_track_position =
- meta_cursor_tracker_x11_set_force_track_position;
- tracker_class->get_sprite =
- meta_cursor_tracker_x11_get_sprite;
-}
diff --git a/src/backends/x11/meta-cursor-tracker-x11.h b/src/backends/x11/meta-cursor-tracker-x11.h
deleted file mode 100644
index a4b462844..000000000
--- a/src/backends/x11/meta-cursor-tracker-x11.h
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright (C) 2020 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- */
-
-#ifndef META_CURSOR_TRACKER_X11_H
-#define META_CURSOR_TRACKER_X11_H
-
-#include "backends/meta-cursor-tracker-private.h"
-
-#define META_TYPE_CURSOR_TRACKER_X11 (meta_cursor_tracker_x11_get_type ())
-G_DECLARE_FINAL_TYPE (MetaCursorTrackerX11, meta_cursor_tracker_x11,
- META, CURSOR_TRACKER_X11,
- MetaCursorTracker)
-
-gboolean meta_cursor_tracker_x11_handle_xevent (MetaCursorTrackerX11 *tracker_x11,
- XEvent *xevent);
-
-#endif /* META_CURSOR_TRACKER_X11_H */
diff --git a/src/backends/x11/meta-event-x11.c b/src/backends/x11/meta-event-x11.c
deleted file mode 100644
index d1a94bb56..000000000
--- a/src/backends/x11/meta-event-x11.c
+++ /dev/null
@@ -1,114 +0,0 @@
-/* Copyright (C) 2006, 2007, 2008 OpenedHand Ltd
- * Copyright (C) 2009, 2010 Intel Corp.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
- *
- *
- *
- * Authored by:
- * Matthew Allum <mallum@openedhand.com>
- * Emmanuele Bassi <ebassi@linux.intel.com>
- */
-
-#include "config.h"
-
-#include <glib.h>
-#include <string.h>
-
-#include "backends/x11/meta-event-x11.h"
-#include "clutter/clutter-mutter.h"
-
-/**
- * meta_x11_handle_event:
- * @xevent: pointer to XEvent structure
- *
- * This function processes a single X event; it can be used to hook
- * into external X11 event processing (for example, a GDK filter
- * function).
- *
- * Return value: #MetaX11FilterReturn. %META_X11_FILTER_REMOVE
- * indicates that Clutter has internally handled the event and the
- * caller should do no further processing. %META_X11_FILTER_CONTINUE
- * indicates that Clutter is either not interested in the event,
- * or has used the event to update internal state without taking
- * any exclusive action. %META_X11_FILTER_TRANSLATE will not
- * occur.
- *
- * Since: 0.8
- */
-MetaX11FilterReturn
-meta_x11_handle_event (XEvent *xevent)
-{
- MetaX11FilterReturn result;
- ClutterBackend *backend;
- ClutterEvent *event;
- gint spin = 1;
- MetaClutterBackendX11 *backend_x11;
- Display *xdisplay;
- gboolean allocated_event;
-
- /* The return values here are someone approximate; we return
- * META_X11_FILTER_REMOVE if a clutter event is
- * generated for the event. This mostly, but not entirely,
- * corresponds to whether other event processing should be
- * excluded. As long as the stage window is not shared with another
- * toolkit it should be safe, and never return
- * %META_X11_FILTER_REMOVE when more processing is needed.
- */
-
- result = META_X11_FILTER_CONTINUE;
-
- backend = clutter_get_default_backend ();
-
- event = clutter_event_new (CLUTTER_NOTHING);
-
- backend_x11 = META_CLUTTER_BACKEND_X11 (backend);
- xdisplay = backend_x11->xdisplay;
-
- allocated_event = XGetEventData (xdisplay, &xevent->xcookie);
-
- if (_clutter_backend_translate_event (backend, xevent, event))
- {
- _clutter_event_push (event, FALSE);
-
- result = META_X11_FILTER_REMOVE;
- }
- else
- {
- clutter_event_free (event);
- goto out;
- }
-
- /*
- * Motion events can generate synthetic enter and leave events, so if we
- * are processing a motion event, we need to spin the event loop at least
- * two extra times to pump the enter/leave events through (otherwise they
- * just get pushed down the queue and never processed).
- */
- if (event->type == CLUTTER_MOTION)
- spin += 2;
-
- while (spin > 0 && (event = clutter_event_get ()))
- {
- /* forward the event into clutter for emission etc. */
- _clutter_stage_queue_event (event->any.stage, event, FALSE);
- --spin;
- }
-
-out:
- if (allocated_event)
- XFreeEventData (xdisplay, &xevent->xcookie);
-
- return result;
-}
diff --git a/src/backends/x11/meta-event-x11.h b/src/backends/x11/meta-event-x11.h
deleted file mode 100644
index 3ddd0fd5d..000000000
--- a/src/backends/x11/meta-event-x11.h
+++ /dev/null
@@ -1,33 +0,0 @@
-/* Copyright (C) 2006, 2007, 2008 OpenedHand Ltd
- * Copyright (C) 2009, 2010 Intel Corp.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
- *
- *
- *
- * Authored by:
- * Matthew Allum <mallum@openedhand.com>
- * Emmanuele Bassi <ebassi@linux.intel.com>
- */
-
-#ifndef META_EVENT_X11_H
-#define META_EVENT_X11_H
-
-#include <X11/Xlib.h>
-
-#include "backends/x11/meta-clutter-backend-x11.h"
-
-MetaX11FilterReturn meta_x11_handle_event (XEvent *xevent);
-
-#endif /* META_EVENT_X11_H */
diff --git a/src/backends/x11/meta-gpu-xrandr.c b/src/backends/x11/meta-gpu-xrandr.c
deleted file mode 100644
index bc3292d36..000000000
--- a/src/backends/x11/meta-gpu-xrandr.c
+++ /dev/null
@@ -1,277 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2001, 2002 Havoc Pennington
- * Copyright (C) 2002, 2003 Red Hat Inc.
- * Some ICCCM manager selection code derived from fvwm2,
- * Copyright (C) 2001 Dominik Vogt, Matthias Clasen, and fvwm2 team
- * Copyright (C) 2003 Rob Adams
- * Copyright (C) 2004-2006 Elijah Newren
- * Copyright (C) 2013-2017 Red Hat Inc.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "config.h"
-
-#include "backends/x11/meta-gpu-xrandr.h"
-
-#include <string.h>
-#include <X11/extensions/dpms.h>
-#include <X11/Xlibint.h>
-
-#include "backends/meta-backend-private.h"
-#include "backends/meta-output.h"
-#include "backends/x11/meta-backend-x11.h"
-#include "backends/x11/meta-crtc-xrandr.h"
-#include "backends/x11/meta-monitor-manager-xrandr.h"
-#include "backends/x11/meta-output-xrandr.h"
-
-struct _MetaGpuXrandr
-{
- MetaGpu parent;
-
- XRRScreenResources *resources;
-
- int max_screen_width;
- int max_screen_height;
-};
-
-G_DEFINE_TYPE (MetaGpuXrandr, meta_gpu_xrandr, META_TYPE_GPU)
-
-XRRScreenResources *
-meta_gpu_xrandr_get_resources (MetaGpuXrandr *gpu_xrandr)
-{
- return gpu_xrandr->resources;
-}
-
-void
-meta_gpu_xrandr_get_max_screen_size (MetaGpuXrandr *gpu_xrandr,
- int *max_width,
- int *max_height)
-{
- *max_width = gpu_xrandr->max_screen_width;
- *max_height = gpu_xrandr->max_screen_height;
-}
-
-static int
-compare_outputs (const void *one,
- const void *two)
-{
- MetaOutput *o_one = (MetaOutput *) one;
- MetaOutput *o_two = (MetaOutput *) two;
- const MetaOutputInfo *output_info_one = meta_output_get_info (o_one);
- const MetaOutputInfo *output_info_two = meta_output_get_info (o_two);
-
- return strcmp (output_info_one->name, output_info_two->name);
-}
-
-static char *
-get_xmode_name (XRRModeInfo *xmode)
-{
- int width = xmode->width;
- int height = xmode->height;
-
- return g_strdup_printf ("%dx%d", width, height);
-}
-
-static gboolean
-meta_gpu_xrandr_read_current (MetaGpu *gpu,
- GError **error)
-{
- MetaGpuXrandr *gpu_xrandr = META_GPU_XRANDR (gpu);
- MetaBackend *backend = meta_gpu_get_backend (gpu);
- MetaMonitorManager *monitor_manager =
- meta_backend_get_monitor_manager (backend);
- MetaMonitorManagerXrandr *monitor_manager_xrandr =
- META_MONITOR_MANAGER_XRANDR (monitor_manager);
- Display *xdisplay =
- meta_monitor_manager_xrandr_get_xdisplay (monitor_manager_xrandr);
- XRRScreenResources *resources;
- RROutput primary_output;
- unsigned int i, j;
- GList *l;
- int min_width, min_height;
- Screen *screen;
- GList *outputs = NULL;
- GList *modes = NULL;
- GList *crtcs = NULL;
-
- if (gpu_xrandr->resources)
- XRRFreeScreenResources (gpu_xrandr->resources);
- gpu_xrandr->resources = NULL;
-
- XRRGetScreenSizeRange (xdisplay, DefaultRootWindow (xdisplay),
- &min_width,
- &min_height,
- &gpu_xrandr->max_screen_width,
- &gpu_xrandr->max_screen_height);
-
- screen = ScreenOfDisplay (xdisplay, DefaultScreen (xdisplay));
- /* This is updated because we called XRRUpdateConfiguration. */
- monitor_manager->screen_width = WidthOfScreen (screen);
- monitor_manager->screen_height = HeightOfScreen (screen);
-
- resources = XRRGetScreenResourcesCurrent (xdisplay,
- DefaultRootWindow (xdisplay));
- if (!resources)
- {
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- "Failed to retrieve Xrandr screen resources");
- return FALSE;
- }
-
- gpu_xrandr->resources = resources;
-
- outputs = NULL;
- modes = NULL;
- crtcs = NULL;
-
- for (i = 0; i < (unsigned)resources->nmode; i++)
- {
- XRRModeInfo *xmode = &resources->modes[i];
- g_autofree char *crtc_mode_name = NULL;
- MetaCrtcMode *mode;
- g_autoptr (MetaCrtcModeInfo) crtc_mode_info = NULL;
-
- crtc_mode_info = meta_crtc_mode_info_new ();
- crtc_mode_info->width = xmode->width;
- crtc_mode_info->height = xmode->height;
- crtc_mode_info->refresh_rate = (xmode->dotClock /
- ((float)xmode->hTotal * xmode->vTotal));
- crtc_mode_info->flags = xmode->modeFlags;
-
- crtc_mode_name = get_xmode_name (xmode);
- mode = g_object_new (META_TYPE_CRTC_MODE,
- "id", (uint64_t) xmode->id,
- "name", crtc_mode_name,
- "info", crtc_mode_info,
- NULL);
- modes = g_list_append (modes, mode);
- }
- meta_gpu_take_modes (gpu, modes);
-
- for (i = 0; i < (unsigned)resources->ncrtc; i++)
- {
- XRRCrtcInfo *xrandr_crtc;
- RRCrtc crtc_id;
- MetaCrtcXrandr *crtc_xrandr;
-
- crtc_id = resources->crtcs[i];
- xrandr_crtc = XRRGetCrtcInfo (xdisplay,
- resources, crtc_id);
- crtc_xrandr = meta_crtc_xrandr_new (gpu_xrandr,
- xrandr_crtc, crtc_id, resources);
- XRRFreeCrtcInfo (xrandr_crtc);
-
- crtcs = g_list_append (crtcs, crtc_xrandr);
- }
-
- meta_gpu_take_crtcs (gpu, crtcs);
-
- primary_output = XRRGetOutputPrimary (xdisplay,
- DefaultRootWindow (xdisplay));
-
- for (i = 0; i < (unsigned)resources->noutput; i++)
- {
- RROutput output_id;
- XRROutputInfo *xrandr_output;
-
- output_id = resources->outputs[i];
- xrandr_output = XRRGetOutputInfo (xdisplay,
- resources, output_id);
- if (!xrandr_output)
- continue;
-
- if (xrandr_output->connection != RR_Disconnected)
- {
- MetaOutputXrandr *output_xrandr;
-
- output_xrandr = meta_output_xrandr_new (gpu_xrandr,
- xrandr_output,
- output_id,
- primary_output);
- if (output_xrandr)
- outputs = g_list_prepend (outputs, output_xrandr);
- }
-
- XRRFreeOutputInfo (xrandr_output);
- }
-
- /* Sort the outputs for easier handling in MetaMonitorConfig */
- outputs = g_list_sort (outputs, compare_outputs);
-
- meta_gpu_take_outputs (gpu, outputs);
-
- /* Now fix the clones */
- for (l = outputs; l; l = l->next)
- {
- MetaOutput *output = l->data;
- const MetaOutputInfo *output_info = meta_output_get_info (output);
- GList *k;
-
- for (j = 0; j < output_info->n_possible_clones; j++)
- {
- RROutput clone = GPOINTER_TO_INT (output_info->possible_clones[j]);
-
- for (k = outputs; k; k = k->next)
- {
- MetaOutput *possible_clone = k->data;
-
- if (clone == (XID) meta_output_get_id (possible_clone))
- {
- output_info->possible_clones[j] = possible_clone;
- break;
- }
- }
- }
- }
-
- return TRUE;
-}
-
-MetaGpuXrandr *
-meta_gpu_xrandr_new (MetaBackendX11 *backend_x11)
-{
- return g_object_new (META_TYPE_GPU_XRANDR,
- "backend", backend_x11,
- NULL);
-}
-
-static void
-meta_gpu_xrandr_finalize (GObject *object)
-{
- MetaGpuXrandr *gpu_xrandr = META_GPU_XRANDR (object);
-
- g_clear_pointer (&gpu_xrandr->resources,
- XRRFreeScreenResources);
-
- G_OBJECT_CLASS (meta_gpu_xrandr_parent_class)->finalize (object);
-}
-
-static void
-meta_gpu_xrandr_init (MetaGpuXrandr *gpu_xrandr)
-{
-}
-
-static void
-meta_gpu_xrandr_class_init (MetaGpuXrandrClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
- MetaGpuClass *gpu_class = META_GPU_CLASS (klass);
-
- object_class->finalize = meta_gpu_xrandr_finalize;
-
- gpu_class->read_current = meta_gpu_xrandr_read_current;
-}
diff --git a/src/backends/x11/meta-gpu-xrandr.h b/src/backends/x11/meta-gpu-xrandr.h
deleted file mode 100644
index 2086f8632..000000000
--- a/src/backends/x11/meta-gpu-xrandr.h
+++ /dev/null
@@ -1,42 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2017 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-
-#ifndef META_GPU_XRANDR_H
-#define META_GPU_XRANDR_H
-
-#include <glib-object.h>
-#include <X11/extensions/Xrandr.h>
-
-#include "backends/meta-gpu.h"
-#include "backends/x11/meta-backend-x11.h"
-
-#define META_TYPE_GPU_XRANDR (meta_gpu_xrandr_get_type ())
-G_DECLARE_FINAL_TYPE (MetaGpuXrandr, meta_gpu_xrandr, META, GPU_XRANDR, MetaGpu)
-
-XRRScreenResources * meta_gpu_xrandr_get_resources (MetaGpuXrandr *gpu_xrandr);
-
-void meta_gpu_xrandr_get_max_screen_size (MetaGpuXrandr *gpu_xrandr,
- int *max_width,
- int *max_height);
-
-MetaGpuXrandr * meta_gpu_xrandr_new (MetaBackendX11 *backend_x11);
-
-#endif /* META_GPU_XRANDR_H */
diff --git a/src/backends/x11/meta-input-device-tool-x11.c b/src/backends/x11/meta-input-device-tool-x11.c
deleted file mode 100644
index bec4d1fad..000000000
--- a/src/backends/x11/meta-input-device-tool-x11.c
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright © 2016 Red Hat
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
- *
- * Author: Carlos Garnacho <carlosg@gnome.org>
- */
-
-#include "config.h"
-
-#include "meta-input-device-tool-x11.h"
-
-G_DEFINE_TYPE (MetaInputDeviceToolX11, meta_input_device_tool_x11,
- CLUTTER_TYPE_INPUT_DEVICE_TOOL)
-
-static void
-meta_input_device_tool_x11_class_init (MetaInputDeviceToolX11Class *klass)
-{
-}
-
-static void
-meta_input_device_tool_x11_init (MetaInputDeviceToolX11 *tool)
-{
-}
-
-ClutterInputDeviceTool *
-meta_input_device_tool_x11_new (guint serial,
- ClutterInputDeviceToolType type)
-{
- ClutterInputAxisFlags axes =
- CLUTTER_INPUT_AXIS_FLAG_PRESSURE |
- CLUTTER_INPUT_AXIS_FLAG_DISTANCE |
- CLUTTER_INPUT_AXIS_FLAG_XTILT |
- CLUTTER_INPUT_AXIS_FLAG_YTILT |
- CLUTTER_INPUT_AXIS_FLAG_WHEEL |
- CLUTTER_INPUT_AXIS_FLAG_DISTANCE |
- CLUTTER_INPUT_AXIS_FLAG_ROTATION |
- CLUTTER_INPUT_AXIS_FLAG_SLIDER;
-
- return g_object_new (META_TYPE_INPUT_DEVICE_TOOL_X11,
- "type", type,
- "serial", serial,
- "axes", axes,
- NULL);
-}
diff --git a/src/backends/x11/meta-input-device-tool-x11.h b/src/backends/x11/meta-input-device-tool-x11.h
deleted file mode 100644
index e52803da9..000000000
--- a/src/backends/x11/meta-input-device-tool-x11.h
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Copyright © 2016 Red Hat
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
- *
- * Author: Carlos Garnacho <carlosg@gnome.org>
- */
-
-#ifndef META_INPUT_DEVICE_TOOL_X11_H
-#define META_INPUT_DEVICE_TOOL_X11_H
-
-#include "clutter/clutter.h"
-
-#define META_TYPE_INPUT_DEVICE_TOOL_X11 (meta_input_device_tool_x11_get_type ())
-
-#define META_INPUT_DEVICE_TOOL_X11(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), META_TYPE_INPUT_DEVICE_TOOL_X11, MetaInputDeviceToolX11))
-#define META_IS_INPUT_DEVICE_TOOL_X11(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), META_TYPE_INPUT_DEVICE_TOOL_X11))
-#define META_INPUT_DEVICE_TOOL_X11_CLASS(c) (G_TYPE_CHECK_CLASS_CAST ((c), META_TYPE_INPUT_DEVICE_TOOL_X11, MetaInputDeviceToolX11Class))
-#define META_IS_INPUT_DEVICE_TOOL_X11_CLASS(c) (G_TYPE_CHECK_CLASS_TYPE ((c), META_TYPE_INPUT_DEVICE_TOOL_X1))
-#define META_INPUT_DEVICE_TOOL_X11_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), META_TYPE_INPUT_DEVICE_TOOL_X11, MetaInputDeviceToolX11Class))
-
-typedef struct _MetaInputDeviceToolX11 MetaInputDeviceToolX11;
-typedef struct _MetaInputDeviceToolX11Class MetaInputDeviceToolX11Class;
-
-struct _MetaInputDeviceToolX11
-{
- ClutterInputDeviceTool parent_instance;
-};
-
-struct _MetaInputDeviceToolX11Class
-{
- ClutterInputDeviceToolClass parent_class;
-};
-
-GType meta_input_device_tool_x11_get_type (void) G_GNUC_CONST;
-
-ClutterInputDeviceTool * meta_input_device_tool_x11_new (guint serial,
- ClutterInputDeviceToolType type);
-
-#endif /* META_INPUT_DEVICE_TOOL_X11_H */
diff --git a/src/backends/x11/meta-input-device-x11.c b/src/backends/x11/meta-input-device-x11.c
deleted file mode 100644
index 81a932e93..000000000
--- a/src/backends/x11/meta-input-device-x11.c
+++ /dev/null
@@ -1,795 +0,0 @@
-/*
- * Copyright © 2011 Intel Corp.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
- *
- * Author: Emmanuele Bassi <ebassi@linux.intel.com>
- */
-
-#include "config.h"
-
-#include <X11/extensions/XInput2.h>
-
-#include "clutter/clutter-mutter.h"
-#include "backends/x11/meta-clutter-backend-x11.h"
-#include "backends/x11/meta-input-device-x11.h"
-
-struct _MetaInputDeviceX11
-{
- ClutterInputDevice device;
-
- int32_t device_id;
- ClutterInputDeviceTool *current_tool;
-
- int inhibit_pointer_query_timer;
- gboolean query_status;
- float current_x;
- float current_y;
-
- GArray *axes;
- GArray *scroll_info;
-
-#ifdef HAVE_LIBWACOM
- GArray *group_modes;
-#endif
-};
-
-typedef struct _MetaX11AxisInfo
-{
- ClutterInputAxis axis;
-
- double min_axis;
- double max_axis;
-
- double min_value;
- double max_value;
-
- double resolution;
-} MetaX11AxisInfo;
-
-typedef struct _MetaX11ScrollInfo
-{
- guint axis_id;
- ClutterScrollDirection direction;
- double increment;
-
- double last_value;
- guint last_value_valid : 1;
-} MetaX11ScrollInfo;
-
-struct _MetaInputDeviceX11Class
-{
- ClutterInputDeviceClass device_class;
-};
-
-#define N_BUTTONS 5
-
-enum
-{
- PROP_0,
- PROP_ID,
- N_PROPS
-};
-
-static GParamSpec *props[N_PROPS] = { 0 };
-
-G_DEFINE_TYPE (MetaInputDeviceX11,
- meta_input_device_x11,
- META_TYPE_INPUT_DEVICE)
-
-static void
-meta_input_device_x11_constructed (GObject *object)
-{
- MetaInputDeviceX11 *device_xi2 = META_INPUT_DEVICE_X11 (object);
-
- if (G_OBJECT_CLASS (meta_input_device_x11_parent_class)->constructed)
- G_OBJECT_CLASS (meta_input_device_x11_parent_class)->constructed (object);
-
-#ifdef HAVE_LIBWACOM
- if (clutter_input_device_get_device_type (CLUTTER_INPUT_DEVICE (object)) == CLUTTER_PAD_DEVICE)
- {
- device_xi2->group_modes = g_array_new (FALSE, TRUE, sizeof (uint32_t));
- g_array_set_size (device_xi2->group_modes,
- clutter_input_device_get_n_mode_groups (CLUTTER_INPUT_DEVICE (object)));
- }
-#endif
-}
-
-static gboolean
-meta_input_device_x11_is_grouped (ClutterInputDevice *device,
- ClutterInputDevice *other_device)
-{
-#ifdef HAVE_LIBWACOM
- WacomDevice *wacom_device, *other_wacom_device;
-
- wacom_device =
- meta_input_device_get_wacom_device (META_INPUT_DEVICE (device));
- other_wacom_device =
- meta_input_device_get_wacom_device (META_INPUT_DEVICE (other_device));
-
- if (wacom_device && other_wacom_device &&
- libwacom_compare (wacom_device,
- other_wacom_device,
- WCOMPARE_NORMAL) == 0)
- return TRUE;
-#endif
-
- if (clutter_input_device_get_vendor_id (device) &&
- clutter_input_device_get_product_id (device) &&
- clutter_input_device_get_vendor_id (other_device) &&
- clutter_input_device_get_product_id (other_device))
- {
- if (strcmp (clutter_input_device_get_vendor_id (device),
- clutter_input_device_get_vendor_id (other_device)) == 0 &&
- strcmp (clutter_input_device_get_product_id (device),
- clutter_input_device_get_product_id (other_device)) == 0)
- return TRUE;
- }
-
- return FALSE;
-}
-
-static void
-meta_input_device_x11_finalize (GObject *object)
-{
- MetaInputDeviceX11 *device_xi2 = META_INPUT_DEVICE_X11 (object);
-
- g_clear_pointer (&device_xi2->axes, g_array_unref);
- g_clear_pointer (&device_xi2->scroll_info, g_array_unref);
-
-#ifdef HAVE_LIBWACOM
- if (device_xi2->group_modes)
- g_array_unref (device_xi2->group_modes);
-#endif
-
- g_clear_handle_id (&device_xi2->inhibit_pointer_query_timer, g_source_remove);
-
- G_OBJECT_CLASS (meta_input_device_x11_parent_class)->finalize (object);
-}
-
-static void
-meta_input_device_x11_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- MetaInputDeviceX11 *device_x11 = META_INPUT_DEVICE_X11 (object);
-
- switch (prop_id)
- {
- case PROP_ID:
- device_x11->device_id = g_value_get_int (value);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- }
-}
-
-static void
-meta_input_device_x11_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- MetaInputDeviceX11 *device_x11 = META_INPUT_DEVICE_X11 (object);
-
- switch (prop_id)
- {
- case PROP_ID:
- g_value_set_int (value, device_x11->device_id);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- }
-}
-
-static int
-meta_input_device_x11_get_group_n_modes (ClutterInputDevice *device,
- int group)
-{
-#ifdef HAVE_LIBWACOM
- WacomDevice *wacom_device;
-
- wacom_device = meta_input_device_get_wacom_device (META_INPUT_DEVICE (device));
-
- if (wacom_device)
- {
- if (group == 0)
- {
- if (libwacom_has_ring (wacom_device))
- return libwacom_get_ring_num_modes (wacom_device);
- else if (libwacom_get_num_strips (wacom_device) >= 1)
- return libwacom_get_strips_num_modes (wacom_device);
- }
- else if (group == 1)
- {
- if (libwacom_has_ring2 (wacom_device))
- return libwacom_get_ring2_num_modes (wacom_device);
- else if (libwacom_get_num_strips (wacom_device) >= 2)
- return libwacom_get_strips_num_modes (wacom_device);
- }
- }
-#endif
-
- return -1;
-}
-
-#ifdef HAVE_LIBWACOM
-static int
-meta_input_device_x11_get_button_group (ClutterInputDevice *device,
- uint32_t button)
-{
- WacomDevice *wacom_device;
-
- wacom_device = meta_input_device_get_wacom_device (META_INPUT_DEVICE (device));
-
- if (wacom_device)
- {
- WacomButtonFlags flags;
-
- if (button >= libwacom_get_num_buttons (wacom_device))
- return -1;
-
- flags = libwacom_get_button_flag (wacom_device, 'A' + button);
-
- if (flags &
- (WACOM_BUTTON_RING_MODESWITCH |
- WACOM_BUTTON_TOUCHSTRIP_MODESWITCH))
- return 0;
- if (flags &
- (WACOM_BUTTON_RING2_MODESWITCH |
- WACOM_BUTTON_TOUCHSTRIP2_MODESWITCH))
- return 1;
- }
-
- return -1;
-}
-#endif
-
-static gboolean
-meta_input_device_x11_is_mode_switch_button (ClutterInputDevice *device,
- uint32_t group,
- uint32_t button)
-{
- int button_group = -1;
-
-#ifdef HAVE_LIBWACOM
- button_group = meta_input_device_x11_get_button_group (device, button);
-#endif
-
- return button_group == (int) group;
-}
-
-static void
-meta_input_device_x11_class_init (MetaInputDeviceX11Class *klass)
-{
- GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
- ClutterInputDeviceClass *device_class = CLUTTER_INPUT_DEVICE_CLASS (klass);
-
- gobject_class->constructed = meta_input_device_x11_constructed;
- gobject_class->finalize = meta_input_device_x11_finalize;
- gobject_class->set_property = meta_input_device_x11_set_property;
- gobject_class->get_property = meta_input_device_x11_get_property;
-
- device_class->is_grouped = meta_input_device_x11_is_grouped;
- device_class->get_group_n_modes = meta_input_device_x11_get_group_n_modes;
- device_class->is_mode_switch_button = meta_input_device_x11_is_mode_switch_button;
-
- props[PROP_ID] =
- g_param_spec_int ("id",
- "Id",
- "Unique identifier of the device",
- -1, G_MAXINT,
- 0,
- CLUTTER_PARAM_READWRITE |
- G_PARAM_CONSTRUCT_ONLY);
-
- g_object_class_install_properties (gobject_class, N_PROPS, props);
-}
-
-static void
-meta_input_device_x11_init (MetaInputDeviceX11 *self)
-{
-}
-
-static ClutterModifierType
-get_modifier_for_button (int i)
-{
- switch (i)
- {
- case 1:
- return CLUTTER_BUTTON1_MASK;
- case 2:
- return CLUTTER_BUTTON2_MASK;
- case 3:
- return CLUTTER_BUTTON3_MASK;
- case 4:
- return CLUTTER_BUTTON4_MASK;
- case 5:
- return CLUTTER_BUTTON5_MASK;
- default:
- return 0;
- }
-}
-
-void
-meta_input_device_x11_translate_state (ClutterEvent *event,
- XIModifierState *modifiers_state,
- XIButtonState *buttons_state,
- XIGroupState *group_state)
-{
- uint32_t button = 0;
- uint32_t base = 0;
- uint32_t latched = 0;
- uint32_t locked = 0;
- uint32_t effective;
-
- if (modifiers_state)
- {
- base = (uint32_t) modifiers_state->base;
- latched = (uint32_t) modifiers_state->latched;
- locked = (uint32_t) modifiers_state->locked;
- }
-
- if (buttons_state)
- {
- int len, i;
-
- len = MIN (N_BUTTONS, buttons_state->mask_len * 8);
-
- for (i = 0; i < len; i++)
- {
- if (!XIMaskIsSet (buttons_state->mask, i))
- continue;
-
- button |= get_modifier_for_button (i);
- }
- }
-
- /* The XIButtonState sent in the event specifies the
- * state of the buttons before the event. In order to
- * get the current state of the buttons, we need to
- * filter out the current button.
- */
- switch (event->type)
- {
- case CLUTTER_BUTTON_PRESS:
- button |= (get_modifier_for_button (event->button.button));
- break;
- case CLUTTER_BUTTON_RELEASE:
- button &= ~(get_modifier_for_button (event->button.button));
- break;
- default:
- break;
- }
-
- effective = button | base | latched | locked;
- if (group_state)
- effective |= (group_state->effective) << 13;
-
- _clutter_event_set_state_full (event, button, base, latched, locked, effective);
-}
-
-void
-meta_input_device_x11_update_tool (ClutterInputDevice *device,
- ClutterInputDeviceTool *tool)
-{
- MetaInputDeviceX11 *device_xi2 = META_INPUT_DEVICE_X11 (device);
- g_set_object (&device_xi2->current_tool, tool);
-}
-
-ClutterInputDeviceTool *
-meta_input_device_x11_get_current_tool (ClutterInputDevice *device)
-{
- MetaInputDeviceX11 *device_xi2 = META_INPUT_DEVICE_X11 (device);
- return device_xi2->current_tool;
-}
-
-static gboolean
-meta_input_device_x11_query_pointer_location (MetaInputDeviceX11 *device_xi2)
-{
- Window xroot_window, xchild_window;
- double xroot_x, xroot_y, xwin_x, xwin_y;
- XIButtonState button_state = { 0 };
- XIModifierState mod_state;
- XIGroupState group_state;
- int result;
-
- meta_clutter_x11_trap_x_errors ();
- result = XIQueryPointer (meta_clutter_x11_get_default_display (),
- device_xi2->device_id,
- meta_clutter_x11_get_root_window (),
- &xroot_window,
- &xchild_window,
- &xroot_x, &xroot_y,
- &xwin_x, &xwin_y,
- &button_state,
- &mod_state,
- &group_state);
- meta_clutter_x11_untrap_x_errors ();
-
- g_free (button_state.mask);
-
- if (!result)
- return FALSE;
-
- device_xi2->current_x = (float) xroot_x;
- device_xi2->current_y = (float) xroot_y;
-
- return TRUE;
-}
-
-static gboolean
-clear_inhibit_pointer_query_cb (gpointer data)
-{
- MetaInputDeviceX11 *device_xi2 = META_INPUT_DEVICE_X11 (data);
-
- device_xi2->inhibit_pointer_query_timer = 0;
-
- return G_SOURCE_REMOVE;
-}
-
-gboolean
-meta_input_device_x11_get_pointer_location (ClutterInputDevice *device,
- float *x,
- float *y)
-
-{
- MetaInputDeviceX11 *device_xi2 = META_INPUT_DEVICE_X11 (device);
-
- g_return_val_if_fail (META_IS_INPUT_DEVICE_X11 (device), FALSE);
- g_return_val_if_fail (clutter_input_device_get_device_type (device) ==
- CLUTTER_POINTER_DEVICE, FALSE);
-
- /* Throttle XServer queries and roundtrips using an idle timeout */
- if (device_xi2->inhibit_pointer_query_timer == 0)
- {
- device_xi2->query_status =
- meta_input_device_x11_query_pointer_location (device_xi2);
- device_xi2->inhibit_pointer_query_timer =
- clutter_threads_add_idle (clear_inhibit_pointer_query_cb, device_xi2);
- }
-
- *x = device_xi2->current_x;
- *y = device_xi2->current_y;
-
- return device_xi2->query_status;
-}
-
-int
-meta_input_device_x11_get_device_id (ClutterInputDevice *device)
-{
- MetaInputDeviceX11 *device_xi2 = META_INPUT_DEVICE_X11 (device);
-
- g_return_val_if_fail (META_IS_INPUT_DEVICE_X11 (device), 0);
-
- return device_xi2->device_id;
-}
-
-void
-meta_input_device_x11_reset_axes (ClutterInputDevice *device)
-{
- MetaInputDeviceX11 *device_x11 = META_INPUT_DEVICE_X11 (device);
-
- g_clear_pointer (&device_x11->axes, g_array_unref);
-}
-
-int
-meta_input_device_x11_add_axis (ClutterInputDevice *device,
- ClutterInputAxis axis,
- double minimum,
- double maximum,
- double resolution)
-{
- MetaInputDeviceX11 *device_x11 = META_INPUT_DEVICE_X11 (device);
- MetaX11AxisInfo info;
- guint pos;
-
- if (device_x11->axes == NULL)
- device_x11->axes = g_array_new (FALSE, TRUE, sizeof (MetaX11AxisInfo));
-
- info.axis = axis;
- info.min_value = minimum;
- info.max_value = maximum;
- info.resolution = resolution;
-
- switch (axis)
- {
- case CLUTTER_INPUT_AXIS_X:
- case CLUTTER_INPUT_AXIS_Y:
- info.min_axis = 0;
- info.max_axis = 0;
- break;
-
- case CLUTTER_INPUT_AXIS_XTILT:
- case CLUTTER_INPUT_AXIS_YTILT:
- info.min_axis = -1;
- info.max_axis = 1;
- break;
-
- default:
- info.min_axis = 0;
- info.max_axis = 1;
- break;
- }
-
- g_array_append_val (device_x11->axes, info);
- pos = device_x11->axes->len - 1;
-
- return pos;
-}
-
-gboolean
-meta_input_device_x11_get_axis (ClutterInputDevice *device,
- int idx,
- ClutterInputAxis *use)
-{
- MetaInputDeviceX11 *device_x11 = META_INPUT_DEVICE_X11 (device);
- MetaX11AxisInfo *info;
-
- if (device_x11->axes == NULL)
- return FALSE;
-
- if (idx < 0 || idx >= device_x11->axes->len)
- return FALSE;
-
- info = &g_array_index (device_x11->axes, MetaX11AxisInfo, idx);
-
- if (use)
- *use = info->axis;
-
- return TRUE;
-}
-
-gboolean
-meta_input_device_x11_translate_axis (ClutterInputDevice *device,
- int idx,
- double value,
- double *axis_value)
-{
- MetaInputDeviceX11 *device_x11 = META_INPUT_DEVICE_X11 (device);
- MetaX11AxisInfo *info;
- double width;
- double real_value;
-
- if (device_x11->axes == NULL || idx < 0 || idx >= device_x11->axes->len)
- return FALSE;
-
- info = &g_array_index (device_x11->axes, MetaX11AxisInfo, idx);
-
- if (info->axis == CLUTTER_INPUT_AXIS_X ||
- info->axis == CLUTTER_INPUT_AXIS_Y)
- return FALSE;
-
- if (fabs (info->max_value - info->min_value) < 0.0000001)
- return FALSE;
-
- width = info->max_value - info->min_value;
- real_value = (info->max_axis * (value - info->min_value)
- + info->min_axis * (info->max_value - value))
- / width;
-
- if (axis_value)
- *axis_value = real_value;
-
- return TRUE;
-}
-
-int
-meta_input_device_x11_get_n_axes (ClutterInputDevice *device)
-{
- MetaInputDeviceX11 *device_x11 = META_INPUT_DEVICE_X11 (device);
-
- return device_x11->axes->len;
-}
-
-void
-meta_input_device_x11_add_scroll_info (ClutterInputDevice *device,
- int idx,
- ClutterScrollDirection direction,
- double increment)
-{
- MetaInputDeviceX11 *device_x11 = META_INPUT_DEVICE_X11 (device);
- MetaX11ScrollInfo info;
-
- g_return_if_fail (CLUTTER_IS_INPUT_DEVICE (device));
-
- info.axis_id = idx;
- info.direction = direction;
- info.increment = increment;
- info.last_value_valid = FALSE;
-
- if (device_x11->scroll_info == NULL)
- {
- device_x11->scroll_info = g_array_new (FALSE,
- FALSE,
- sizeof (MetaX11ScrollInfo));
- }
-
- g_array_append_val (device_x11->scroll_info, info);
-}
-
-gboolean
-meta_input_device_x11_get_scroll_delta (ClutterInputDevice *device,
- int idx,
- double value,
- ClutterScrollDirection *direction_p,
- double *delta_p)
-{
- MetaInputDeviceX11 *device_x11 = META_INPUT_DEVICE_X11 (device);
- int i;
-
- if (device_x11->scroll_info == NULL)
- return FALSE;
-
- for (i = 0; i < device_x11->scroll_info->len; i++)
- {
- MetaX11ScrollInfo *info = &g_array_index (device_x11->scroll_info,
- MetaX11ScrollInfo,
- i);
-
- if (info->axis_id == idx)
- {
- if (direction_p != NULL)
- *direction_p = info->direction;
-
- if (delta_p != NULL)
- *delta_p = 0.0;
-
- if (info->last_value_valid)
- {
- if (delta_p != NULL)
- {
- *delta_p = (value - info->last_value)
- / info->increment;
- }
-
- info->last_value = value;
- }
- else
- {
- info->last_value = value;
- info->last_value_valid = TRUE;
- }
-
- return TRUE;
- }
- }
-
- return FALSE;
-}
-
-void
-meta_input_device_x11_reset_scroll_info (ClutterInputDevice *device)
-{
- MetaInputDeviceX11 *device_x11 = META_INPUT_DEVICE_X11 (device);
- int i;
-
- if (device_x11->scroll_info == NULL)
- return;
-
- for (i = 0; i < device_x11->scroll_info->len; i++)
- {
- MetaX11ScrollInfo *info = &g_array_index (device_x11->scroll_info,
- MetaX11ScrollInfo,
- i);
-
- info->last_value_valid = FALSE;
- }
-}
-
-#ifdef HAVE_LIBWACOM
-uint32_t
-meta_input_device_x11_get_pad_group_mode (ClutterInputDevice *device,
- uint32_t group)
-{
- MetaInputDeviceX11 *device_xi2 = META_INPUT_DEVICE_X11 (device);
-
- if (group >= device_xi2->group_modes->len)
- return 0;
-
- return g_array_index (device_xi2->group_modes, uint32_t, group);
-}
-
-static gboolean
-pad_switch_mode (ClutterInputDevice *device,
- uint32_t button,
- uint32_t group,
- uint32_t *mode)
-{
- MetaInputDeviceX11 *device_x11 = META_INPUT_DEVICE_X11 (device);
- uint32_t n_buttons, n_modes, button_group, next_mode, i;
- WacomDevice *wacom_device;
- GList *switch_buttons = NULL;
-
- wacom_device =
- meta_input_device_get_wacom_device (META_INPUT_DEVICE (device));
- n_buttons = libwacom_get_num_buttons (wacom_device);
-
- for (i = 0; i < n_buttons; i++)
- {
- button_group = meta_input_device_x11_get_button_group (device, i);
- if (button_group == group)
- switch_buttons = g_list_prepend (switch_buttons, GINT_TO_POINTER (button));
- }
-
- switch_buttons = g_list_reverse (switch_buttons);
- n_modes = clutter_input_device_get_group_n_modes (device, group);
-
- if (g_list_length (switch_buttons) > 1)
- {
- /* If there's multiple switch buttons, we don't toggle but assign a mode
- * to each of those buttons.
- */
- next_mode = g_list_index (switch_buttons, GINT_TO_POINTER (button));
- }
- else if (switch_buttons)
- {
- uint32_t cur_mode;
-
- /* If there is a single button, have it toggle across modes */
- cur_mode = g_array_index (device_x11->group_modes, uint32_t, group);
- next_mode = (cur_mode + 1) % n_modes;
- }
- else
- {
- return FALSE;
- }
-
- g_list_free (switch_buttons);
-
- if (next_mode < 0 || next_mode > n_modes)
- return FALSE;
-
- *mode = next_mode;
- return TRUE;
-}
-
-void
-meta_input_device_x11_update_pad_state (ClutterInputDevice *device,
- uint32_t button,
- uint32_t state,
- uint32_t *group,
- uint32_t *mode)
-{
- MetaInputDeviceX11 *device_xi2 = META_INPUT_DEVICE_X11 (device);
- uint32_t button_group, *group_mode;
-
- button_group = meta_input_device_x11_get_button_group (device, button);
-
- if (button_group < 0 || button_group >= device_xi2->group_modes->len)
- {
- if (group)
- *group = 0;
- if (mode)
- *mode = 0;
- return;
- }
-
- group_mode = &g_array_index (device_xi2->group_modes, uint32_t, button_group);
-
- if (state)
- {
- uint32_t next_mode;
-
- if (pad_switch_mode (device, button, button_group, &next_mode))
- *group_mode = next_mode;
- }
-
- if (group)
- *group = button_group;
- if (mode)
- *mode = *group_mode;
-}
-#endif
diff --git a/src/backends/x11/meta-input-device-x11.h b/src/backends/x11/meta-input-device-x11.h
deleted file mode 100644
index 66e03f581..000000000
--- a/src/backends/x11/meta-input-device-x11.h
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- * Copyright © 2011 Intel Corp.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
- *
- * Author: Emmanuele Bassi <ebassi@linux.intel.com>
- */
-
-#ifndef META_INPUT_DEVICE_X11_H
-#define META_INPUT_DEVICE_X11_H
-
-#include <X11/extensions/XInput2.h>
-
-#ifdef HAVE_LIBWACOM
-#include <libwacom/libwacom.h>
-#endif
-
-#include "backends/meta-input-device-private.h"
-#include "clutter/clutter.h"
-
-G_BEGIN_DECLS
-
-#define META_TYPE_INPUT_DEVICE_X11 (meta_input_device_x11_get_type ())
-#define META_INPUT_DEVICE_X11(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), META_TYPE_INPUT_DEVICE_X11, MetaInputDeviceX11))
-#define META_IS_INPUT_DEVICE_X11(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), META_TYPE_INPUT_DEVICE_X11))
-#define META_INPUT_DEVICE_X11_CLASS(c) (G_TYPE_CHECK_CLASS_CAST ((c), META_TYPE_INPUT_DEVICE_X11, MetaInputDeviceX11Class))
-#define META_IS_INPUT_DEVICE_X11_CLASS(c) (G_TYPE_CHECK_CLASS_TYPE ((c), META_TYPE_INPUT_DEVICE_X11))
-#define META_INPUT_DEVICE_X11_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), META_TYPE_INPUT_DEVICE_X11, MetaInputDeviceX11Class))
-
-typedef struct _MetaInputDeviceX11 MetaInputDeviceX11;
-typedef struct _MetaInputDeviceX11Class MetaInputDeviceX11Class;
-
-GType meta_input_device_x11_get_type (void) G_GNUC_CONST;
-
-void meta_input_device_x11_translate_state (ClutterEvent *event,
- XIModifierState *modifiers_state,
- XIButtonState *buttons_state,
- XIGroupState *group_state);
-void meta_input_device_x11_update_tool (ClutterInputDevice *device,
- ClutterInputDeviceTool *tool);
-ClutterInputDeviceTool * meta_input_device_x11_get_current_tool (ClutterInputDevice *device);
-
-#ifdef HAVE_LIBWACOM
-void meta_input_device_x11_ensure_wacom_info (ClutterInputDevice *device,
- WacomDeviceDatabase *wacom_db);
-
-uint32_t meta_input_device_x11_get_pad_group_mode (ClutterInputDevice *device,
- uint32_t group);
-
-void meta_input_device_x11_update_pad_state (ClutterInputDevice *device,
- uint32_t button,
- uint32_t state,
- uint32_t *group,
- uint32_t *mode);
-
-#endif
-
-gboolean meta_input_device_x11_get_pointer_location (ClutterInputDevice *device,
- float *x,
- float *y);
-int meta_input_device_x11_get_device_id (ClutterInputDevice *device);
-
-int meta_input_device_x11_get_n_axes (ClutterInputDevice *device);
-void meta_input_device_x11_reset_axes (ClutterInputDevice *device);
-int meta_input_device_x11_add_axis (ClutterInputDevice *device,
- ClutterInputAxis axis,
- double minimum,
- double maximum,
- double resolution);
-gboolean meta_input_device_x11_get_axis (ClutterInputDevice *device,
- int idx,
- ClutterInputAxis *use);
-gboolean meta_input_device_x11_translate_axis (ClutterInputDevice *device,
- int idx,
- double value,
- double *axis_value);
-
-void meta_input_device_x11_add_scroll_info (ClutterInputDevice *device,
- int idx,
- ClutterScrollDirection direction,
- double increment);
-gboolean meta_input_device_x11_get_scroll_delta (ClutterInputDevice *device,
- int idx,
- gdouble value,
- ClutterScrollDirection *direction_p,
- double *delta_p);
-void meta_input_device_x11_reset_scroll_info (ClutterInputDevice *device);
-
-G_END_DECLS
-
-#endif /* META_INPUT_DEVICE_X11_H */
diff --git a/src/backends/x11/meta-input-settings-x11.c b/src/backends/x11/meta-input-settings-x11.c
deleted file mode 100644
index 26048f803..000000000
--- a/src/backends/x11/meta-input-settings-x11.c
+++ /dev/null
@@ -1,948 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2014 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Author: Carlos Garnacho <carlosg@gnome.org>
- */
-
-#include "config.h"
-
-#include "backends/x11/meta-input-settings-x11.h"
-
-#include <gdk/gdkx.h>
-#include <string.h>
-#include <X11/Xatom.h>
-#include <X11/extensions/XInput2.h>
-#include <X11/XKBlib.h>
-
-#ifdef HAVE_LIBGUDEV
-#include <gudev/gudev.h>
-#endif
-
-#include "backends/x11/meta-backend-x11.h"
-#include "backends/x11/meta-input-device-x11.h"
-#include "core/display-private.h"
-#include "meta/meta-x11-errors.h"
-
-typedef struct _MetaInputSettingsX11Private
-{
-#ifdef HAVE_LIBGUDEV
- GUdevClient *udev_client;
-#endif
-} MetaInputSettingsX11Private;
-
-G_DEFINE_TYPE_WITH_PRIVATE (MetaInputSettingsX11, meta_input_settings_x11,
- META_TYPE_INPUT_SETTINGS)
-
-typedef enum
-{
- SCROLL_METHOD_FIELD_2FG,
- SCROLL_METHOD_FIELD_EDGE,
- SCROLL_METHOD_FIELD_BUTTON,
- SCROLL_METHOD_NUM_FIELDS
-} ScrollMethod;
-
-static void
-device_free_xdevice (gpointer user_data)
-{
- MetaDisplay *display = meta_get_display ();
- MetaBackend *backend = meta_get_backend ();
- Display *xdisplay = meta_backend_x11_get_xdisplay (META_BACKEND_X11 (backend));
- XDevice *xdev = user_data;
-
- meta_x11_error_trap_push (display->x11_display);
- XCloseDevice (xdisplay, xdev);
- meta_x11_error_trap_pop (display->x11_display);
-}
-
-static XDevice *
-device_ensure_xdevice (ClutterInputDevice *device)
-{
- MetaDisplay *display = meta_get_display ();
- MetaBackend *backend = meta_get_backend ();
- Display *xdisplay = meta_backend_x11_get_xdisplay (META_BACKEND_X11 (backend));
- int device_id = meta_input_device_x11_get_device_id (device);
- XDevice *xdev = NULL;
-
- xdev = g_object_get_data (G_OBJECT (device), "meta-input-settings-xdevice");
- if (xdev)
- return xdev;
-
- meta_x11_error_trap_push (display->x11_display);
- xdev = XOpenDevice (xdisplay, device_id);
- meta_x11_error_trap_pop (display->x11_display);
-
- if (xdev)
- {
- g_object_set_data_full (G_OBJECT (device),
- "meta-input-settings-xdevice",
- xdev, device_free_xdevice);
- }
-
- return xdev;
-}
-
-static void *
-get_property (ClutterInputDevice *device,
- const gchar *property,
- Atom type,
- int format,
- gulong nitems)
-{
- MetaBackend *backend = meta_get_backend ();
- Display *xdisplay = meta_backend_x11_get_xdisplay (META_BACKEND_X11 (backend));
- gulong nitems_ret, bytes_after_ret;
- int rc, device_id, format_ret;
- Atom property_atom, type_ret;
- guchar *data_ret = NULL;
-
- property_atom = XInternAtom (xdisplay, property, True);
- if (!property_atom)
- return NULL;
-
- device_id = meta_input_device_x11_get_device_id (device);
-
- meta_clutter_x11_trap_x_errors ();
- rc = XIGetProperty (xdisplay, device_id, property_atom,
- 0, 10, False, type, &type_ret, &format_ret,
- &nitems_ret, &bytes_after_ret, &data_ret);
- meta_clutter_x11_untrap_x_errors ();
-
- if (rc == Success && type_ret == type && format_ret == format && nitems_ret >= nitems)
- {
- if (nitems_ret > nitems)
- g_warning ("Property '%s' for device '%s' returned %lu items, expected %lu",
- property, clutter_input_device_get_device_name (device), nitems_ret, nitems);
- return data_ret;
- }
-
- meta_XFree (data_ret);
- return NULL;
-}
-
-static void
-change_property (ClutterInputDevice *device,
- const gchar *property,
- Atom type,
- int format,
- void *data,
- gulong nitems)
-{
- MetaBackend *backend = meta_get_backend ();
- Display *xdisplay = meta_backend_x11_get_xdisplay (META_BACKEND_X11 (backend));
- int device_id;
- Atom property_atom;
- guchar *data_ret;
-
- property_atom = XInternAtom (xdisplay, property, True);
- if (!property_atom)
- return;
-
- device_id = meta_input_device_x11_get_device_id (device);
-
- data_ret = get_property (device, property, type, format, nitems);
- if (!data_ret)
- return;
-
- XIChangeProperty (xdisplay, device_id, property_atom, type,
- format, XIPropModeReplace, data, nitems);
- meta_XFree (data_ret);
-}
-
-static void
-meta_input_settings_x11_set_send_events (MetaInputSettings *settings,
- ClutterInputDevice *device,
- GDesktopDeviceSendEvents mode)
-{
- guchar values[2] = { 0 }; /* disabled, disabled-on-external-mouse */
- guchar *available;
-
- available = get_property (device, "libinput Send Events Modes Available",
- XA_INTEGER, 8, 2);
- if (!available)
- return;
-
- switch (mode)
- {
- case G_DESKTOP_DEVICE_SEND_EVENTS_DISABLED:
- values[0] = 1;
- break;
- case G_DESKTOP_DEVICE_SEND_EVENTS_DISABLED_ON_EXTERNAL_MOUSE:
- values[1] = 1;
- break;
- default:
- break;
- }
-
- if ((values[0] && !available[0]) || (values[1] && !available[1]))
- g_warning ("Device '%s' does not support sendevents mode %d",
- clutter_input_device_get_device_name (device), mode);
- else
- change_property (device, "libinput Send Events Mode Enabled",
- XA_INTEGER, 8, &values, 2);
-
- meta_XFree (available);
-}
-
-static void
-meta_input_settings_x11_set_matrix (MetaInputSettings *settings,
- ClutterInputDevice *device,
- const float matrix[6])
-{
- MetaBackend *backend = meta_get_backend ();
- Display *xdisplay = meta_backend_x11_get_xdisplay (META_BACKEND_X11 (backend));
- gfloat full_matrix[9] = { matrix[0], matrix[1], matrix[2],
- matrix[3], matrix[4], matrix[5],
- 0, 0, 1 };
-
- change_property (device, "Coordinate Transformation Matrix",
- XInternAtom (xdisplay, "FLOAT", False),
- 32, &full_matrix, 9);
-}
-
-static void
-meta_input_settings_x11_set_speed (MetaInputSettings *settings,
- ClutterInputDevice *device,
- gdouble speed)
-{
- MetaBackend *backend = meta_get_backend ();
- Display *xdisplay = meta_backend_x11_get_xdisplay (META_BACKEND_X11 (backend));
- gfloat value = speed;
-
- change_property (device, "libinput Accel Speed",
- XInternAtom (xdisplay, "FLOAT", False),
- 32, &value, 1);
-}
-
-static void
-meta_input_settings_x11_set_left_handed (MetaInputSettings *settings,
- ClutterInputDevice *device,
- gboolean enabled)
-{
- ClutterInputDeviceType device_type;
- guchar value;
-
- device_type = clutter_input_device_get_device_type (device);
-
- if (device_type == CLUTTER_TABLET_DEVICE ||
- device_type == CLUTTER_PEN_DEVICE ||
- device_type == CLUTTER_ERASER_DEVICE)
- {
- value = enabled ? 3 : 0;
- change_property (device, "Wacom Rotation",
- XA_INTEGER, 8, &value, 1);
- }
- else
- {
- value = enabled ? 1 : 0;
- change_property (device, "libinput Left Handed Enabled",
- XA_INTEGER, 8, &value, 1);
- }
-}
-
-static void
-meta_input_settings_x11_set_disable_while_typing (MetaInputSettings *settings,
- ClutterInputDevice *device,
- gboolean enabled)
-{
- guchar value = (enabled) ? 1 : 0;
-
- change_property (device, "libinput Disable While Typing Enabled",
- XA_INTEGER, 8, &value, 1);
-}
-
-static void
-meta_input_settings_x11_set_tap_enabled (MetaInputSettings *settings,
- ClutterInputDevice *device,
- gboolean enabled)
-{
- guchar value = (enabled) ? 1 : 0;
-
- change_property (device, "libinput Tapping Enabled",
- XA_INTEGER, 8, &value, 1);
-}
-
-static void
-meta_input_settings_x11_set_tap_and_drag_enabled (MetaInputSettings *settings,
- ClutterInputDevice *device,
- gboolean enabled)
-{
- guchar value = (enabled) ? 1 : 0;
-
- change_property (device, "libinput Tapping Drag Enabled",
- XA_INTEGER, 8, &value, 1);
-}
-
-static void
-meta_input_settings_x11_set_tap_and_drag_lock_enabled (MetaInputSettings *settings,
- ClutterInputDevice *device,
- gboolean enabled)
-{
- guchar value = (enabled) ? 1 : 0;
-
- change_property (device, "libinput Tapping Drag Lock Enabled",
- XA_INTEGER, 8, &value, 1);
-}
-
-static void
-meta_input_settings_x11_set_invert_scroll (MetaInputSettings *settings,
- ClutterInputDevice *device,
- gboolean inverted)
-{
- guchar value = (inverted) ? 1 : 0;
-
- change_property (device, "libinput Natural Scrolling Enabled",
- XA_INTEGER, 8, &value, 1);
-}
-
-static void
-change_scroll_method (ClutterInputDevice *device,
- ScrollMethod method,
- gboolean enabled)
-{
- guchar values[SCROLL_METHOD_NUM_FIELDS] = { 0 }; /* 2fg, edge, button. The last value is unused */
- guchar *current = NULL;
- guchar *available = NULL;
-
- available = get_property (device, "libinput Scroll Methods Available",
- XA_INTEGER, 8, SCROLL_METHOD_NUM_FIELDS);
- if (!available || !available[method])
- goto out;
-
- current = get_property (device, "libinput Scroll Method Enabled",
- XA_INTEGER, 8, SCROLL_METHOD_NUM_FIELDS);
- if (!current)
- goto out;
-
- memcpy (values, current, SCROLL_METHOD_NUM_FIELDS);
-
- values[method] = !!enabled;
- change_property (device, "libinput Scroll Method Enabled",
- XA_INTEGER, 8, &values, SCROLL_METHOD_NUM_FIELDS);
- out:
- meta_XFree (current);
- meta_XFree (available);
-}
-
-static void
-meta_input_settings_x11_set_edge_scroll (MetaInputSettings *settings,
- ClutterInputDevice *device,
- gboolean edge_scroll_enabled)
-{
- change_scroll_method (device, SCROLL_METHOD_FIELD_EDGE, edge_scroll_enabled);
-}
-
-static void
-meta_input_settings_x11_set_two_finger_scroll (MetaInputSettings *settings,
- ClutterInputDevice *device,
- gboolean two_finger_scroll_enabled)
-{
- change_scroll_method (device, SCROLL_METHOD_FIELD_2FG, two_finger_scroll_enabled);
-}
-
-static gboolean
-meta_input_settings_x11_has_two_finger_scroll (MetaInputSettings *settings,
- ClutterInputDevice *device)
-{
- guchar *available = NULL;
- gboolean has_two_finger = TRUE;
-
- available = get_property (device, "libinput Scroll Methods Available",
- XA_INTEGER, 8, SCROLL_METHOD_NUM_FIELDS);
- if (!available || !available[SCROLL_METHOD_FIELD_2FG])
- has_two_finger = FALSE;
-
- meta_XFree (available);
- return has_two_finger;
-}
-
-static void
-meta_input_settings_x11_set_scroll_button (MetaInputSettings *settings,
- ClutterInputDevice *device,
- guint button,
- gboolean button_lock)
-{
- gchar lock = button_lock;
-
- change_scroll_method (device, SCROLL_METHOD_FIELD_BUTTON, button != 0);
- change_property (device, "libinput Button Scrolling Button",
- XA_CARDINAL, 32, &button, 1);
- change_property (device, "libinput Button Scrolling Button Lock Enabled",
- XA_INTEGER, 8, &lock, 1);
-}
-
-static void
-meta_input_settings_x11_set_click_method (MetaInputSettings *settings,
- ClutterInputDevice *device,
- GDesktopTouchpadClickMethod mode)
-{
- guchar values[2] = { 0 }; /* buttonareas, clickfinger */
- guchar *defaults, *available;
-
- available = get_property (device, "libinput Click Methods Available",
- XA_INTEGER, 8, 2);
- if (!available)
- return;
-
- switch (mode)
- {
- case G_DESKTOP_TOUCHPAD_CLICK_METHOD_DEFAULT:
- defaults = get_property (device, "libinput Click Method Enabled Default",
- XA_INTEGER, 8, 2);
- if (!defaults)
- break;
- memcpy (values, defaults, 2);
- meta_XFree (defaults);
- break;
- case G_DESKTOP_TOUCHPAD_CLICK_METHOD_NONE:
- break;
- case G_DESKTOP_TOUCHPAD_CLICK_METHOD_AREAS:
- values[0] = 1;
- break;
- case G_DESKTOP_TOUCHPAD_CLICK_METHOD_FINGERS:
- values[1] = 1;
- break;
- default:
- g_assert_not_reached ();
- return;
- }
-
- if ((values[0] && !available[0]) || (values[1] && !available[1]))
- g_warning ("Device '%s' does not support click method %d",
- clutter_input_device_get_device_name (device), mode);
- else
- change_property (device, "libinput Click Method Enabled",
- XA_INTEGER, 8, &values, 2);
-
- meta_XFree(available);
-}
-
-static void
-meta_input_settings_x11_set_tap_button_map (MetaInputSettings *settings,
- ClutterInputDevice *device,
- GDesktopTouchpadTapButtonMap mode)
-{
- guchar values[2] = { 0 }; /* lrm, lmr */
- guchar *defaults;
-
- switch (mode)
- {
- case G_DESKTOP_TOUCHPAD_BUTTON_TAP_MAP_DEFAULT:
- defaults = get_property (device, "libinput Tapping Button Mapping Default",
- XA_INTEGER, 8, 2);
- if (!defaults)
- break;
- memcpy (values, defaults, 2);
- meta_XFree (defaults);
- break;
- case G_DESKTOP_TOUCHPAD_BUTTON_TAP_MAP_LRM:
- values[0] = 1;
- break;
- case G_DESKTOP_TOUCHPAD_BUTTON_TAP_MAP_LMR:
- values[1] = 1;
- break;
- default:
- g_assert_not_reached ();
- return;
- }
-
- if (values[0] || values[1])
- change_property (device, "libinput Tapping Button Mapping Enabled",
- XA_INTEGER, 8, &values, 2);
-}
-
-static void
-meta_input_settings_x11_set_keyboard_repeat (MetaInputSettings *settings,
- gboolean enabled,
- guint delay,
- guint interval)
-{
- MetaBackend *backend = meta_get_backend ();
- Display *xdisplay = meta_backend_x11_get_xdisplay (META_BACKEND_X11 (backend));
-
- if (enabled)
- {
- XAutoRepeatOn (xdisplay);
- XkbSetAutoRepeatRate (xdisplay, XkbUseCoreKbd, delay, interval);
- }
- else
- {
- XAutoRepeatOff (xdisplay);
- }
-}
-
-static gboolean
-has_udev_property (MetaInputSettings *settings,
- ClutterInputDevice *device,
- const char *property_name)
-{
-#ifdef HAVE_LIBGUDEV
- MetaInputSettingsX11 *settings_x11 = META_INPUT_SETTINGS_X11 (settings);
- MetaInputSettingsX11Private *priv =
- meta_input_settings_x11_get_instance_private (settings_x11);
- const char *device_node;
- GUdevDevice *udev_device = NULL;
- GUdevDevice *parent_udev_device = NULL;
-
- device_node = clutter_input_device_get_device_node (device);
- if (!device_node)
- return FALSE;
-
- udev_device = g_udev_client_query_by_device_file (priv->udev_client,
- device_node);
- if (!udev_device)
- return FALSE;
-
- if (NULL != g_udev_device_get_property (udev_device, property_name))
- {
- g_object_unref (udev_device);
- return TRUE;
- }
-
- parent_udev_device = g_udev_device_get_parent (udev_device);
- g_object_unref (udev_device);
-
- if (!parent_udev_device)
- return FALSE;
-
- if (NULL != g_udev_device_get_property (parent_udev_device, property_name))
- {
- g_object_unref (parent_udev_device);
- return TRUE;
- }
-
- g_object_unref (parent_udev_device);
- return FALSE;
-#else
- static gboolean warned_once = FALSE;
-
- if (!warned_once)
- {
- g_warning ("Failed to query property: no udev support");
- warned_once = TRUE;
- }
-
- return FALSE;
-#endif
-}
-
-static gboolean
-is_mouse (MetaInputSettings *settings,
- ClutterInputDevice *device)
-{
- return (has_udev_property (settings, device, "ID_INPUT_MOUSE") &&
- !has_udev_property (settings, device, "ID_INPUT_POINTINGSTICK"));
-}
-
-static gboolean
-meta_input_settings_x11_is_touchpad_device (MetaInputSettings *settings,
- ClutterInputDevice *device)
-{
- return has_udev_property (settings, device, "ID_INPUT_TOUCHPAD");
-}
-
-static gboolean
-meta_input_settings_x11_is_trackball_device (MetaInputSettings *settings,
- ClutterInputDevice *device)
-{
- return has_udev_property (settings, device, "ID_INPUT_TRACKBALL");
-}
-
-static void
-set_device_accel_profile (ClutterInputDevice *device,
- GDesktopPointerAccelProfile profile)
-{
- guchar *defaults, *available;
- guchar values[2] = { 0 }; /* adaptive, flat */
-
- defaults = get_property (device, "libinput Accel Profile Enabled Default",
- XA_INTEGER, 8, 2);
- if (!defaults)
- return;
-
- available = get_property (device, "libinput Accel Profiles Available",
- XA_INTEGER, 8, 2);
- if (!available)
- goto err_available;
-
- switch (profile)
- {
- case G_DESKTOP_POINTER_ACCEL_PROFILE_FLAT:
- values[0] = 0;
- values[1] = 1;
- break;
- case G_DESKTOP_POINTER_ACCEL_PROFILE_ADAPTIVE:
- values[0] = 1;
- values[1] = 0;
- break;
- default:
- g_warn_if_reached ();
- case G_DESKTOP_POINTER_ACCEL_PROFILE_DEFAULT:
- values[0] = defaults[0];
- values[1] = defaults[1];
- break;
- }
-
- change_property (device, "libinput Accel Profile Enabled",
- XA_INTEGER, 8, &values, 2);
-
- meta_XFree (available);
-
-err_available:
- meta_XFree (defaults);
-}
-
-static void
-meta_input_settings_x11_set_mouse_accel_profile (MetaInputSettings *settings,
- ClutterInputDevice *device,
- GDesktopPointerAccelProfile profile)
-{
- if (!is_mouse (settings, device))
- return;
-
- set_device_accel_profile (device, profile);
-}
-
-static void
-meta_input_settings_x11_set_trackball_accel_profile (MetaInputSettings *settings,
- ClutterInputDevice *device,
- GDesktopPointerAccelProfile profile)
-{
- if (!meta_input_settings_x11_is_trackball_device (settings, device))
- return;
-
- set_device_accel_profile (device, profile);
-}
-
-static void
-meta_input_settings_x11_set_tablet_mapping (MetaInputSettings *settings,
- ClutterInputDevice *device,
- GDesktopTabletMapping mapping)
-{
- MetaDisplay *display = meta_get_display ();
- MetaBackend *backend = meta_get_backend ();
- Display *xdisplay = meta_backend_x11_get_xdisplay (META_BACKEND_X11 (backend));
- XDevice *xdev;
-
- if (!display)
- return;
-
- /* Grab the puke bucket! */
- meta_x11_error_trap_push (display->x11_display);
- xdev = device_ensure_xdevice (device);
- if (xdev)
- {
- XSetDeviceMode (xdisplay, xdev,
- mapping == G_DESKTOP_TABLET_MAPPING_ABSOLUTE ?
- Absolute : Relative);
- }
-
- if (meta_x11_error_trap_pop_with_return (display->x11_display))
- {
- g_warning ("Could not set tablet mapping for %s",
- clutter_input_device_get_device_name (device));
- }
-}
-
-static gboolean
-device_query_area (ClutterInputDevice *device,
- gint *x,
- gint *y,
- gint *width,
- gint *height)
-{
- MetaBackend *backend = meta_get_backend ();
- Display *xdisplay = meta_backend_x11_get_xdisplay (META_BACKEND_X11 (backend));
- gint device_id, n_devices, i;
- XIDeviceInfo *info;
- Atom abs_x, abs_y;
-
- *width = *height = 0;
- device_id = meta_input_device_x11_get_device_id (device);
- info = XIQueryDevice (xdisplay, device_id, &n_devices);
- if (n_devices <= 0 || !info)
- return FALSE;
-
- abs_x = XInternAtom (xdisplay, "Abs X", True);
- abs_y = XInternAtom (xdisplay, "Abs Y", True);
-
- for (i = 0; i < info->num_classes; i++)
- {
- XIValuatorClassInfo *valuator = (XIValuatorClassInfo *) info->classes[i];
-
- if (valuator->type != XIValuatorClass)
- continue;
- if (valuator->label == abs_x)
- {
- *x = valuator->min;
- *width = valuator->max - valuator->min;
- }
- else if (valuator->label == abs_y)
- {
- *y = valuator->min;
- *height = valuator->max - valuator->min;
- }
- }
-
- XIFreeDeviceInfo (info);
- return TRUE;
-}
-
-static void
-update_tablet_area (MetaInputSettings *settings,
- ClutterInputDevice *device,
- gint32 *area)
-{
- change_property (device, "Wacom Tablet Area",
- XA_INTEGER, 32, area, 4);
-}
-
-static void
-meta_input_settings_x11_set_tablet_area (MetaInputSettings *settings,
- ClutterInputDevice *device,
- gdouble padding_left,
- gdouble padding_right,
- gdouble padding_top,
- gdouble padding_bottom)
-{
- gint32 x, y, width, height, area[4] = { 0 };
-
- if (!device_query_area (device, &x, &y, &width, &height))
- return;
-
- area[0] = (width * padding_left) + x;
- area[1] = (height * padding_top) + y;
- area[2] = width - (width * padding_right) + x;
- area[3] = height - (height * padding_bottom) + y;
- update_tablet_area (settings, device, area);
-}
-
-static void
-meta_input_settings_x11_set_tablet_aspect_ratio (MetaInputSettings *settings,
- ClutterInputDevice *device,
- gdouble aspect_ratio)
-{
- int32_t dev_x, dev_y, dev_width, dev_height, area[4] = { 0 };
-
- if (!device_query_area (device, &dev_x, &dev_y, &dev_width, &dev_height))
- return;
-
- if (aspect_ratio > 0)
- {
- double dev_aspect;
-
- dev_aspect = (double) dev_width / dev_height;
-
- if (dev_aspect > aspect_ratio)
- dev_width = dev_height * aspect_ratio;
- else if (dev_aspect < aspect_ratio)
- dev_height = dev_width / aspect_ratio;
- }
-
- area[0] = dev_x;
- area[1] = dev_y;
- area[2] = dev_width + dev_x;
- area[3] = dev_height + dev_y;
- update_tablet_area (settings, device, area);
-}
-
-static void
-meta_input_settings_x11_dispose (GObject *object)
-{
-#ifdef HAVE_LIBGUDEV
- MetaInputSettingsX11 *settings_x11 = META_INPUT_SETTINGS_X11 (object);
- MetaInputSettingsX11Private *priv =
- meta_input_settings_x11_get_instance_private (settings_x11);
-
- g_clear_object (&priv->udev_client);
-#endif
-
- G_OBJECT_CLASS (meta_input_settings_x11_parent_class)->dispose (object);
-}
-
-static guint
-action_to_button (GDesktopStylusButtonAction action,
- guint button)
-{
- switch (action)
- {
- case G_DESKTOP_STYLUS_BUTTON_ACTION_MIDDLE:
- return CLUTTER_BUTTON_MIDDLE;
- case G_DESKTOP_STYLUS_BUTTON_ACTION_RIGHT:
- return CLUTTER_BUTTON_SECONDARY;
- case G_DESKTOP_STYLUS_BUTTON_ACTION_BACK:
- return 8;
- case G_DESKTOP_STYLUS_BUTTON_ACTION_FORWARD:
- return 9;
- case G_DESKTOP_STYLUS_BUTTON_ACTION_DEFAULT:
- default:
- return button;
- }
-}
-
-static void
-meta_input_settings_x11_set_stylus_button_map (MetaInputSettings *settings,
- ClutterInputDevice *device,
- ClutterInputDeviceTool *tool,
- GDesktopStylusButtonAction primary,
- GDesktopStylusButtonAction secondary,
- GDesktopStylusButtonAction tertiary)
-{
- MetaDisplay *display = meta_get_display ();
- MetaBackend *backend = meta_get_backend ();
- Display *xdisplay = meta_backend_x11_get_xdisplay (META_BACKEND_X11 (backend));
- XDevice *xdev;
-
- if (!display)
- return;
-
- /* Grab the puke bucket! */
- meta_x11_error_trap_push (display->x11_display);
- xdev = device_ensure_xdevice (device);
- if (xdev)
- {
- guchar map[8] = {
- CLUTTER_BUTTON_PRIMARY,
- action_to_button (primary, CLUTTER_BUTTON_MIDDLE),
- action_to_button (secondary, CLUTTER_BUTTON_SECONDARY),
- 4,
- 5,
- 6,
- 7,
- action_to_button (tertiary, 8), /* "Back" */
- };
-
- XSetDeviceButtonMapping (xdisplay, xdev, map, G_N_ELEMENTS (map));
- }
-
- if (meta_x11_error_trap_pop_with_return (display->x11_display))
- {
- g_warning ("Could not set stylus button map for %s",
- clutter_input_device_get_device_name (device));
- }
-}
-
-static void
-meta_input_settings_x11_set_mouse_middle_click_emulation (MetaInputSettings *settings,
- ClutterInputDevice *device,
- gboolean enabled)
-{
- guchar value = enabled ? 1 : 0;
-
- if (!is_mouse (settings, device))
- return;
-
- change_property (device, "libinput Middle Click Emulation Enabled",
- XA_INTEGER, 8, &value, 1);
-}
-
-static void
-meta_input_settings_x11_set_touchpad_middle_click_emulation (MetaInputSettings *settings,
- ClutterInputDevice *device,
- gboolean enabled)
-{
- guchar value = enabled ? 1 : 0;
-
- if (!meta_input_settings_x11_is_touchpad_device (settings, device))
- return;
-
- change_property (device, "libinput Middle Click Emulation Enabled",
- XA_INTEGER, 8, &value, 1);
-}
-
-static void
-meta_input_settings_x11_set_trackball_middle_click_emulation (MetaInputSettings *settings,
- ClutterInputDevice *device,
- gboolean enabled)
-{
- guchar value = enabled ? 1 : 0;
-
- if (!meta_input_settings_x11_is_trackball_device (settings, device))
- return;
-
- change_property (device, "libinput Middle Click Emulation Enabled",
- XA_INTEGER, 8, &value, 1);
-}
-
-static void
-meta_input_settings_x11_set_stylus_pressure (MetaInputSettings *settings,
- ClutterInputDevice *device,
- ClutterInputDeviceTool *tool,
- const gint32 pressure[4])
-{
- guint32 values[4] = { pressure[0], pressure[1], pressure[2], pressure[3] };
-
- change_property (device, "Wacom Pressurecurve", XA_INTEGER, 32,
- &values, G_N_ELEMENTS (values));
-}
-
-static void
-meta_input_settings_x11_class_init (MetaInputSettingsX11Class *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
- MetaInputSettingsClass *input_settings_class = META_INPUT_SETTINGS_CLASS (klass);
-
- object_class->dispose = meta_input_settings_x11_dispose;
-
- input_settings_class->set_send_events = meta_input_settings_x11_set_send_events;
- input_settings_class->set_matrix = meta_input_settings_x11_set_matrix;
- input_settings_class->set_speed = meta_input_settings_x11_set_speed;
- input_settings_class->set_left_handed = meta_input_settings_x11_set_left_handed;
- input_settings_class->set_tap_enabled = meta_input_settings_x11_set_tap_enabled;
- input_settings_class->set_tap_button_map = meta_input_settings_x11_set_tap_button_map;
- input_settings_class->set_tap_and_drag_enabled = meta_input_settings_x11_set_tap_and_drag_enabled;
- input_settings_class->set_tap_and_drag_lock_enabled =
- meta_input_settings_x11_set_tap_and_drag_lock_enabled;
- input_settings_class->set_disable_while_typing = meta_input_settings_x11_set_disable_while_typing;
- input_settings_class->set_invert_scroll = meta_input_settings_x11_set_invert_scroll;
- input_settings_class->set_edge_scroll = meta_input_settings_x11_set_edge_scroll;
- input_settings_class->set_two_finger_scroll = meta_input_settings_x11_set_two_finger_scroll;
- input_settings_class->set_scroll_button = meta_input_settings_x11_set_scroll_button;
- input_settings_class->set_click_method = meta_input_settings_x11_set_click_method;
- input_settings_class->set_keyboard_repeat = meta_input_settings_x11_set_keyboard_repeat;
-
- input_settings_class->set_tablet_mapping = meta_input_settings_x11_set_tablet_mapping;
- input_settings_class->set_tablet_aspect_ratio = meta_input_settings_x11_set_tablet_aspect_ratio;
- input_settings_class->set_tablet_area = meta_input_settings_x11_set_tablet_area;
-
- input_settings_class->set_mouse_accel_profile = meta_input_settings_x11_set_mouse_accel_profile;
- input_settings_class->set_trackball_accel_profile = meta_input_settings_x11_set_trackball_accel_profile;
-
- input_settings_class->set_stylus_pressure = meta_input_settings_x11_set_stylus_pressure;
- input_settings_class->set_stylus_button_map = meta_input_settings_x11_set_stylus_button_map;
-
- input_settings_class->set_mouse_middle_click_emulation = meta_input_settings_x11_set_mouse_middle_click_emulation;
- input_settings_class->set_touchpad_middle_click_emulation = meta_input_settings_x11_set_touchpad_middle_click_emulation;
- input_settings_class->set_trackball_middle_click_emulation = meta_input_settings_x11_set_trackball_middle_click_emulation;
-
- input_settings_class->has_two_finger_scroll = meta_input_settings_x11_has_two_finger_scroll;
- input_settings_class->is_trackball_device = meta_input_settings_x11_is_trackball_device;
-}
-
-static void
-meta_input_settings_x11_init (MetaInputSettingsX11 *settings)
-{
-#ifdef HAVE_LIBGUDEV
- MetaInputSettingsX11Private *priv =
- meta_input_settings_x11_get_instance_private (settings);
- const char *subsystems[] = { NULL };
-
- priv->udev_client = g_udev_client_new (subsystems);
-#endif
-}
diff --git a/src/backends/x11/meta-input-settings-x11.h b/src/backends/x11/meta-input-settings-x11.h
deleted file mode 100644
index 2780bb224..000000000
--- a/src/backends/x11/meta-input-settings-x11.h
+++ /dev/null
@@ -1,49 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright 2014 Red Hat, Inc.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, see <http://www.gnu.org/licenses/>.
- *
- * Author: Carlos Garnacho <carlosg@gnome.org>
- */
-
-#ifndef META_INPUT_SETTINGS_X11_H
-#define META_INPUT_SETTINGS_X11_H
-
-#include "backends/meta-input-settings-private.h"
-
-#define META_TYPE_INPUT_SETTINGS_X11 (meta_input_settings_x11_get_type ())
-#define META_INPUT_SETTINGS_X11(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), META_TYPE_INPUT_SETTINGS_X11, MetaInputSettingsX11))
-#define META_INPUT_SETTINGS_X11_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), META_TYPE_INPUT_SETTINGS_X11, MetaInputSettingsX11Class))
-#define META_IS_INPUT_SETTINGS_X11(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), META_TYPE_INPUT_SETTINGS_X11))
-#define META_IS_INPUT_SETTINGS_X11_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), META_TYPE_INPUT_SETTINGS_X11))
-#define META_INPUT_SETTINGS_X11_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), META_TYPE_INPUT_SETTINGS_X11, MetaInputSettingsX11Class))
-
-typedef struct _MetaInputSettingsX11 MetaInputSettingsX11;
-typedef struct _MetaInputSettingsX11Class MetaInputSettingsX11Class;
-
-struct _MetaInputSettingsX11
-{
- MetaInputSettings parent_instance;
-};
-
-struct _MetaInputSettingsX11Class
-{
- MetaInputSettingsClass parent_class;
-};
-
-GType meta_input_settings_x11_get_type (void) G_GNUC_CONST;
-
-#endif /* META_INPUT_SETTINGS_X11_H */
diff --git a/src/backends/x11/meta-keymap-x11.c b/src/backends/x11/meta-keymap-x11.c
deleted file mode 100644
index 994ad8594..000000000
--- a/src/backends/x11/meta-keymap-x11.c
+++ /dev/null
@@ -1,949 +0,0 @@
-/*
- * Clutter.
- *
- * An OpenGL based 'interactive canvas' library.
- *
- * Copyright (C) 2010 Intel Corp.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
- *
- * Author: Emmanuele Bassi <ebassi@linux.intel.com>
- */
-
-#include "config.h"
-
-#include <X11/Xatom.h>
-#include <X11/XKBlib.h>
-
-#include "backends/meta-backend-private.h"
-#include "backends/meta-input-settings-private.h"
-#include "backends/x11/meta-clutter-backend-x11.h"
-#include "backends/x11/meta-keymap-x11.h"
-#include "clutter/clutter.h"
-#include "clutter/clutter-keymap-private.h"
-#include "clutter/clutter-mutter.h"
-
-typedef struct _DirectionCacheEntry DirectionCacheEntry;
-typedef struct _ClutterKeymapKey ClutterKeymapKey;
-
-struct _ClutterKeymapKey
-{
- uint32_t keycode;
- uint32_t group;
- uint32_t level;
-};
-
-struct _DirectionCacheEntry
-{
- uint32_t serial;
- Atom group_atom;
- PangoDirection direction;
-};
-
-struct _MetaKeymapX11
-{
- ClutterKeymap parent_instance;
-
- ClutterBackend *backend;
-
- int min_keycode;
- int max_keycode;
-
- ClutterModifierType modmap[8];
-
- ClutterModifierType num_lock_mask;
- ClutterModifierType scroll_lock_mask;
- ClutterModifierType level3_shift_mask;
-
- PangoDirection current_direction;
-
- XkbDescPtr xkb_desc;
- int xkb_event_base;
- uint32_t xkb_map_serial;
- Atom current_group_atom;
- uint32_t current_cache_serial;
- DirectionCacheEntry group_direction_cache[4];
- int current_group;
-
- GHashTable *reserved_keycodes;
- GQueue *available_keycodes;
-
- uint32_t keymap_serial;
-
- uint32_t has_direction : 1;
-
- uint32_t use_xkb : 1;
- uint32_t have_xkb_autorepeat : 1;
-};
-
-enum
-{
- PROP_0,
-
- PROP_BACKEND,
-
- PROP_LAST
-};
-
-static GParamSpec *obj_props[PROP_LAST] = { NULL, };
-
-G_DEFINE_TYPE (MetaKeymapX11, meta_keymap_x11, CLUTTER_TYPE_KEYMAP)
-
-/* code adapted from gdk/x11/gdkkeys-x11.c - update_modmap */
-static void
-update_modmap (Display *display,
- MetaKeymapX11 *keymap_x11)
-{
- static struct {
- const char *name;
- Atom atom;
- ClutterModifierType mask;
- } vmods[] = {
- { "Meta", 0, CLUTTER_META_MASK },
- { "Super", 0, CLUTTER_SUPER_MASK },
- { "Hyper", 0, CLUTTER_HYPER_MASK },
- { NULL, 0, 0 }
- };
-
- int i, j, k;
-
- if (vmods[0].atom == 0)
- for (i = 0; vmods[i].name; i++)
- vmods[i].atom = XInternAtom (display, vmods[i].name, FALSE);
-
- for (i = 0; i < 8; i++)
- keymap_x11->modmap[i] = 1 << i;
-
- for (i = 0; i < XkbNumVirtualMods; i++)
- {
- for (j = 0; vmods[j].atom; j++)
- {
- if (keymap_x11->xkb_desc->names->vmods[i] == vmods[j].atom)
- {
- for (k = 0; k < 8; k++)
- {
- if (keymap_x11->xkb_desc->server->vmods[i] & (1 << k))
- keymap_x11->modmap[k] |= vmods[j].mask;
- }
- }
- }
- }
-}
-
-static XkbDescPtr
-get_xkb (MetaKeymapX11 *keymap_x11)
-{
- Display *xdisplay = meta_clutter_x11_get_default_display ();
-
- if (keymap_x11->max_keycode == 0)
- XDisplayKeycodes (xdisplay,
- &keymap_x11->min_keycode,
- &keymap_x11->max_keycode);
-
- if (keymap_x11->xkb_desc == NULL)
- {
- int flags = XkbKeySymsMask
- | XkbKeyTypesMask
- | XkbModifierMapMask
- | XkbVirtualModsMask;
-
- keymap_x11->xkb_desc = XkbGetMap (xdisplay, flags, XkbUseCoreKbd);
- if (G_UNLIKELY (keymap_x11->xkb_desc == NULL))
- {
- g_error ("Failed to get the keymap from XKB");
- return NULL;
- }
-
- flags = XkbGroupNamesMask | XkbVirtualModNamesMask;
- XkbGetNames (xdisplay, flags, keymap_x11->xkb_desc);
-
- update_modmap (xdisplay, keymap_x11);
- }
- else if (keymap_x11->xkb_map_serial != keymap_x11->keymap_serial)
- {
- int flags = XkbKeySymsMask
- | XkbKeyTypesMask
- | XkbModifierMapMask
- | XkbVirtualModsMask;
-
- XkbGetUpdatedMap (xdisplay, flags, keymap_x11->xkb_desc);
-
- flags = XkbGroupNamesMask | XkbVirtualModNamesMask;
- XkbGetNames (xdisplay, flags, keymap_x11->xkb_desc);
-
- update_modmap (xdisplay, keymap_x11);
-
- keymap_x11->xkb_map_serial = keymap_x11->keymap_serial;
- }
-
- if (keymap_x11->num_lock_mask == 0)
- keymap_x11->num_lock_mask = XkbKeysymToModifiers (xdisplay, XK_Num_Lock);
-
- if (keymap_x11->scroll_lock_mask == 0)
- keymap_x11->scroll_lock_mask = XkbKeysymToModifiers (xdisplay,
- XK_Scroll_Lock);
- if (keymap_x11->level3_shift_mask == 0)
- keymap_x11->level3_shift_mask = XkbKeysymToModifiers (xdisplay,
- XK_ISO_Level3_Shift);
-
- return keymap_x11->xkb_desc;
-}
-
-static void
-update_locked_mods (MetaKeymapX11 *keymap_x11,
- int locked_mods)
-{
- ClutterKeymap *keymap = CLUTTER_KEYMAP (keymap_x11);
- gboolean caps_lock_state;
- gboolean num_lock_state;
- gboolean old_num_lock_state;
-
- caps_lock_state = !!(locked_mods & CLUTTER_LOCK_MASK);
- num_lock_state = !!(locked_mods & keymap_x11->num_lock_mask);
-
- old_num_lock_state = clutter_keymap_get_num_lock_state (keymap);
- clutter_keymap_set_lock_modifier_state (CLUTTER_KEYMAP (keymap_x11),
- caps_lock_state,
- num_lock_state);
-
- if (num_lock_state != old_num_lock_state)
- {
- MetaBackend *backend;
- MetaInputSettings *input_settings;
-
- backend = meta_get_backend ();
- input_settings = meta_backend_get_input_settings (backend);
-
- if (input_settings)
- {
- meta_input_settings_maybe_save_numlock_state (input_settings,
- num_lock_state);
- }
- }
-}
-
-/* the code to retrieve the keymap direction and cache it
- * is taken from GDK:
- * gdk/x11/gdkkeys-x11.c
- */
-static PangoDirection
-get_direction (XkbDescPtr xkb,
- int group)
-{
- int rtl_minus_ltr = 0; /* total number of RTL keysyms minus LTR ones */
- int code;
-
- for (code = xkb->min_key_code;
- code <= xkb->max_key_code;
- code += 1)
- {
- int level = 0;
- KeySym sym = XkbKeySymEntry (xkb, code, level, group);
- PangoDirection dir =
- _clutter_pango_unichar_direction (clutter_keysym_to_unicode (sym));
-
- switch (dir)
- {
- case PANGO_DIRECTION_RTL:
- rtl_minus_ltr++;
- break;
-
- case PANGO_DIRECTION_LTR:
- rtl_minus_ltr--;
- break;
-
- default:
- break;
- }
- }
-
- if (rtl_minus_ltr > 0)
- return PANGO_DIRECTION_RTL;
-
- return PANGO_DIRECTION_LTR;
-}
-
-static PangoDirection
-get_direction_from_cache (MetaKeymapX11 *keymap_x11,
- XkbDescPtr xkb,
- int group)
-{
- Atom group_atom = xkb->names->groups[group];
- gboolean cache_hit = FALSE;
- DirectionCacheEntry *cache = keymap_x11->group_direction_cache;
- PangoDirection direction = PANGO_DIRECTION_NEUTRAL;
- int i;
-
- if (keymap_x11->has_direction)
- {
- /* look up in the cache */
- for (i = 0; i < G_N_ELEMENTS (keymap_x11->group_direction_cache); i++)
- {
- if (cache[i].group_atom == group_atom)
- {
- cache_hit = TRUE;
- cache[i].serial = keymap_x11->current_cache_serial++;
- direction = cache[i].direction;
- group_atom = cache[i].group_atom;
- break;
- }
- }
- }
- else
- {
- /* initialize the cache */
- for (i = 0; i < G_N_ELEMENTS (keymap_x11->group_direction_cache); i++)
- {
- cache[i].group_atom = 0;
- cache[i].direction = PANGO_DIRECTION_NEUTRAL;
- cache[i].serial = keymap_x11->current_cache_serial;
- }
-
- keymap_x11->current_cache_serial += 1;
- }
-
- /* insert the new entry in the cache */
- if (!cache_hit)
- {
- int oldest = 0;
-
- direction = get_direction (xkb, group);
-
- /* replace the oldest entry */
- for (i = 0; i < G_N_ELEMENTS (keymap_x11->group_direction_cache); i++)
- {
- if (cache[i].serial < cache[oldest].serial)
- oldest = i;
- }
-
- cache[oldest].group_atom = group_atom;
- cache[oldest].direction = direction;
- cache[oldest].serial = keymap_x11->current_cache_serial++;
- }
-
- return direction;
-}
-
-static void
-update_direction (MetaKeymapX11 *keymap_x11,
- int group)
-{
- XkbDescPtr xkb = get_xkb (keymap_x11);
- Atom group_atom;
-
- group_atom = xkb->names->groups[group];
-
- if (!keymap_x11->has_direction || keymap_x11->current_group_atom != group_atom)
- {
- keymap_x11->current_direction = get_direction_from_cache (keymap_x11, xkb, group);
- keymap_x11->current_group_atom = group_atom;
- keymap_x11->has_direction = TRUE;
- }
-}
-
-static void
-meta_keymap_x11_constructed (GObject *object)
-{
- MetaKeymapX11 *keymap_x11 = META_KEYMAP_X11 (object);
- Display *xdisplay = meta_clutter_x11_get_default_display ();
- int xkb_major = XkbMajorVersion;
- int xkb_minor = XkbMinorVersion;
-
- g_assert (keymap_x11->backend != NULL);
-
- if (XkbLibraryVersion (&xkb_major, &xkb_minor))
- {
- xkb_major = XkbMajorVersion;
- xkb_minor = XkbMinorVersion;
-
- if (XkbQueryExtension (xdisplay,
- NULL,
- &keymap_x11->xkb_event_base,
- NULL,
- &xkb_major, &xkb_minor))
- {
- Bool detectable_autorepeat_supported;
-
- keymap_x11->use_xkb = TRUE;
-
- XkbSelectEvents (xdisplay,
- XkbUseCoreKbd,
- XkbNewKeyboardNotifyMask | XkbMapNotifyMask | XkbStateNotifyMask,
- XkbNewKeyboardNotifyMask | XkbMapNotifyMask | XkbStateNotifyMask);
-
- XkbSelectEventDetails (xdisplay,
- XkbUseCoreKbd, XkbStateNotify,
- XkbAllStateComponentsMask,
- XkbGroupLockMask | XkbModifierLockMask);
-
- /* enable XKB autorepeat */
- XkbSetDetectableAutoRepeat (xdisplay,
- True,
- &detectable_autorepeat_supported);
-
- keymap_x11->have_xkb_autorepeat = detectable_autorepeat_supported;
- }
- }
-}
-
-static void
-meta_keymap_x11_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- MetaKeymapX11 *keymap = META_KEYMAP_X11 (object);
-
- switch (prop_id)
- {
- case PROP_BACKEND:
- keymap->backend = g_value_get_object (value);
- break;
-
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-
-static void
-meta_keymap_x11_refresh_reserved_keycodes (MetaKeymapX11 *keymap_x11)
-{
- Display *xdisplay = meta_clutter_x11_get_default_display ();
- GHashTableIter iter;
- gpointer key, value;
-
- g_hash_table_iter_init (&iter, keymap_x11->reserved_keycodes);
- while (g_hash_table_iter_next (&iter, &key, &value))
- {
- uint32_t reserved_keycode = GPOINTER_TO_UINT (key);
- uint32_t reserved_keysym = GPOINTER_TO_UINT (value);
- uint32_t actual_keysym = XkbKeycodeToKeysym (xdisplay, reserved_keycode, 0, 0);
-
- /* If an available keycode is no longer mapped to the stored keysym, then
- * the keycode should not be considered available anymore and should be
- * removed both from the list of available and reserved keycodes.
- */
- if (reserved_keysym != actual_keysym)
- {
- g_hash_table_iter_remove (&iter);
- g_queue_remove (keymap_x11->available_keycodes, key);
- }
- }
-}
-
-static gboolean
-meta_keymap_x11_replace_keycode (MetaKeymapX11 *keymap_x11,
- KeyCode keycode,
- KeySym keysym)
-{
- if (keymap_x11->use_xkb)
- {
- Display *xdisplay = meta_clutter_x11_get_default_display ();
- XkbDescPtr xkb = get_xkb (keymap_x11);
- XkbMapChangesRec changes;
-
- XFlush (xdisplay);
-
- xkb->device_spec = XkbUseCoreKbd;
- memset (&changes, 0, sizeof(changes));
-
- if (keysym != NoSymbol)
- {
- int types[XkbNumKbdGroups] = { XkbOneLevelIndex };
- XkbChangeTypesOfKey (xkb, keycode, 1, XkbGroup1Mask, types, &changes);
- XkbKeySymEntry (xkb, keycode, 0, 0) = keysym;
- }
- else
- {
- /* Reset to NoSymbol */
- XkbChangeTypesOfKey (xkb, keycode, 0, XkbGroup1Mask, NULL, &changes);
- }
-
- changes.changed = XkbKeySymsMask | XkbKeyTypesMask;
- changes.first_key_sym = keycode;
- changes.num_key_syms = 1;
- changes.first_type = 0;
- changes.num_types = xkb->map->num_types;
- XkbChangeMap (xdisplay, xkb, &changes);
-
- XFlush (xdisplay);
-
- return TRUE;
- }
-
- return FALSE;
-}
-
-static void
-meta_keymap_x11_finalize (GObject *object)
-{
- MetaKeymapX11 *keymap;
- GHashTableIter iter;
- gpointer key, value;
-
- keymap = META_KEYMAP_X11 (object);
-
- meta_keymap_x11_refresh_reserved_keycodes (keymap);
- g_hash_table_iter_init (&iter, keymap->reserved_keycodes);
- while (g_hash_table_iter_next (&iter, &key, &value))
- {
- uint32_t keycode = GPOINTER_TO_UINT (key);
- meta_keymap_x11_replace_keycode (keymap, keycode, NoSymbol);
- }
-
- g_hash_table_destroy (keymap->reserved_keycodes);
- g_queue_free (keymap->available_keycodes);
-
- if (keymap->xkb_desc != NULL)
- XkbFreeKeyboard (keymap->xkb_desc, XkbAllComponentsMask, True);
-
- G_OBJECT_CLASS (meta_keymap_x11_parent_class)->finalize (object);
-}
-
-static PangoDirection
-meta_keymap_x11_get_direction (ClutterKeymap *keymap)
-{
- MetaKeymapX11 *keymap_x11;
-
- g_return_val_if_fail (META_IS_KEYMAP_X11 (keymap), PANGO_DIRECTION_NEUTRAL);
-
- keymap_x11 = META_KEYMAP_X11 (keymap);
-
- if (keymap_x11->use_xkb)
- {
- if (!keymap_x11->has_direction)
- {
- XkbStateRec state_rec;
-
- XkbGetState (meta_clutter_x11_get_default_display (),
- XkbUseCoreKbd, &state_rec);
- update_direction (keymap_x11, XkbStateGroup (&state_rec));
- }
-
- return keymap_x11->current_direction;
- }
- else
- {
- return PANGO_DIRECTION_NEUTRAL;
- }
-}
-
-static void
-meta_keymap_x11_class_init (MetaKeymapX11Class *klass)
-{
- GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
- ClutterKeymapClass *keymap_class = CLUTTER_KEYMAP_CLASS (klass);
-
- obj_props[PROP_BACKEND] =
- g_param_spec_object ("backend",
- "Backend",
- "The Clutter backend",
- CLUTTER_TYPE_BACKEND,
- G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY);
-
- gobject_class->constructed = meta_keymap_x11_constructed;
- gobject_class->set_property = meta_keymap_x11_set_property;
- gobject_class->finalize = meta_keymap_x11_finalize;
-
- keymap_class->get_direction = meta_keymap_x11_get_direction;
-
- g_object_class_install_properties (gobject_class, PROP_LAST, obj_props);
-}
-
-static void
-meta_keymap_x11_init (MetaKeymapX11 *keymap)
-{
- keymap->current_direction = PANGO_DIRECTION_NEUTRAL;
- keymap->current_group = -1;
- keymap->reserved_keycodes = g_hash_table_new (NULL, NULL);
- keymap->available_keycodes = g_queue_new ();
-}
-
-gboolean
-meta_keymap_x11_handle_event (MetaKeymapX11 *keymap_x11,
- XEvent *xevent)
-{
- gboolean retval;
-
- if (!keymap_x11->use_xkb)
- return FALSE;
-
- retval = FALSE;
-
- if (xevent->type == keymap_x11->xkb_event_base)
- {
- XkbEvent *xkb_event = (XkbEvent *) xevent;
-
- switch (xkb_event->any.xkb_type)
- {
- case XkbStateNotify:
- g_debug ("Updating keyboard state");
- keymap_x11->current_group = XkbStateGroup (&xkb_event->state);
- update_direction (keymap_x11, keymap_x11->current_group);
- update_locked_mods (keymap_x11, xkb_event->state.locked_mods);
- retval = TRUE;
- break;
-
- case XkbNewKeyboardNotify:
- case XkbMapNotify:
- g_debug ("Updating keyboard mapping");
- XkbRefreshKeyboardMapping (&xkb_event->map);
- keymap_x11->keymap_serial += 1;
- retval = TRUE;
- break;
-
- default:
- break;
- }
- }
- else if (xevent->type == MappingNotify)
- {
- XRefreshKeyboardMapping (&xevent->xmapping);
- keymap_x11->keymap_serial += 1;
- retval = TRUE;
- }
-
- return retval;
-}
-
-int
-meta_keymap_x11_get_key_group (MetaKeymapX11 *keymap,
- ClutterModifierType state)
-{
- return XkbGroupForCoreState (state);
-}
-
-G_GNUC_BEGIN_IGNORE_DEPRECATIONS
-
-/* XXX - yes, I know that XKeycodeToKeysym() has been deprecated; hopefully,
- * this code will never get run on any decent system that is also able to
- * run Clutter. I just don't want to copy the implementation inside GDK for
- * a fallback path.
- */
-static int
-translate_keysym (MetaKeymapX11 *keymap,
- uint32_t hardware_keycode)
-{
- int retval;
-
- retval = XKeycodeToKeysym (meta_clutter_x11_get_default_display (),
- hardware_keycode, 0);
- return retval;
-}
-
-G_GNUC_END_IGNORE_DEPRECATIONS
-
-int
-meta_keymap_x11_translate_key_state (MetaKeymapX11 *keymap,
- uint32_t hardware_keycode,
- ClutterModifierType *modifier_state_p,
- ClutterModifierType *mods_p)
-{
- ClutterModifierType unconsumed_modifiers = 0;
- ClutterModifierType modifier_state = *modifier_state_p;
- int retval;
-
- g_return_val_if_fail (META_IS_KEYMAP_X11 (keymap), 0);
-
- if (keymap->use_xkb)
- {
- XkbDescRec *xkb = get_xkb (keymap);
- KeySym tmp_keysym;
-
- if (XkbTranslateKeyCode (xkb, hardware_keycode, modifier_state,
- &unconsumed_modifiers,
- &tmp_keysym))
- {
- retval = tmp_keysym;
- }
- else
- retval = 0;
- }
- else
- retval = translate_keysym (keymap, hardware_keycode);
-
- if (mods_p)
- *mods_p = unconsumed_modifiers;
-
- *modifier_state_p = modifier_state & ~(keymap->num_lock_mask |
- keymap->scroll_lock_mask |
- LockMask);
-
- return retval;
-}
-
-gboolean
-meta_keymap_x11_get_is_modifier (MetaKeymapX11 *keymap,
- int keycode)
-{
- g_return_val_if_fail (META_IS_KEYMAP_X11 (keymap), FALSE);
-
- if (keycode < keymap->min_keycode || keycode > keymap->max_keycode)
- return FALSE;
-
- if (keymap->use_xkb)
- {
- XkbDescRec *xkb = get_xkb (keymap);
-
- if (xkb->map->modmap && xkb->map->modmap[keycode] != 0)
- return TRUE;
- }
-
- return FALSE;
-}
-
-static gboolean
-meta_keymap_x11_get_entries_for_keyval (MetaKeymapX11 *keymap_x11,
- uint32_t keyval,
- ClutterKeymapKey **keys,
- int *n_keys)
-{
- if (keymap_x11->use_xkb)
- {
- XkbDescRec *xkb = get_xkb (keymap_x11);
- GArray *retval;
- int keycode;
-
- keycode = keymap_x11->min_keycode;
- retval = g_array_new (FALSE, FALSE, sizeof (ClutterKeymapKey));
-
- while (keycode <= keymap_x11->max_keycode)
- {
- int max_shift_levels = XkbKeyGroupsWidth (xkb, keycode);
- int group = 0;
- int level = 0;
- int total_syms = XkbKeyNumSyms (xkb, keycode);
- int i = 0;
- KeySym *entry;
-
- /* entry is an array with all syms for group 0, all
- * syms for group 1, etc. and for each group the
- * shift level syms are in order
- */
- entry = XkbKeySymsPtr (xkb, keycode);
-
- while (i < total_syms)
- {
- g_assert (i == (group * max_shift_levels + level));
-
- if (entry[i] == keyval)
- {
- ClutterKeymapKey key;
-
- key.keycode = keycode;
- key.group = group;
- key.level = level;
-
- g_array_append_val (retval, key);
-
- g_assert (XkbKeySymEntry (xkb, keycode, level, group) ==
- keyval);
- }
-
- ++level;
-
- if (level == max_shift_levels)
- {
- level = 0;
- ++group;
- }
-
- ++i;
- }
-
- ++keycode;
- }
-
- if (retval->len > 0)
- {
- *keys = (ClutterKeymapKey*) retval->data;
- *n_keys = retval->len;
- }
- else
- {
- *keys = NULL;
- *n_keys = 0;
- }
-
- g_array_free (retval, retval->len > 0 ? FALSE : TRUE);
-
- return *n_keys > 0;
- }
- else
- {
- return FALSE;
- }
-}
-
-static uint32_t
-meta_keymap_x11_get_available_keycode (MetaKeymapX11 *keymap_x11)
-{
- if (keymap_x11->use_xkb)
- {
- meta_keymap_x11_refresh_reserved_keycodes (keymap_x11);
-
- if (g_hash_table_size (keymap_x11->reserved_keycodes) < 5)
- {
- Display *xdisplay = meta_clutter_x11_get_default_display ();
- XkbDescPtr xkb = get_xkb (keymap_x11);
- uint32_t i;
-
- for (i = xkb->max_key_code; i >= xkb->min_key_code; --i)
- {
- if (XkbKeycodeToKeysym (xdisplay, i, 0, 0) == NoSymbol)
- return i;
- }
- }
-
- return GPOINTER_TO_UINT (g_queue_pop_head (keymap_x11->available_keycodes));
- }
-
- return 0;
-}
-
-gboolean
-meta_keymap_x11_reserve_keycode (MetaKeymapX11 *keymap_x11,
- uint32_t keyval,
- uint32_t *keycode_out)
-{
- g_return_val_if_fail (META_IS_KEYMAP_X11 (keymap_x11), FALSE);
- g_return_val_if_fail (keyval != 0, FALSE);
- g_return_val_if_fail (keycode_out != NULL, FALSE);
-
- *keycode_out = meta_keymap_x11_get_available_keycode (keymap_x11);
-
- if (*keycode_out == NoSymbol)
- {
- g_warning ("Cannot reserve a keycode for keyval %d: no available keycode", keyval);
- return FALSE;
- }
-
- if (!meta_keymap_x11_replace_keycode (keymap_x11, *keycode_out, keyval))
- {
- g_warning ("Failed to remap keycode %d to keyval %d", *keycode_out, keyval);
- return FALSE;
- }
-
- g_hash_table_insert (keymap_x11->reserved_keycodes, GUINT_TO_POINTER (*keycode_out), GUINT_TO_POINTER (keyval));
- g_queue_remove (keymap_x11->available_keycodes, GUINT_TO_POINTER (*keycode_out));
-
- return TRUE;
-}
-
-void
-meta_keymap_x11_release_keycode_if_needed (MetaKeymapX11 *keymap_x11,
- uint32_t keycode)
-{
- g_return_if_fail (META_IS_KEYMAP_X11 (keymap_x11));
-
- if (!g_hash_table_contains (keymap_x11->reserved_keycodes, GUINT_TO_POINTER (keycode)) ||
- g_queue_index (keymap_x11->available_keycodes, GUINT_TO_POINTER (keycode)) != -1)
- return;
-
- g_queue_push_tail (keymap_x11->available_keycodes, GUINT_TO_POINTER (keycode));
-}
-
-void
-meta_keymap_x11_latch_modifiers (MetaKeymapX11 *keymap_x11,
- uint32_t level,
- gboolean enable)
-{
- uint32_t modifiers[] = {
- 0,
- ShiftMask,
- keymap_x11->level3_shift_mask,
- keymap_x11->level3_shift_mask | ShiftMask,
- };
- uint32_t value = 0;
-
- if (!keymap_x11->use_xkb)
- return;
-
- level = CLAMP (level, 0, G_N_ELEMENTS (modifiers) - 1);
-
- if (enable)
- value = modifiers[level];
- else
- value = 0;
-
- XkbLatchModifiers (meta_clutter_x11_get_default_display (),
- XkbUseCoreKbd, modifiers[level],
- value);
-}
-
-static uint32_t
-meta_keymap_x11_get_current_group (MetaKeymapX11 *keymap_x11)
-{
- XkbStateRec state_rec;
-
- if (keymap_x11->current_group >= 0)
- return keymap_x11->current_group;
-
- XkbGetState (meta_clutter_x11_get_default_display (),
- XkbUseCoreKbd, &state_rec);
- return XkbStateGroup (&state_rec);
-}
-
-gboolean
-meta_keymap_x11_keycode_for_keyval (MetaKeymapX11 *keymap_x11,
- uint32_t keyval,
- uint32_t *keycode_out,
- uint32_t *level_out)
-{
- ClutterKeymapKey *keys;
- int i, n_keys, group;
- gboolean found = FALSE;
-
- g_return_val_if_fail (keycode_out != NULL, FALSE);
- g_return_val_if_fail (level_out != NULL, FALSE);
-
- group = meta_keymap_x11_get_current_group (keymap_x11);
-
- if (!meta_keymap_x11_get_entries_for_keyval (keymap_x11, keyval, &keys, &n_keys))
- return FALSE;
-
- for (i = 0; i < n_keys && !found; i++)
- {
- if (keys[i].group == group)
- {
- *keycode_out = keys[i].keycode;
- *level_out = keys[i].level;
- found = TRUE;
- }
- }
-
- if (!found)
- {
- GHashTableIter iter;
- gpointer key, value;
-
- g_hash_table_iter_init (&iter, keymap_x11->reserved_keycodes);
- while (!found && g_hash_table_iter_next (&iter, &key, &value))
- {
- uint32_t reserved_keycode = GPOINTER_TO_UINT (key);
- uint32_t reserved_keysym = GPOINTER_TO_UINT (value);
-
- if (keyval == reserved_keysym)
- {
- *keycode_out = reserved_keycode;
- *level_out = 0;
- found = TRUE;
- }
- }
- }
-
- g_free (keys);
- return found;
-}
diff --git a/src/backends/x11/meta-keymap-x11.h b/src/backends/x11/meta-keymap-x11.h
deleted file mode 100644
index 67a5f8eb9..000000000
--- a/src/backends/x11/meta-keymap-x11.h
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Copyright (C) 2009 Intel Corp.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
- *
- * Author: Emmanuele Bassi <ebassi@linux.intel.com>
- */
-
-#ifndef META_KEYMAP_X11_H
-#define META_KEYMAP_X11_H
-
-#include <glib-object.h>
-#include <pango/pango.h>
-
-#include "clutter/clutter.h"
-
-G_BEGIN_DECLS
-
-#define META_TYPE_KEYMAP_X11 (meta_keymap_x11_get_type ())
-G_DECLARE_FINAL_TYPE (MetaKeymapX11, meta_keymap_x11,
- META, KEYMAP_X11, ClutterKeymap)
-
-int meta_keymap_x11_get_key_group (MetaKeymapX11 *keymap,
- ClutterModifierType state);
-int meta_keymap_x11_translate_key_state (MetaKeymapX11 *keymap,
- guint hardware_keycode,
- ClutterModifierType *modifier_state_p,
- ClutterModifierType *mods_p);
-gboolean meta_keymap_x11_get_is_modifier (MetaKeymapX11 *keymap,
- int keycode);
-
-gboolean meta_keymap_x11_keycode_for_keyval (MetaKeymapX11 *keymap_x11,
- guint keyval,
- guint *keycode_out,
- guint *level_out);
-void meta_keymap_x11_latch_modifiers (MetaKeymapX11 *keymap_x11,
- uint32_t level,
- gboolean enable);
-gboolean meta_keymap_x11_reserve_keycode (MetaKeymapX11 *keymap_x11,
- guint keyval,
- guint *keycode_out);
-void meta_keymap_x11_release_keycode_if_needed (MetaKeymapX11 *keymap_x11,
- guint keycode);
-
-gboolean meta_keymap_x11_handle_event (MetaKeymapX11 *keymap_x11,
- XEvent *xevent);
-
-G_END_DECLS
-
-#endif /* META_KEYMAP_X11_H */
diff --git a/src/backends/x11/meta-monitor-manager-xrandr.c b/src/backends/x11/meta-monitor-manager-xrandr.c
deleted file mode 100644
index 489a9b424..000000000
--- a/src/backends/x11/meta-monitor-manager-xrandr.c
+++ /dev/null
@@ -1,1151 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2001, 2002 Havoc Pennington
- * Copyright (C) 2002, 2003 Red Hat Inc.
- * Some ICCCM manager selection code derived from fvwm2,
- * Copyright (C) 2001 Dominik Vogt, Matthias Clasen, and fvwm2 team
- * Copyright (C) 2003 Rob Adams
- * Copyright (C) 2004-2006 Elijah Newren
- * Copyright (C) 2013 Red Hat Inc.
- * Copyright (C) 2020 NVIDIA CORPORATION
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, see <http://www.gnu.org/licenses/>.
- */
-
-/**
- * SECTION:meta-monitor-manager-xrandr
- * @title: MetaMonitorManagerXrandr
- * @short_description: A subclass of #MetaMonitorManager using XRadR
- *
- * #MetaMonitorManagerXrandr is a subclass of #MetaMonitorManager which
- * implements its functionality using the RandR X protocol.
- *
- * See also #MetaMonitorManagerKms for a native implementation using Linux DRM
- * and udev.
- */
-
-#include "config.h"
-
-#include "backends/x11/meta-monitor-manager-xrandr.h"
-
-#include <math.h>
-#include <stdlib.h>
-#include <string.h>
-#include <X11/Xlib-xcb.h>
-#include <X11/Xlibint.h>
-#include <X11/extensions/dpms.h>
-#include <xcb/randr.h>
-
-#include "backends/meta-crtc.h"
-#include "backends/meta-logical-monitor.h"
-#include "backends/meta-monitor-config-manager.h"
-#include "backends/meta-output.h"
-#include "backends/x11/meta-backend-x11.h"
-#include "backends/x11/meta-crtc-xrandr.h"
-#include "backends/x11/meta-gpu-xrandr.h"
-#include "backends/x11/meta-output-xrandr.h"
-#include "clutter/clutter.h"
-#include "meta/main.h"
-#include "meta/meta-x11-errors.h"
-
-/* Look for DPI_FALLBACK in:
- * http://git.gnome.org/browse/gnome-settings-daemon/tree/plugins/xsettings/gsd-xsettings-manager.c
- * for the reasoning */
-#define DPI_FALLBACK 96.0
-
-struct _MetaMonitorManagerXrandr
-{
- MetaMonitorManager parent_instance;
-
- Display *xdisplay;
- int rr_event_base;
- int rr_error_base;
- gboolean has_randr15;
-
- xcb_timestamp_t last_xrandr_set_timestamp;
-
- GHashTable *tiled_monitor_atoms;
-
- float *supported_scales;
- int n_supported_scales;
-};
-
-struct _MetaMonitorManagerXrandrClass
-{
- MetaMonitorManagerClass parent_class;
-};
-
-G_DEFINE_TYPE (MetaMonitorManagerXrandr, meta_monitor_manager_xrandr, META_TYPE_MONITOR_MANAGER);
-
-typedef struct _MetaMonitorXrandrData
-{
- Atom xrandr_name;
-} MetaMonitorXrandrData;
-
-GQuark quark_meta_monitor_xrandr_data;
-
-Display *
-meta_monitor_manager_xrandr_get_xdisplay (MetaMonitorManagerXrandr *manager_xrandr)
-{
- return manager_xrandr->xdisplay;
-}
-
-gboolean
-meta_monitor_manager_xrandr_has_randr15 (MetaMonitorManagerXrandr *manager_xrandr)
-{
- return manager_xrandr->has_randr15;
-}
-
-static GBytes *
-meta_monitor_manager_xrandr_read_edid (MetaMonitorManager *manager,
- MetaOutput *output)
-{
- return meta_output_xrandr_read_edid (output);
-}
-
-static MetaPowerSave
-x11_dpms_state_to_power_save (CARD16 dpms_state)
-{
- switch (dpms_state)
- {
- case DPMSModeOn:
- return META_POWER_SAVE_ON;
- case DPMSModeStandby:
- return META_POWER_SAVE_STANDBY;
- case DPMSModeSuspend:
- return META_POWER_SAVE_SUSPEND;
- case DPMSModeOff:
- return META_POWER_SAVE_OFF;
- default:
- return META_POWER_SAVE_UNSUPPORTED;
- }
-}
-
-static void
-meta_monitor_manager_xrandr_read_current_state (MetaMonitorManager *manager)
-{
- MetaMonitorManagerXrandr *manager_xrandr =
- META_MONITOR_MANAGER_XRANDR (manager);
- MetaMonitorManagerClass *parent_class =
- META_MONITOR_MANAGER_CLASS (meta_monitor_manager_xrandr_parent_class);
- Display *xdisplay = meta_monitor_manager_xrandr_get_xdisplay (manager_xrandr);
- BOOL dpms_capable, dpms_enabled;
- CARD16 dpms_state;
- MetaPowerSave power_save_mode;
-
- dpms_capable = DPMSCapable (xdisplay);
-
- if (dpms_capable &&
- DPMSInfo (xdisplay, &dpms_state, &dpms_enabled) &&
- dpms_enabled)
- power_save_mode = x11_dpms_state_to_power_save (dpms_state);
- else
- power_save_mode = META_POWER_SAVE_UNSUPPORTED;
-
- meta_monitor_manager_power_save_mode_changed (manager, power_save_mode);
-
- parent_class->read_current_state (manager);
-}
-
-static void
-meta_monitor_manager_xrandr_set_power_save_mode (MetaMonitorManager *manager,
- MetaPowerSave mode)
-{
- MetaMonitorManagerXrandr *manager_xrandr = META_MONITOR_MANAGER_XRANDR (manager);
- CARD16 state;
-
- switch (mode) {
- case META_POWER_SAVE_ON:
- state = DPMSModeOn;
- break;
- case META_POWER_SAVE_STANDBY:
- state = DPMSModeStandby;
- break;
- case META_POWER_SAVE_SUSPEND:
- state = DPMSModeSuspend;
- break;
- case META_POWER_SAVE_OFF:
- state = DPMSModeOff;
- break;
- default:
- return;
- }
-
- DPMSForceLevel (manager_xrandr->xdisplay, state);
- DPMSSetTimeouts (manager_xrandr->xdisplay, 0, 0, 0);
-}
-
-static xcb_randr_rotation_t
-meta_monitor_transform_to_xrandr (MetaMonitorTransform transform)
-{
- switch (transform)
- {
- case META_MONITOR_TRANSFORM_NORMAL:
- return XCB_RANDR_ROTATION_ROTATE_0;
- case META_MONITOR_TRANSFORM_90:
- return XCB_RANDR_ROTATION_ROTATE_90;
- case META_MONITOR_TRANSFORM_180:
- return XCB_RANDR_ROTATION_ROTATE_180;
- case META_MONITOR_TRANSFORM_270:
- return XCB_RANDR_ROTATION_ROTATE_270;
- case META_MONITOR_TRANSFORM_FLIPPED:
- return XCB_RANDR_ROTATION_REFLECT_X | XCB_RANDR_ROTATION_ROTATE_0;
- case META_MONITOR_TRANSFORM_FLIPPED_90:
- return XCB_RANDR_ROTATION_REFLECT_X | XCB_RANDR_ROTATION_ROTATE_90;
- case META_MONITOR_TRANSFORM_FLIPPED_180:
- return XCB_RANDR_ROTATION_REFLECT_X | XCB_RANDR_ROTATION_ROTATE_180;
- case META_MONITOR_TRANSFORM_FLIPPED_270:
- return XCB_RANDR_ROTATION_REFLECT_X | XCB_RANDR_ROTATION_ROTATE_270;
- }
-
- g_assert_not_reached ();
- return 0;
-}
-
-static gboolean
-xrandr_set_crtc_config (MetaMonitorManagerXrandr *manager_xrandr,
- MetaCrtc *crtc,
- gboolean save_timestamp,
- xcb_randr_crtc_t xrandr_crtc,
- xcb_timestamp_t timestamp,
- int x,
- int y,
- xcb_randr_mode_t mode,
- xcb_randr_rotation_t rotation,
- xcb_randr_output_t *outputs,
- int n_outputs)
-{
- xcb_timestamp_t new_timestamp;
-
- if (!meta_crtc_xrandr_set_config (META_CRTC_XRANDR (crtc),
- xrandr_crtc, timestamp,
- x, y, mode, rotation,
- outputs, n_outputs,
- &new_timestamp))
- return FALSE;
-
- if (save_timestamp)
- manager_xrandr->last_xrandr_set_timestamp = new_timestamp;
-
- return TRUE;
-}
-
-static gboolean
-is_crtc_assignment_changed (MetaCrtc *crtc,
- MetaCrtcAssignment **crtc_assignments,
- unsigned int n_crtc_assignments)
-{
- unsigned int i;
-
- for (i = 0; i < n_crtc_assignments; i++)
- {
- MetaCrtcAssignment *crtc_assignment = crtc_assignments[i];
-
- if (crtc_assignment->crtc != crtc)
- continue;
-
- return meta_crtc_xrandr_is_assignment_changed (META_CRTC_XRANDR (crtc),
- crtc_assignment);
- }
-
- return !!meta_crtc_xrandr_get_current_mode (META_CRTC_XRANDR (crtc));
-}
-
-static gboolean
-is_output_assignment_changed (MetaOutput *output,
- MetaCrtcAssignment **crtc_assignments,
- unsigned int n_crtc_assignments,
- MetaOutputAssignment **output_assignments,
- unsigned int n_output_assignments)
-{
- MetaCrtc *assigned_crtc;
- gboolean output_is_found = FALSE;
- unsigned int i;
-
- for (i = 0; i < n_output_assignments; i++)
- {
- MetaOutputAssignment *output_assignment = output_assignments[i];
-
- if (output_assignment->output != output)
- continue;
-
- if (meta_output_is_primary (output) != output_assignment->is_primary)
- return TRUE;
-
- if (meta_output_is_presentation (output) !=
- output_assignment->is_presentation)
- return TRUE;
-
- if (meta_output_is_underscanning (output) !=
- output_assignment->is_underscanning)
- return TRUE;
-
- output_is_found = TRUE;
- }
-
- assigned_crtc = meta_output_get_assigned_crtc (output);
-
- if (!output_is_found)
- return assigned_crtc != NULL;
-
- for (i = 0; i < n_crtc_assignments; i++)
- {
- MetaCrtcAssignment *crtc_assignment = crtc_assignments[i];
- unsigned int j;
-
- for (j = 0; j < crtc_assignment->outputs->len; j++)
- {
- MetaOutput *crtc_assignment_output =
- ((MetaOutput**) crtc_assignment->outputs->pdata)[j];
-
- if (crtc_assignment_output == output &&
- crtc_assignment->crtc == assigned_crtc)
- return FALSE;
- }
- }
-
- return TRUE;
-}
-
-static MetaGpu *
-meta_monitor_manager_xrandr_get_gpu (MetaMonitorManagerXrandr *manager_xrandr)
-{
- MetaMonitorManager *manager = META_MONITOR_MANAGER (manager_xrandr);
- MetaBackend *backend = meta_monitor_manager_get_backend (manager);
-
- return META_GPU (meta_backend_get_gpus (backend)->data);
-}
-
-static gboolean
-is_assignments_changed (MetaMonitorManager *manager,
- MetaCrtcAssignment **crtc_assignments,
- unsigned int n_crtc_assignments,
- MetaOutputAssignment **output_assignments,
- unsigned int n_output_assignments)
-{
- MetaMonitorManagerXrandr *manager_xrandr =
- META_MONITOR_MANAGER_XRANDR (manager);
- MetaGpu *gpu = meta_monitor_manager_xrandr_get_gpu (manager_xrandr);
- GList *l;
-
- for (l = meta_gpu_get_crtcs (gpu); l; l = l->next)
- {
- MetaCrtc *crtc = l->data;
-
- if (is_crtc_assignment_changed (crtc, crtc_assignments, n_crtc_assignments))
- return TRUE;
- }
-
- for (l = meta_gpu_get_outputs (gpu); l; l = l->next)
- {
- MetaOutput *output = l->data;
-
- if (is_output_assignment_changed (output,
- crtc_assignments,
- n_crtc_assignments,
- output_assignments,
- n_output_assignments))
- return TRUE;
- }
-
- return FALSE;
-}
-
-static void
-apply_crtc_assignments (MetaMonitorManager *manager,
- gboolean save_timestamp,
- MetaCrtcAssignment **crtcs,
- unsigned int n_crtcs,
- MetaOutputAssignment **outputs,
- unsigned int n_outputs)
-{
- MetaMonitorManagerXrandr *manager_xrandr = META_MONITOR_MANAGER_XRANDR (manager);
- MetaGpu *gpu = meta_monitor_manager_xrandr_get_gpu (manager_xrandr);
- g_autoptr (GList) to_configure_outputs = NULL;
- g_autoptr (GList) to_disable_crtcs = NULL;
- unsigned i;
- GList *l;
- int width, height, width_mm, height_mm;
-
- to_configure_outputs = g_list_copy (meta_gpu_get_outputs (gpu));
- to_disable_crtcs = g_list_copy (meta_gpu_get_crtcs (gpu));
-
- XGrabServer (manager_xrandr->xdisplay);
-
- /* First compute the new size of the screen (framebuffer) */
- width = 0; height = 0;
- for (i = 0; i < n_crtcs; i++)
- {
- MetaCrtcAssignment *crtc_assignment = crtcs[i];
- MetaCrtc *crtc = crtc_assignment->crtc;
-
- if (crtc_assignment->mode == NULL)
- continue;
-
- to_disable_crtcs = g_list_remove (to_disable_crtcs, crtc);
-
- width = MAX (width, (int) roundf (crtc_assignment->layout.origin.x +
- crtc_assignment->layout.size.width));
- height = MAX (height, (int) roundf (crtc_assignment->layout.origin.y +
- crtc_assignment->layout.size.height));
- }
-
- /* Second disable all newly disabled CRTCs, or CRTCs that in the previous
- configuration would be outside the new framebuffer (otherwise X complains
- loudly when resizing)
- CRTC will be enabled again after resizing the FB
- */
- for (i = 0; i < n_crtcs; i++)
- {
- MetaCrtcAssignment *crtc_assignment = crtcs[i];
- MetaCrtc *crtc = crtc_assignment->crtc;
- const MetaCrtcConfig *crtc_config;
- int x2, y2;
-
- crtc_config = meta_crtc_get_config (crtc);
- if (!crtc_config)
- continue;
-
- x2 = (int) roundf (crtc_config->layout.origin.x +
- crtc_config->layout.size.width);
- y2 = (int) roundf (crtc_config->layout.origin.y +
- crtc_config->layout.size.height);
-
- if (!crtc_assignment->mode || x2 > width || y2 > height)
- {
- xrandr_set_crtc_config (manager_xrandr,
- crtc,
- save_timestamp,
- (xcb_randr_crtc_t) meta_crtc_get_id (crtc),
- XCB_CURRENT_TIME,
- 0, 0, XCB_NONE,
- XCB_RANDR_ROTATION_ROTATE_0,
- NULL, 0);
-
- meta_crtc_unset_config (crtc);
- }
- }
-
- for (l = to_disable_crtcs; l; l = l->next)
- {
- MetaCrtc *crtc = l->data;
-
- if (!meta_crtc_get_config (crtc))
- continue;
-
- xrandr_set_crtc_config (manager_xrandr,
- crtc,
- save_timestamp,
- (xcb_randr_crtc_t) meta_crtc_get_id (crtc),
- XCB_CURRENT_TIME,
- 0, 0, XCB_NONE,
- XCB_RANDR_ROTATION_ROTATE_0,
- NULL, 0);
-
- meta_crtc_unset_config (crtc);
- }
-
- if (!n_crtcs)
- goto out;
-
- g_assert (width > 0 && height > 0);
- /* The 'physical size' of an X screen is meaningless if that screen
- * can consist of many monitors. So just pick a size that make the
- * dpi 96.
- *
- * Firefox and Evince apparently believe what X tells them.
- */
- width_mm = (width / DPI_FALLBACK) * 25.4 + 0.5;
- height_mm = (height / DPI_FALLBACK) * 25.4 + 0.5;
- XRRSetScreenSize (manager_xrandr->xdisplay, DefaultRootWindow (manager_xrandr->xdisplay),
- width, height, width_mm, height_mm);
-
- for (i = 0; i < n_crtcs; i++)
- {
- MetaCrtcAssignment *crtc_assignment = crtcs[i];
- MetaCrtc *crtc = crtc_assignment->crtc;
-
- if (crtc_assignment->mode != NULL)
- {
- MetaCrtcMode *crtc_mode;
- g_autofree xcb_randr_output_t *output_ids = NULL;
- unsigned int j, n_output_ids;
- xcb_randr_crtc_t crtc_id;
- int x, y;
- xcb_randr_rotation_t rotation;
- xcb_randr_mode_t mode;
-
- crtc_mode = crtc_assignment->mode;
-
- n_output_ids = crtc_assignment->outputs->len;
- output_ids = g_new (xcb_randr_output_t, n_output_ids);
-
- for (j = 0; j < n_output_ids; j++)
- {
- MetaOutput *output;
- MetaOutputAssignment *output_assignment;
-
- output = ((MetaOutput**)crtc_assignment->outputs->pdata)[j];
-
- to_configure_outputs = g_list_remove (to_configure_outputs,
- output);
-
- output_assignment = meta_find_output_assignment (outputs,
- n_outputs,
- output);
- meta_output_assign_crtc (output, crtc, output_assignment);
-
- output_ids[j] = meta_output_get_id (output);
- }
-
- crtc_id = (xcb_randr_crtc_t) meta_crtc_get_id (crtc);
- x = (int) roundf (crtc_assignment->layout.origin.x);
- y = (int) roundf (crtc_assignment->layout.origin.y);
- rotation =
- meta_monitor_transform_to_xrandr (crtc_assignment->transform);
- mode = meta_crtc_mode_get_id (crtc_mode);
- if (!xrandr_set_crtc_config (manager_xrandr,
- crtc,
- save_timestamp,
- crtc_id,
- XCB_CURRENT_TIME,
- x, y,
- mode,
- rotation,
- output_ids, n_output_ids))
- {
- const MetaCrtcModeInfo *crtc_mode_info =
- meta_crtc_mode_get_info (crtc_mode);
-
- meta_warning ("Configuring CRTC %d with mode %d (%d x %d @ %f) at position %d, %d and transform %u failed",
- (unsigned) meta_crtc_get_id (crtc),
- (unsigned) mode,
- crtc_mode_info->width, crtc_mode_info->height,
- (float) crtc_mode_info->refresh_rate,
- (int) roundf (crtc_assignment->layout.origin.x),
- (int) roundf (crtc_assignment->layout.origin.y),
- crtc_assignment->transform);
- continue;
- }
-
- meta_crtc_set_config (crtc,
- &crtc_assignment->layout,
- crtc_mode,
- crtc_assignment->transform);
- }
- }
-
- for (i = 0; i < n_outputs; i++)
- {
- MetaOutputAssignment *output_assignment = outputs[i];
- MetaOutput *output = output_assignment->output;
-
- meta_output_xrandr_apply_mode (META_OUTPUT_XRANDR (output));
- }
-
- g_list_foreach (to_configure_outputs,
- (GFunc) meta_output_unassign_crtc,
- NULL);
-
-out:
- XUngrabServer (manager_xrandr->xdisplay);
- XFlush (manager_xrandr->xdisplay);
-}
-
-static void
-meta_monitor_manager_xrandr_ensure_initial_config (MetaMonitorManager *manager)
-{
- MetaMonitorConfigManager *config_manager =
- meta_monitor_manager_get_config_manager (manager);
- MetaMonitorsConfig *config;
-
- meta_monitor_manager_ensure_configured (manager);
-
- /*
- * Normally we don't rebuild our data structures until we see the
- * RRScreenNotify event, but at least at startup we want to have the right
- * configuration immediately.
- */
- meta_monitor_manager_read_current_state (manager);
-
- config = meta_monitor_config_manager_get_current (config_manager);
- meta_monitor_manager_update_logical_state_derived (manager, config);
-}
-
-static void
-meta_monitor_manager_xrandr_rebuild_derived (MetaMonitorManager *manager,
- MetaMonitorsConfig *config)
-{
- MetaMonitorManagerXrandr *manager_xrandr =
- META_MONITOR_MANAGER_XRANDR (manager);
-
- g_clear_pointer (&manager_xrandr->supported_scales, g_free);
- meta_monitor_manager_rebuild_derived (manager, config);
-}
-
-static gboolean
-meta_monitor_manager_xrandr_apply_monitors_config (MetaMonitorManager *manager,
- MetaMonitorsConfig *config,
- MetaMonitorsConfigMethod method,
- GError **error)
-{
- GPtrArray *crtc_assignments;
- GPtrArray *output_assignments;
-
- if (!config)
- {
- if (!manager->in_init)
- apply_crtc_assignments (manager, TRUE, NULL, 0, NULL, 0);
-
- meta_monitor_manager_xrandr_rebuild_derived (manager, NULL);
- return TRUE;
- }
-
- if (!meta_monitor_config_manager_assign (manager, config,
- &crtc_assignments,
- &output_assignments,
- error))
- return FALSE;
-
- if (method != META_MONITORS_CONFIG_METHOD_VERIFY)
- {
- /*
- * If the assignment has not changed, we won't get any notification about
- * any new configuration from the X server; but we still need to update
- * our own configuration, as something not applicable in Xrandr might
- * have changed locally, such as the logical monitors scale. This means we
- * must check that our new assignment actually changes anything, otherwise
- * just update the logical state.
- */
- if (is_assignments_changed (manager,
- (MetaCrtcAssignment **) crtc_assignments->pdata,
- crtc_assignments->len,
- (MetaOutputAssignment **) output_assignments->pdata,
- output_assignments->len))
- {
- apply_crtc_assignments (manager,
- TRUE,
- (MetaCrtcAssignment **) crtc_assignments->pdata,
- crtc_assignments->len,
- (MetaOutputAssignment **) output_assignments->pdata,
- output_assignments->len);
- }
- else
- {
- meta_monitor_manager_xrandr_rebuild_derived (manager, config);
- }
- }
-
- g_ptr_array_free (crtc_assignments, TRUE);
- g_ptr_array_free (output_assignments, TRUE);
-
- return TRUE;
-}
-
-static void
-meta_monitor_manager_xrandr_change_backlight (MetaMonitorManager *manager,
- MetaOutput *output,
- gint value)
-{
- meta_output_xrandr_change_backlight (META_OUTPUT_XRANDR (output), value);
-}
-
-static void
-meta_monitor_manager_xrandr_get_crtc_gamma (MetaMonitorManager *manager,
- MetaCrtc *crtc,
- gsize *size,
- unsigned short **red,
- unsigned short **green,
- unsigned short **blue)
-{
- MetaMonitorManagerXrandr *manager_xrandr = META_MONITOR_MANAGER_XRANDR (manager);
- XRRCrtcGamma *gamma;
-
- gamma = XRRGetCrtcGamma (manager_xrandr->xdisplay,
- (XID) meta_crtc_get_id (crtc));
-
- *size = gamma->size;
- *red = g_memdup2 (gamma->red, sizeof (unsigned short) * gamma->size);
- *green = g_memdup2 (gamma->green, sizeof (unsigned short) * gamma->size);
- *blue = g_memdup2 (gamma->blue, sizeof (unsigned short) * gamma->size);
-
- XRRFreeGamma (gamma);
-}
-
-static void
-meta_monitor_manager_xrandr_set_crtc_gamma (MetaMonitorManager *manager,
- MetaCrtc *crtc,
- gsize size,
- unsigned short *red,
- unsigned short *green,
- unsigned short *blue)
-{
- MetaMonitorManagerXrandr *manager_xrandr = META_MONITOR_MANAGER_XRANDR (manager);
- XRRCrtcGamma *gamma;
-
- gamma = XRRAllocGamma (size);
- memcpy (gamma->red, red, sizeof (unsigned short) * size);
- memcpy (gamma->green, green, sizeof (unsigned short) * size);
- memcpy (gamma->blue, blue, sizeof (unsigned short) * size);
-
- XRRSetCrtcGamma (manager_xrandr->xdisplay,
- (XID) meta_crtc_get_id (crtc),
- gamma);
-
- XRRFreeGamma (gamma);
-}
-
-static MetaMonitorXrandrData *
-meta_monitor_xrandr_data_from_monitor (MetaMonitor *monitor)
-{
- MetaMonitorXrandrData *monitor_xrandr_data;
-
- monitor_xrandr_data = g_object_get_qdata (G_OBJECT (monitor),
- quark_meta_monitor_xrandr_data);
- if (monitor_xrandr_data)
- return monitor_xrandr_data;
-
- monitor_xrandr_data = g_new0 (MetaMonitorXrandrData, 1);
- g_object_set_qdata_full (G_OBJECT (monitor),
- quark_meta_monitor_xrandr_data,
- monitor_xrandr_data,
- g_free);
-
- return monitor_xrandr_data;
-}
-
-static void
-meta_monitor_manager_xrandr_increase_monitor_count (MetaMonitorManagerXrandr *manager_xrandr,
- Atom name_atom)
-{
- int count;
-
- count =
- GPOINTER_TO_INT (g_hash_table_lookup (manager_xrandr->tiled_monitor_atoms,
- GSIZE_TO_POINTER (name_atom)));
-
- count++;
- g_hash_table_insert (manager_xrandr->tiled_monitor_atoms,
- GSIZE_TO_POINTER (name_atom),
- GINT_TO_POINTER (count));
-}
-
-static int
-meta_monitor_manager_xrandr_decrease_monitor_count (MetaMonitorManagerXrandr *manager_xrandr,
- Atom name_atom)
-{
- int count;
-
- count =
- GPOINTER_TO_SIZE (g_hash_table_lookup (manager_xrandr->tiled_monitor_atoms,
- GSIZE_TO_POINTER (name_atom)));
- g_assert (count > 0);
-
- count--;
- g_hash_table_insert (manager_xrandr->tiled_monitor_atoms,
- GSIZE_TO_POINTER (name_atom),
- GINT_TO_POINTER (count));
-
- return count;
-}
-
-static void
-meta_monitor_manager_xrandr_tiled_monitor_added (MetaMonitorManager *manager,
- MetaMonitor *monitor)
-{
- MetaMonitorManagerXrandr *manager_xrandr = META_MONITOR_MANAGER_XRANDR (manager);
- MetaMonitorTiled *monitor_tiled = META_MONITOR_TILED (monitor);
- const char *product;
- char *name;
- uint32_t tile_group_id;
- MetaMonitorXrandrData *monitor_xrandr_data;
- Atom name_atom;
- XRRMonitorInfo *xrandr_monitor_info;
- GList *outputs;
- GList *l;
- int i;
-
- if (manager_xrandr->has_randr15 == FALSE)
- return;
-
- product = meta_monitor_get_product (monitor);
- tile_group_id = meta_monitor_tiled_get_tile_group_id (monitor_tiled);
-
- if (product)
- name = g_strdup_printf ("%s-%d", product, tile_group_id);
- else
- name = g_strdup_printf ("Tiled-%d", tile_group_id);
-
- name_atom = XInternAtom (manager_xrandr->xdisplay, name, False);
- g_free (name);
-
- monitor_xrandr_data = meta_monitor_xrandr_data_from_monitor (monitor);
- monitor_xrandr_data->xrandr_name = name_atom;
-
- meta_monitor_manager_xrandr_increase_monitor_count (manager_xrandr,
- name_atom);
-
- outputs = meta_monitor_get_outputs (monitor);
- xrandr_monitor_info = XRRAllocateMonitor (manager_xrandr->xdisplay,
- g_list_length (outputs));
- xrandr_monitor_info->name = name_atom;
- xrandr_monitor_info->primary = meta_monitor_is_primary (monitor);
- xrandr_monitor_info->automatic = True;
- for (l = outputs, i = 0; l; l = l->next, i++)
- {
- MetaOutput *output = l->data;
-
- xrandr_monitor_info->outputs[i] = meta_output_get_id (output);
- }
-
- XRRSetMonitor (manager_xrandr->xdisplay,
- DefaultRootWindow (manager_xrandr->xdisplay),
- xrandr_monitor_info);
- XRRFreeMonitors (xrandr_monitor_info);
-}
-
-static void
-meta_monitor_manager_xrandr_tiled_monitor_removed (MetaMonitorManager *manager,
- MetaMonitor *monitor)
-{
- MetaMonitorManagerXrandr *manager_xrandr = META_MONITOR_MANAGER_XRANDR (manager);
- MetaMonitorXrandrData *monitor_xrandr_data;
- Atom monitor_name;
-
- int monitor_count;
-
- if (manager_xrandr->has_randr15 == FALSE)
- return;
-
- monitor_xrandr_data = meta_monitor_xrandr_data_from_monitor (monitor);
- monitor_name = monitor_xrandr_data->xrandr_name;
- monitor_count =
- meta_monitor_manager_xrandr_decrease_monitor_count (manager_xrandr,
- monitor_name);
-
- if (monitor_count == 0)
- XRRDeleteMonitor (manager_xrandr->xdisplay,
- DefaultRootWindow (manager_xrandr->xdisplay),
- monitor_name);
-}
-
-static void
-meta_monitor_manager_xrandr_init_monitors (MetaMonitorManagerXrandr *manager_xrandr)
-{
- XRRMonitorInfo *m;
- int n, i;
-
- if (manager_xrandr->has_randr15 == FALSE)
- return;
-
- /* delete any tiled monitors setup, as mutter will want to recreate
- things in its image */
- m = XRRGetMonitors (manager_xrandr->xdisplay,
- DefaultRootWindow (manager_xrandr->xdisplay),
- FALSE, &n);
- if (n == -1)
- return;
-
- for (i = 0; i < n; i++)
- {
- if (m[i].noutput > 1)
- XRRDeleteMonitor (manager_xrandr->xdisplay,
- DefaultRootWindow (manager_xrandr->xdisplay),
- m[i].name);
- }
- XRRFreeMonitors (m);
-}
-
-static gboolean
-meta_monitor_manager_xrandr_is_transform_handled (MetaMonitorManager *manager,
- MetaCrtc *crtc,
- MetaMonitorTransform transform)
-{
- g_warn_if_fail ((meta_crtc_get_all_transforms (crtc) & transform) ==
- transform);
-
- return TRUE;
-}
-
-static float
-meta_monitor_manager_xrandr_calculate_monitor_mode_scale (MetaMonitorManager *manager,
- MetaMonitor *monitor,
- MetaMonitorMode *monitor_mode)
-{
- return meta_monitor_calculate_mode_scale (monitor, monitor_mode);
-}
-
-static void
-add_supported_scale (GArray *supported_scales,
- float scale)
-{
- unsigned int i;
-
- for (i = 0; i < supported_scales->len; i++)
- {
- float supported_scale = g_array_index (supported_scales, float, i);
-
- if (scale == supported_scale)
- return;
- }
-
- g_array_append_val (supported_scales, scale);
-}
-
-static int
-compare_scales (gconstpointer a,
- gconstpointer b)
-{
- float f = *(float *) a - *(float *) b;
-
- if (f < 0)
- return -1;
- if (f > 0)
- return 1;
- return 0;
-}
-
-static void
-ensure_supported_monitor_scales (MetaMonitorManager *manager)
-{
- MetaMonitorManagerXrandr *manager_xrandr =
- META_MONITOR_MANAGER_XRANDR (manager);
- MetaMonitorScalesConstraint constraints;
- GList *l;
- GArray *supported_scales;
-
- if (manager_xrandr->supported_scales)
- return;
-
- constraints = META_MONITOR_SCALES_CONSTRAINT_NO_FRAC;
- supported_scales = g_array_new (FALSE, FALSE, sizeof (float));
-
- for (l = manager->monitors; l; l = l->next)
- {
- MetaMonitor *monitor = l->data;
- MetaMonitorMode *monitor_mode;
- float *monitor_scales;
- int n_monitor_scales;
- int i;
-
- monitor_mode = meta_monitor_get_preferred_mode (monitor);
- monitor_scales =
- meta_monitor_calculate_supported_scales (monitor,
- monitor_mode,
- constraints,
- &n_monitor_scales);
-
- for (i = 0; i < n_monitor_scales; i++)
- add_supported_scale (supported_scales, monitor_scales[i]);
- g_array_sort (supported_scales, compare_scales);
- g_free (monitor_scales);
- }
-
- manager_xrandr->supported_scales = (float *) supported_scales->data;
- manager_xrandr->n_supported_scales = supported_scales->len;
- g_array_free (supported_scales, FALSE);
-}
-
-static float *
-meta_monitor_manager_xrandr_calculate_supported_scales (MetaMonitorManager *manager,
- MetaLogicalMonitorLayoutMode layout_mode,
- MetaMonitor *monitor,
- MetaMonitorMode *monitor_mode,
- int *n_supported_scales)
-{
- MetaMonitorManagerXrandr *manager_xrandr =
- META_MONITOR_MANAGER_XRANDR (manager);
-
- ensure_supported_monitor_scales (manager);
-
- *n_supported_scales = manager_xrandr->n_supported_scales;
- return g_memdup2 (manager_xrandr->supported_scales,
- manager_xrandr->n_supported_scales * sizeof (float));
-}
-
-static MetaMonitorManagerCapability
-meta_monitor_manager_xrandr_get_capabilities (MetaMonitorManager *manager)
-{
- return META_MONITOR_MANAGER_CAPABILITY_GLOBAL_SCALE_REQUIRED;
-}
-
-static gboolean
-meta_monitor_manager_xrandr_get_max_screen_size (MetaMonitorManager *manager,
- int *max_width,
- int *max_height)
-{
- MetaMonitorManagerXrandr *manager_xrandr =
- META_MONITOR_MANAGER_XRANDR (manager);
- MetaGpu *gpu = meta_monitor_manager_xrandr_get_gpu (manager_xrandr);
-
- meta_gpu_xrandr_get_max_screen_size (META_GPU_XRANDR (gpu),
- max_width, max_height);
-
- return TRUE;
-}
-
-static MetaLogicalMonitorLayoutMode
-meta_monitor_manager_xrandr_get_default_layout_mode (MetaMonitorManager *manager)
-{
- return META_LOGICAL_MONITOR_LAYOUT_MODE_PHYSICAL;
-}
-
-static void
-meta_monitor_manager_xrandr_set_output_ctm (MetaOutput *output,
- const MetaOutputCtm *ctm)
-{
- meta_output_xrandr_set_ctm (META_OUTPUT_XRANDR (output), ctm);
-}
-
-static void
-meta_monitor_manager_xrandr_constructed (GObject *object)
-{
- MetaMonitorManagerXrandr *manager_xrandr =
- META_MONITOR_MANAGER_XRANDR (object);
- MetaMonitorManager *manager = META_MONITOR_MANAGER (manager_xrandr);
- MetaBackend *backend = meta_monitor_manager_get_backend (manager);
- MetaBackendX11 *backend_x11 = META_BACKEND_X11 (backend);
-
- manager_xrandr->xdisplay = meta_backend_x11_get_xdisplay (backend_x11);
-
- if (!XRRQueryExtension (manager_xrandr->xdisplay,
- &manager_xrandr->rr_event_base,
- &manager_xrandr->rr_error_base))
- {
- return;
- }
- else
- {
- int major_version, minor_version;
- /* We only use ScreenChangeNotify, but GDK uses the others,
- and we don't want to step on its toes */
- XRRSelectInput (manager_xrandr->xdisplay,
- DefaultRootWindow (manager_xrandr->xdisplay),
- RRScreenChangeNotifyMask
- | RRCrtcChangeNotifyMask
- | RROutputPropertyNotifyMask);
-
- manager_xrandr->has_randr15 = FALSE;
- XRRQueryVersion (manager_xrandr->xdisplay, &major_version,
- &minor_version);
- if (major_version > 1 ||
- (major_version == 1 &&
- minor_version >= 5))
- {
- manager_xrandr->has_randr15 = TRUE;
- manager_xrandr->tiled_monitor_atoms = g_hash_table_new (NULL, NULL);
- }
- meta_monitor_manager_xrandr_init_monitors (manager_xrandr);
- }
-
- G_OBJECT_CLASS (meta_monitor_manager_xrandr_parent_class)->constructed (object);
-}
-
-static void
-meta_monitor_manager_xrandr_finalize (GObject *object)
-{
- MetaMonitorManagerXrandr *manager_xrandr = META_MONITOR_MANAGER_XRANDR (object);
-
- g_hash_table_destroy (manager_xrandr->tiled_monitor_atoms);
- g_free (manager_xrandr->supported_scales);
-
- G_OBJECT_CLASS (meta_monitor_manager_xrandr_parent_class)->finalize (object);
-}
-
-static void
-meta_monitor_manager_xrandr_init (MetaMonitorManagerXrandr *manager_xrandr)
-{
-}
-
-static void
-meta_monitor_manager_xrandr_class_init (MetaMonitorManagerXrandrClass *klass)
-{
- MetaMonitorManagerClass *manager_class = META_MONITOR_MANAGER_CLASS (klass);
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- object_class->finalize = meta_monitor_manager_xrandr_finalize;
- object_class->constructed = meta_monitor_manager_xrandr_constructed;
-
- manager_class->read_edid = meta_monitor_manager_xrandr_read_edid;
- manager_class->read_current_state = meta_monitor_manager_xrandr_read_current_state;
- manager_class->ensure_initial_config = meta_monitor_manager_xrandr_ensure_initial_config;
- manager_class->apply_monitors_config = meta_monitor_manager_xrandr_apply_monitors_config;
- manager_class->set_power_save_mode = meta_monitor_manager_xrandr_set_power_save_mode;
- manager_class->change_backlight = meta_monitor_manager_xrandr_change_backlight;
- manager_class->get_crtc_gamma = meta_monitor_manager_xrandr_get_crtc_gamma;
- manager_class->set_crtc_gamma = meta_monitor_manager_xrandr_set_crtc_gamma;
- manager_class->tiled_monitor_added = meta_monitor_manager_xrandr_tiled_monitor_added;
- manager_class->tiled_monitor_removed = meta_monitor_manager_xrandr_tiled_monitor_removed;
- manager_class->is_transform_handled = meta_monitor_manager_xrandr_is_transform_handled;
- manager_class->calculate_monitor_mode_scale = meta_monitor_manager_xrandr_calculate_monitor_mode_scale;
- manager_class->calculate_supported_scales = meta_monitor_manager_xrandr_calculate_supported_scales;
- manager_class->get_capabilities = meta_monitor_manager_xrandr_get_capabilities;
- manager_class->get_max_screen_size = meta_monitor_manager_xrandr_get_max_screen_size;
- manager_class->get_default_layout_mode = meta_monitor_manager_xrandr_get_default_layout_mode;
- manager_class->set_output_ctm = meta_monitor_manager_xrandr_set_output_ctm;
-
- quark_meta_monitor_xrandr_data =
- g_quark_from_static_string ("-meta-monitor-xrandr-data");
-}
-
-gboolean
-meta_monitor_manager_xrandr_handle_xevent (MetaMonitorManagerXrandr *manager_xrandr,
- XEvent *event)
-{
- MetaMonitorManager *manager = META_MONITOR_MANAGER (manager_xrandr);
- MetaGpu *gpu = meta_monitor_manager_xrandr_get_gpu (manager_xrandr);
- MetaGpuXrandr *gpu_xrandr;
- XRRScreenResources *resources;
- gboolean is_hotplug;
- gboolean is_our_configuration;
-
- if ((event->type - manager_xrandr->rr_event_base) != RRScreenChangeNotify)
- return FALSE;
-
- XRRUpdateConfiguration (event);
-
- meta_monitor_manager_read_current_state (manager);
-
- gpu_xrandr = META_GPU_XRANDR (gpu);
- resources = meta_gpu_xrandr_get_resources (gpu_xrandr);
-
- is_hotplug = resources->timestamp < resources->configTimestamp;
- is_our_configuration = (resources->timestamp ==
- manager_xrandr->last_xrandr_set_timestamp);
- if (is_hotplug)
- {
- meta_monitor_manager_reconfigure (manager);
- }
- else
- {
- MetaMonitorsConfig *config;
-
- if (is_our_configuration)
- {
- MetaMonitorConfigManager *config_manager =
- meta_monitor_manager_get_config_manager (manager);
-
- config = meta_monitor_config_manager_get_current (config_manager);
- }
- else
- {
- config = NULL;
- }
-
- meta_monitor_manager_xrandr_rebuild_derived (manager, config);
- }
-
- return TRUE;
-}
diff --git a/src/backends/x11/meta-monitor-manager-xrandr.h b/src/backends/x11/meta-monitor-manager-xrandr.h
deleted file mode 100644
index d55b3d2b8..000000000
--- a/src/backends/x11/meta-monitor-manager-xrandr.h
+++ /dev/null
@@ -1,41 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2001 Havoc Pennington
- * Copyright (C) 2003 Rob Adams
- * Copyright (C) 2004-2006 Elijah Newren
- * Copyright (C) 2013 Red Hat Inc.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef META_MONITOR_MANAGER_XRANDR_H
-#define META_MONITOR_MANAGER_XRANDR_H
-
-#include <X11/extensions/Xrandr.h>
-
-#include "backends/meta-monitor-manager-private.h"
-
-#define META_TYPE_MONITOR_MANAGER_XRANDR (meta_monitor_manager_xrandr_get_type ())
-G_DECLARE_FINAL_TYPE (MetaMonitorManagerXrandr, meta_monitor_manager_xrandr,
- META, MONITOR_MANAGER_XRANDR, MetaMonitorManager)
-
-Display * meta_monitor_manager_xrandr_get_xdisplay (MetaMonitorManagerXrandr *manager_xrandr);
-
-gboolean meta_monitor_manager_xrandr_has_randr15 (MetaMonitorManagerXrandr *manager_xrandr);
-
-gboolean meta_monitor_manager_xrandr_handle_xevent (MetaMonitorManagerXrandr *manager,
- XEvent *event);
-
-#endif /* META_MONITOR_MANAGER_XRANDR_H */
diff --git a/src/backends/x11/meta-output-xrandr.c b/src/backends/x11/meta-output-xrandr.c
deleted file mode 100644
index 7265624f4..000000000
--- a/src/backends/x11/meta-output-xrandr.c
+++ /dev/null
@@ -1,987 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2001, 2002 Havoc Pennington
- * Copyright (C) 2001, 2002 Havoc Pennington
- * Copyright (C) 2002, 2003 Red Hat Inc.
- * Some ICCCM manager selection code derived from fvwm2,
- * Copyright (C) 2001 Dominik Vogt, Matthias Clasen, and fvwm2 team
- * Copyright (C) 2003 Rob Adams
- * Copyright (C) 2004-2006 Elijah Newren
- * Copyright (C) 2002, 2003 Red Hat Inc.
- * Some ICCCM manager selection code derived from fvwm2,
- * Copyright (C) 2001 Dominik Vogt, Matthias Clasen, and fvwm2 team
- * Copyright (C) 2003 Rob Adams
- * Copyright (C) 2004-2006 Elijah Newren
- * Copyright (C) 2013-2017 Red Hat Inc.
- * Copyright (C) 2020 NVIDIA CORPORATION
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-
-#include "config.h"
-
-#include "backends/x11/meta-output-xrandr.h"
-
-#include <glib.h>
-#include <string.h>
-#include <X11/Xatom.h>
-#include <X11/Xlib-xcb.h>
-#include <xcb/randr.h>
-
-#include "backends/meta-backend-private.h"
-#include "backends/meta-crtc.h"
-#include "backends/x11/meta-monitor-manager-xrandr.h"
-#include "meta/util.h"
-
-struct _MetaOutputXrandr
-{
- MetaOutput parent;
-
- gboolean ctm_initialized;
- MetaOutputCtm ctm;
-};
-
-G_DEFINE_TYPE (MetaOutputXrandr, meta_output_xrandr, META_TYPE_OUTPUT)
-
-static Display *
-xdisplay_from_gpu (MetaGpu *gpu)
-{
- MetaBackend *backend = meta_gpu_get_backend (gpu);
- MetaMonitorManager *monitor_manager =
- meta_backend_get_monitor_manager (backend);
- MetaMonitorManagerXrandr *monitor_manager_xrandr =
- META_MONITOR_MANAGER_XRANDR (monitor_manager);
-
- return meta_monitor_manager_xrandr_get_xdisplay (monitor_manager_xrandr);
-}
-
-static Display *
-xdisplay_from_output (MetaOutput *output)
-{
- return xdisplay_from_gpu (meta_output_get_gpu (output));
-}
-
-static void
-output_set_presentation_xrandr (MetaOutput *output,
- gboolean presentation)
-{
- Display *xdisplay = xdisplay_from_output (output);
- Atom atom;
- int value = presentation;
-
- atom = XInternAtom (xdisplay, "_MUTTER_PRESENTATION_OUTPUT", False);
-
- xcb_randr_change_output_property (XGetXCBConnection (xdisplay),
- (XID) meta_output_get_id (output),
- atom, XCB_ATOM_CARDINAL, 32,
- XCB_PROP_MODE_REPLACE,
- 1, &value);
-}
-
-static void
-output_set_underscanning_xrandr (MetaOutput *output,
- gboolean underscanning)
-{
- Display *xdisplay = xdisplay_from_output (output);
- Atom prop, valueatom;
- const char *value;
-
- prop = XInternAtom (xdisplay, "underscan", False);
-
- value = underscanning ? "on" : "off";
- valueatom = XInternAtom (xdisplay, value, False);
-
- xcb_randr_change_output_property (XGetXCBConnection (xdisplay),
- (XID) meta_output_get_id (output),
- prop, XCB_ATOM_ATOM, 32,
- XCB_PROP_MODE_REPLACE,
- 1, &valueatom);
-
- /* Configure the border at the same time. Currently, we use a
- * 5% of the width/height of the mode. In the future, we should
- * make the border configurable. */
- if (underscanning)
- {
- MetaCrtc *crtc;
- const MetaCrtcConfig *crtc_config;
- const MetaCrtcModeInfo *crtc_mode_info;
- uint32_t border_value;
-
- crtc = meta_output_get_assigned_crtc (output);
- crtc_config = meta_crtc_get_config (crtc);
- crtc_mode_info = meta_crtc_mode_get_info (crtc_config->mode);
-
- prop = XInternAtom (xdisplay, "underscan hborder", False);
- border_value = crtc_mode_info->width * 0.05;
-
- xcb_randr_change_output_property (XGetXCBConnection (xdisplay),
- (XID) meta_output_get_id (output),
- prop, XCB_ATOM_INTEGER, 32,
- XCB_PROP_MODE_REPLACE,
- 1, &border_value);
-
- prop = XInternAtom (xdisplay, "underscan vborder", False);
- border_value = crtc_mode_info->height * 0.05;
-
- xcb_randr_change_output_property (XGetXCBConnection (xdisplay),
- (XID) meta_output_get_id (output),
- prop, XCB_ATOM_INTEGER, 32,
- XCB_PROP_MODE_REPLACE,
- 1, &border_value);
- }
-}
-
-void
-meta_output_xrandr_apply_mode (MetaOutputXrandr *output_xrandr)
-{
- MetaOutput *output = META_OUTPUT (output_xrandr);
- Display *xdisplay = xdisplay_from_output (output);
-
- if (meta_output_is_primary (output))
- {
- XRRSetOutputPrimary (xdisplay, DefaultRootWindow (xdisplay),
- (XID) meta_output_get_id (output));
- }
-
- output_set_presentation_xrandr (output, meta_output_is_presentation (output));
-
- if (meta_output_get_info (output)->supports_underscanning)
- {
- output_set_underscanning_xrandr (output,
- meta_output_is_underscanning (output));
- }
-}
-
-static int
-normalize_backlight (MetaOutput *output,
- int hw_value)
-{
- const MetaOutputInfo *output_info = meta_output_get_info (output);
-
- return round ((double) (hw_value - output_info->backlight_min) /
- (output_info->backlight_max - output_info->backlight_min) * 100.0);
-}
-
-void
-meta_output_xrandr_change_backlight (MetaOutputXrandr *output_xrandr,
- int value)
-{
- MetaOutput *output = META_OUTPUT (output_xrandr);
- const MetaOutputInfo *output_info = meta_output_get_info (output);
- Display *xdisplay = xdisplay_from_output (output);
- Atom atom;
- int hw_value;
-
- hw_value = round ((double) value / 100.0 * output_info->backlight_max +
- output_info->backlight_min);
-
- atom = XInternAtom (xdisplay, "Backlight", False);
-
- xcb_randr_change_output_property (XGetXCBConnection (xdisplay),
- (XID) meta_output_get_id (output),
- atom, XCB_ATOM_INTEGER, 32,
- XCB_PROP_MODE_REPLACE,
- 1, &hw_value);
-
- /* We're not selecting for property notifies, so update the value immediately */
- meta_output_set_backlight (output, normalize_backlight (output, hw_value));
-}
-
-static gboolean
-ctm_is_equal (const MetaOutputCtm *ctm1,
- const MetaOutputCtm *ctm2)
-{
- int i;
-
- for (i = 0; i < 9; i++)
- {
- if (ctm1->matrix[i] != ctm2->matrix[i])
- return FALSE;
- }
-
- return TRUE;
-}
-
-void
-meta_output_xrandr_set_ctm (MetaOutputXrandr *output_xrandr,
- const MetaOutputCtm *ctm)
-{
- if (!output_xrandr->ctm_initialized ||
- !ctm_is_equal (ctm, &output_xrandr->ctm))
- {
- MetaOutput *output = META_OUTPUT (output_xrandr);
- Display *xdisplay = xdisplay_from_output (output);
- Atom ctm_atom = XInternAtom (xdisplay, "CTM", False);
-
- xcb_randr_change_output_property (XGetXCBConnection (xdisplay),
- (XID) meta_output_get_id (output),
- ctm_atom, XCB_ATOM_INTEGER, 32,
- XCB_PROP_MODE_REPLACE,
- 18, &ctm->matrix);
-
- output_xrandr->ctm = *ctm;
- output_xrandr->ctm_initialized = TRUE;
- }
-}
-
-static gboolean
-output_get_integer_property (Display *xdisplay,
- RROutput output_id,
- const char *propname,
- gint *value)
-{
- gboolean exists = FALSE;
- Atom atom, actual_type;
- int actual_format;
- unsigned long nitems, bytes_after;
- unsigned char *buffer;
-
- atom = XInternAtom (xdisplay, propname, False);
- XRRGetOutputProperty (xdisplay,
- (XID) output_id,
- atom,
- 0, G_MAXLONG, False, False, XA_INTEGER,
- &actual_type, &actual_format,
- &nitems, &bytes_after, &buffer);
-
- exists = (actual_type == XA_INTEGER && actual_format == 32 && nitems == 1);
-
- if (exists && value != NULL)
- *value = ((int*)buffer)[0];
-
- XFree (buffer);
- return exists;
-}
-
-static gboolean
-output_get_property_exists (Display *xdisplay,
- RROutput output_id,
- const char *propname)
-{
- gboolean exists = FALSE;
- Atom atom, actual_type;
- int actual_format;
- unsigned long nitems, bytes_after;
- unsigned char *buffer;
-
- atom = XInternAtom (xdisplay, propname, False);
- XRRGetOutputProperty (xdisplay,
- (XID) output_id,
- atom,
- 0, G_MAXLONG, False, False, AnyPropertyType,
- &actual_type, &actual_format,
- &nitems, &bytes_after, &buffer);
-
- exists = (actual_type != None);
-
- XFree (buffer);
- return exists;
-}
-
-static gboolean
-output_get_boolean_property (MetaOutput *output,
- const char *propname)
-{
- Display *xdisplay = xdisplay_from_output (output);
- Atom atom, actual_type;
- int actual_format;
- unsigned long nitems, bytes_after;
- g_autofree unsigned char *buffer = NULL;
-
- atom = XInternAtom (xdisplay, propname, False);
- XRRGetOutputProperty (xdisplay,
- (XID) meta_output_get_id (output),
- atom,
- 0, G_MAXLONG, False, False, XA_CARDINAL,
- &actual_type, &actual_format,
- &nitems, &bytes_after, &buffer);
-
- if (actual_type != XA_CARDINAL || actual_format != 32 || nitems < 1)
- return FALSE;
-
- return ((int*)buffer)[0];
-}
-
-static gboolean
-output_get_presentation_xrandr (MetaOutput *output)
-{
- return output_get_boolean_property (output, "_MUTTER_PRESENTATION_OUTPUT");
-}
-
-static gboolean
-output_get_underscanning_xrandr (MetaOutput *output)
-{
- Display *xdisplay = xdisplay_from_output (output);
- Atom atom, actual_type;
- int actual_format;
- unsigned long nitems, bytes_after;
- g_autofree unsigned char *buffer = NULL;
- g_autofree char *str = NULL;
-
- atom = XInternAtom (xdisplay, "underscan", False);
- XRRGetOutputProperty (xdisplay,
- (XID) meta_output_get_id (output),
- atom,
- 0, G_MAXLONG, False, False, XA_ATOM,
- &actual_type, &actual_format,
- &nitems, &bytes_after, &buffer);
-
- if (actual_type != XA_ATOM || actual_format != 32 || nitems < 1)
- return FALSE;
-
- str = XGetAtomName (xdisplay, *(Atom *)buffer);
- return (strcmp (str, "on") == 0);
-}
-
-static gboolean
-output_get_supports_underscanning_xrandr (Display *xdisplay,
- RROutput output_id)
-{
- Atom atom, actual_type;
- int actual_format, i;
- unsigned long nitems, bytes_after;
- g_autofree unsigned char *buffer = NULL;
- XRRPropertyInfo *property_info;
- Atom *values;
- gboolean supports_underscanning = FALSE;
-
- atom = XInternAtom (xdisplay, "underscan", False);
- XRRGetOutputProperty (xdisplay,
- (XID) output_id,
- atom,
- 0, G_MAXLONG, False, False, XA_ATOM,
- &actual_type, &actual_format,
- &nitems, &bytes_after, &buffer);
-
- if (actual_type != XA_ATOM || actual_format != 32 || nitems < 1)
- return FALSE;
-
- property_info = XRRQueryOutputProperty (xdisplay,
- (XID) output_id,
- atom);
- values = (Atom *) property_info->values;
-
- for (i = 0; i < property_info->num_values; i++)
- {
- /* The output supports underscanning if "on" is a valid value
- * for the underscan property.
- */
- char *name = XGetAtomName (xdisplay, values[i]);
- if (strcmp (name, "on") == 0)
- supports_underscanning = TRUE;
-
- XFree (name);
- }
-
- XFree (property_info);
-
- return supports_underscanning;
-}
-
-static gboolean
-output_get_supports_color_transform_xrandr (Display *xdisplay,
- RROutput output_id)
-{
- Atom atom, actual_type;
- int actual_format;
- unsigned long nitems, bytes_after;
- g_autofree unsigned char *buffer = NULL;
-
- atom = XInternAtom (xdisplay, "CTM", False);
- XRRGetOutputProperty (xdisplay,
- (XID) output_id,
- atom,
- 0, G_MAXLONG, False, False, XA_INTEGER,
- &actual_type, &actual_format,
- &nitems, &bytes_after, &buffer);
-
- /*
- * X's CTM property is 9 64-bit integers represented as an array of 18 32-bit
- * integers.
- */
- return (actual_type == XA_INTEGER &&
- actual_format == 32 &&
- nitems == 18);
-}
-
-static int
-output_get_backlight_xrandr (MetaOutput *output)
-{
- Display *xdisplay = xdisplay_from_output (output);
- int value = -1;
- Atom atom, actual_type;
- int actual_format;
- unsigned long nitems, bytes_after;
- g_autofree unsigned char *buffer = NULL;
-
- atom = XInternAtom (xdisplay, "Backlight", False);
- XRRGetOutputProperty (xdisplay,
- (XID) meta_output_get_id (output),
- atom,
- 0, G_MAXLONG, False, False, XA_INTEGER,
- &actual_type, &actual_format,
- &nitems, &bytes_after, &buffer);
-
- if (actual_type != XA_INTEGER || actual_format != 32 || nitems < 1)
- return FALSE;
-
- value = ((int*)buffer)[0];
- if (value > 0)
- return normalize_backlight (output, value);
- else
- return -1;
-}
-
-static void
-output_info_init_backlight_limits_xrandr (MetaOutputInfo *output_info,
- Display *xdisplay,
- xcb_randr_output_t output_id)
-{
- Atom atom;
- xcb_connection_t *xcb_conn;
- xcb_randr_query_output_property_cookie_t cookie;
- g_autofree xcb_randr_query_output_property_reply_t *reply = NULL;
-
- atom = XInternAtom (xdisplay, "Backlight", False);
-
- xcb_conn = XGetXCBConnection (xdisplay);
- cookie = xcb_randr_query_output_property (xcb_conn,
- output_id,
- (xcb_atom_t) atom);
- reply = xcb_randr_query_output_property_reply (xcb_conn,
- cookie,
- NULL);
-
- /* This can happen on systems without backlights. */
- if (reply == NULL)
- return;
-
- if (!reply->range || reply->length != 2)
- {
- meta_verbose ("backlight %s was not range", output_info->name);
- return;
- }
-
- int32_t *values = xcb_randr_query_output_property_valid_values (reply);
- output_info->backlight_min = values[0];
- output_info->backlight_max = values[1];
-}
-
-static guint8 *
-get_edid_property (Display *xdisplay,
- RROutput output,
- Atom atom,
- gsize *len)
-{
- unsigned char *prop;
- int actual_format;
- unsigned long nitems, bytes_after;
- Atom actual_type;
- guint8 *result;
-
- XRRGetOutputProperty (xdisplay, output, atom,
- 0, 100, False, False,
- AnyPropertyType,
- &actual_type, &actual_format,
- &nitems, &bytes_after, &prop);
-
- if (actual_type == XA_INTEGER && actual_format == 8)
- {
- result = g_memdup2 (prop, nitems);
- if (len)
- *len = nitems;
- }
- else
- {
- result = NULL;
- }
-
- XFree (prop);
-
- return result;
-}
-
-static GBytes *
-read_xrandr_edid (Display *xdisplay,
- RROutput output_id)
-{
- Atom edid_atom;
- guint8 *result;
- gsize len;
-
- edid_atom = XInternAtom (xdisplay, "EDID", FALSE);
- result = get_edid_property (xdisplay, output_id, edid_atom, &len);
-
- if (!result)
- {
- edid_atom = XInternAtom (xdisplay, "EDID_DATA", FALSE);
- result = get_edid_property (xdisplay, output_id, edid_atom, &len);
- }
-
- if (result)
- {
- if (len > 0 && len % 128 == 0)
- return g_bytes_new_take (result, len);
- else
- g_free (result);
- }
-
- return NULL;
-}
-
-GBytes *
-meta_output_xrandr_read_edid (MetaOutput *output)
-{
- Display *xdisplay = xdisplay_from_output (output);
- RROutput output_id = (RROutput) meta_output_get_id (output);
-
- return read_xrandr_edid (xdisplay, output_id);
-}
-
-static gboolean
-output_get_hotplug_mode_update (Display *xdisplay,
- RROutput output_id)
-{
- return output_get_property_exists (xdisplay, output_id, "hotplug_mode_update");
-}
-
-static gint
-output_get_suggested_x (Display *xdisplay,
- RROutput output_id)
-{
- gint val;
- if (output_get_integer_property (xdisplay, output_id, "suggested X", &val))
- return val;
-
- return -1;
-}
-
-static gint
-output_get_suggested_y (Display *xdisplay,
- RROutput output_id)
-{
- gint val;
- if (output_get_integer_property (xdisplay, output_id, "suggested Y", &val))
- return val;
-
- return -1;
-}
-
-static MetaConnectorType
-connector_type_from_atom (Display *xdisplay,
- Atom atom)
-{
- if (atom == XInternAtom (xdisplay, "HDMI", True))
- return META_CONNECTOR_TYPE_HDMIA;
- if (atom == XInternAtom (xdisplay, "VGA", True))
- return META_CONNECTOR_TYPE_VGA;
- /* Doesn't have a DRM equivalent, but means an internal panel.
- * We could pick either LVDS or eDP here. */
- if (atom == XInternAtom (xdisplay, "Panel", True))
- return META_CONNECTOR_TYPE_LVDS;
- if (atom == XInternAtom (xdisplay, "DVI", True) ||
- atom == XInternAtom (xdisplay, "DVI-I", True))
- return META_CONNECTOR_TYPE_DVII;
- if (atom == XInternAtom (xdisplay, "DVI-A", True))
- return META_CONNECTOR_TYPE_DVIA;
- if (atom == XInternAtom (xdisplay, "DVI-D", True))
- return META_CONNECTOR_TYPE_DVID;
- if (atom == XInternAtom (xdisplay, "DisplayPort", True))
- return META_CONNECTOR_TYPE_DisplayPort;
-
- if (atom == XInternAtom (xdisplay, "TV", True))
- return META_CONNECTOR_TYPE_TV;
- if (atom == XInternAtom (xdisplay, "TV-Composite", True))
- return META_CONNECTOR_TYPE_Composite;
- if (atom == XInternAtom (xdisplay, "TV-SVideo", True))
- return META_CONNECTOR_TYPE_SVIDEO;
- /* Another set of mismatches. */
- if (atom == XInternAtom (xdisplay, "TV-SCART", True))
- return META_CONNECTOR_TYPE_TV;
- if (atom == XInternAtom (xdisplay, "TV-C4", True))
- return META_CONNECTOR_TYPE_TV;
-
- return META_CONNECTOR_TYPE_Unknown;
-}
-
-static MetaConnectorType
-output_get_connector_type_from_prop (Display *xdisplay,
- RROutput output_id)
-{
- Atom atom, actual_type, connector_type_atom;
- int actual_format;
- unsigned long nitems, bytes_after;
- g_autofree unsigned char *buffer = NULL;
-
- atom = XInternAtom (xdisplay, "ConnectorType", False);
- XRRGetOutputProperty (xdisplay,
- (XID) output_id,
- atom,
- 0, G_MAXLONG, False, False, XA_ATOM,
- &actual_type, &actual_format,
- &nitems, &bytes_after, &buffer);
-
- if (actual_type != XA_ATOM || actual_format != 32 || nitems < 1)
- return META_CONNECTOR_TYPE_Unknown;
-
- connector_type_atom = ((Atom *) buffer)[0];
- return connector_type_from_atom (xdisplay, connector_type_atom);
-}
-
-static MetaConnectorType
-output_info_get_connector_type_from_name (const MetaOutputInfo *output_info)
-{
- const char *name = output_info->name;
-
- /* drmmode_display.c, which was copy/pasted across all the FOSS
- * xf86-video-* drivers, seems to name its outputs based on the
- * connector type, so look for that....
- *
- * SNA has its own naming scheme, because what else did you expect
- * from SNA, but it's not too different, so we can thankfully use
- * that with minor changes.
- *
- * http://cgit.freedesktop.org/xorg/xserver/tree/hw/xfree86/drivers/modesetting/drmmode_display.c#n953
- * http://cgit.freedesktop.org/xorg/driver/xf86-video-intel/tree/src/sna/sna_display.c#n3486
- */
-
- if (g_str_has_prefix (name, "DVI"))
- return META_CONNECTOR_TYPE_DVII;
- if (g_str_has_prefix (name, "LVDS"))
- return META_CONNECTOR_TYPE_LVDS;
- if (g_str_has_prefix (name, "HDMI"))
- return META_CONNECTOR_TYPE_HDMIA;
- if (g_str_has_prefix (name, "VGA"))
- return META_CONNECTOR_TYPE_VGA;
- /* SNA uses DP, not DisplayPort. Test for both. */
- if (g_str_has_prefix (name, "DP") || g_str_has_prefix (name, "DisplayPort"))
- return META_CONNECTOR_TYPE_DisplayPort;
- if (g_str_has_prefix (name, "eDP"))
- return META_CONNECTOR_TYPE_eDP;
- if (g_str_has_prefix (name, "Virtual"))
- return META_CONNECTOR_TYPE_VIRTUAL;
- if (g_str_has_prefix (name, "Composite"))
- return META_CONNECTOR_TYPE_Composite;
- if (g_str_has_prefix (name, "S-video"))
- return META_CONNECTOR_TYPE_SVIDEO;
- if (g_str_has_prefix (name, "TV"))
- return META_CONNECTOR_TYPE_TV;
- if (g_str_has_prefix (name, "CTV"))
- return META_CONNECTOR_TYPE_Composite;
- if (g_str_has_prefix (name, "DSI"))
- return META_CONNECTOR_TYPE_DSI;
- if (g_str_has_prefix (name, "DIN"))
- return META_CONNECTOR_TYPE_9PinDIN;
-
- return META_CONNECTOR_TYPE_Unknown;
-}
-
-static MetaConnectorType
-output_info_get_connector_type (MetaOutputInfo *output_info,
- Display *xdisplay,
- RROutput output_id)
-{
- MetaConnectorType ret;
-
- /* The "ConnectorType" property is considered mandatory since RandR 1.3,
- * but none of the FOSS drivers support it, because we're a bunch of
- * professional software developers.
- *
- * Try poking it first, without any expectations that it will work.
- * If it's not there, we thankfully have other bonghits to try next.
- */
- ret = output_get_connector_type_from_prop (xdisplay, output_id);
- if (ret != META_CONNECTOR_TYPE_Unknown)
- return ret;
-
- /* Fall back to heuristics based on the output name. */
- ret = output_info_get_connector_type_from_name (output_info);
- if (ret != META_CONNECTOR_TYPE_Unknown)
- return ret;
-
- return META_CONNECTOR_TYPE_Unknown;
-}
-
-static gint
-output_get_panel_orientation_transform (Display *xdisplay,
- RROutput output_id)
-{
- unsigned long nitems, bytes_after;
- Atom atom, actual_type;
- int actual_format;
- g_autofree unsigned char *buffer = NULL;
- g_autofree char *str = NULL;
-
- atom = XInternAtom (xdisplay, "panel orientation", False);
- XRRGetOutputProperty (xdisplay,
- (XID) output_id,
- atom,
- 0, G_MAXLONG, False, False, XA_ATOM,
- &actual_type, &actual_format,
- &nitems, &bytes_after, &buffer);
-
- if (actual_type != XA_ATOM || actual_format != 32 || nitems < 1)
- return META_MONITOR_TRANSFORM_NORMAL;
-
- str = XGetAtomName (xdisplay, *(Atom *)buffer);
- if (strcmp (str, "Upside Down") == 0)
- return META_MONITOR_TRANSFORM_180;
-
- if (strcmp (str, "Left Side Up") == 0)
- return META_MONITOR_TRANSFORM_90;
-
- if (strcmp (str, "Right Side Up") == 0)
- return META_MONITOR_TRANSFORM_270;
-
- return META_MONITOR_TRANSFORM_NORMAL;
-}
-
-static void
-output_info_init_tile_info (MetaOutputInfo *output_info,
- Display *xdisplay,
- RROutput output_id)
-{
- Atom tile_atom;
- unsigned char *prop;
- unsigned long nitems, bytes_after;
- int actual_format;
- Atom actual_type;
-
- tile_atom = XInternAtom (xdisplay, "TILE", FALSE);
- XRRGetOutputProperty (xdisplay,
- (XID) output_id,
- tile_atom, 0, 100, False,
- False, AnyPropertyType,
- &actual_type, &actual_format,
- &nitems, &bytes_after, &prop);
-
- if (actual_type == XA_INTEGER && actual_format == 32 && nitems == 8)
- {
- long *values = (long *)prop;
-
- output_info->tile_info.group_id = values[0];
- output_info->tile_info.flags = values[1];
- output_info->tile_info.max_h_tiles = values[2];
- output_info->tile_info.max_v_tiles = values[3];
- output_info->tile_info.loc_h_tile = values[4];
- output_info->tile_info.loc_v_tile = values[5];
- output_info->tile_info.tile_w = values[6];
- output_info->tile_info.tile_h = values[7];
- }
- XFree (prop);
-}
-
-
-static void
-output_info_init_modes (MetaOutputInfo *output_info,
- MetaGpu *gpu,
- XRROutputInfo *xrandr_output)
-{
- unsigned int i;
- unsigned int n_actual_modes;
-
- output_info->modes = g_new0 (MetaCrtcMode *, xrandr_output->nmode);
-
- n_actual_modes = 0;
- for (i = 0; i < (unsigned int) xrandr_output->nmode; i++)
- {
- GList *l;
-
- for (l = meta_gpu_get_modes (gpu); l; l = l->next)
- {
- MetaCrtcMode *mode = l->data;
-
- if (xrandr_output->modes[i] == (XID) meta_crtc_mode_get_id (mode))
- {
- output_info->modes[n_actual_modes] = mode;
- n_actual_modes += 1;
- break;
- }
- }
- }
- output_info->n_modes = n_actual_modes;
- if (n_actual_modes > 0)
- output_info->preferred_mode = output_info->modes[0];
-}
-
-static void
-output_info_init_crtcs (MetaOutputInfo *output_info,
- MetaGpu *gpu,
- XRROutputInfo *xrandr_output)
-{
- unsigned int i;
- unsigned int n_actual_crtcs;
- GList *l;
-
- output_info->possible_crtcs = g_new0 (MetaCrtc *, xrandr_output->ncrtc);
-
- n_actual_crtcs = 0;
- for (i = 0; i < (unsigned int) xrandr_output->ncrtc; i++)
- {
- for (l = meta_gpu_get_crtcs (gpu); l; l = l->next)
- {
- MetaCrtc *crtc = l->data;
-
- if ((XID) meta_crtc_get_id (crtc) == xrandr_output->crtcs[i])
- {
- output_info->possible_crtcs[n_actual_crtcs] = crtc;
- n_actual_crtcs += 1;
- break;
- }
- }
- }
- output_info->n_possible_crtcs = n_actual_crtcs;
-}
-
-static MetaCrtc *
-find_assigned_crtc (MetaGpu *gpu,
- XRROutputInfo *xrandr_output)
-{
- GList *l;
-
- for (l = meta_gpu_get_crtcs (gpu); l; l = l->next)
- {
- MetaCrtc *crtc = l->data;
-
- if ((XID) meta_crtc_get_id (crtc) == xrandr_output->crtc)
- return crtc;
- }
-
- return NULL;
-}
-
-MetaOutputXrandr *
-meta_output_xrandr_new (MetaGpuXrandr *gpu_xrandr,
- XRROutputInfo *xrandr_output,
- RROutput output_id,
- RROutput primary_output)
-{
- MetaGpu *gpu = META_GPU (gpu_xrandr);
- MetaBackend *backend = meta_gpu_get_backend (gpu);
- MetaMonitorManager *monitor_manager =
- meta_backend_get_monitor_manager (backend);
- MetaMonitorManagerXrandr *monitor_manager_xrandr =
- META_MONITOR_MANAGER_XRANDR (monitor_manager);
- Display *xdisplay =
- meta_monitor_manager_xrandr_get_xdisplay (monitor_manager_xrandr);
- g_autoptr (MetaOutputInfo) output_info = NULL;
- MetaOutput *output;
- GBytes *edid;
- MetaCrtc *assigned_crtc;
- unsigned int i;
-
- output_info = meta_output_info_new ();
-
- output_info->name = g_strdup (xrandr_output->name);
-
- edid = read_xrandr_edid (xdisplay, output_id);
- meta_output_info_parse_edid (output_info, edid);
- g_bytes_unref (edid);
-
- output_info->subpixel_order = COGL_SUBPIXEL_ORDER_UNKNOWN;
- output_info->hotplug_mode_update = output_get_hotplug_mode_update (xdisplay,
- output_id);
- output_info->suggested_x = output_get_suggested_x (xdisplay, output_id);
- output_info->suggested_y = output_get_suggested_y (xdisplay, output_id);
- output_info->connector_type = output_info_get_connector_type (output_info,
- xdisplay,
- output_id);
- output_info->panel_orientation_transform =
- output_get_panel_orientation_transform (xdisplay, output_id);
-
- if (meta_monitor_transform_is_rotated (
- output_info->panel_orientation_transform))
- {
- output_info->width_mm = xrandr_output->mm_height;
- output_info->height_mm = xrandr_output->mm_width;
- }
- else
- {
- output_info->width_mm = xrandr_output->mm_width;
- output_info->height_mm = xrandr_output->mm_height;
- }
-
- if (meta_monitor_manager_xrandr_has_randr15 (monitor_manager_xrandr))
- output_info_init_tile_info (output_info, xdisplay, output_id);
- output_info_init_modes (output_info, gpu, xrandr_output);
- output_info_init_crtcs (output_info, gpu, xrandr_output);
-
- output_info->n_possible_clones = xrandr_output->nclone;
- output_info->possible_clones = g_new0 (MetaOutput *,
- output_info->n_possible_clones);
- /*
- * We can build the list of clones now, because we don't have the list of
- * outputs yet, so temporarily set the pointers to the bare XIDs, and then
- * we'll fix them in a second pass.
- */
- for (i = 0; i < (unsigned int) xrandr_output->nclone; i++)
- {
- output_info->possible_clones[i] = GINT_TO_POINTER (xrandr_output->clones[i]);
- }
-
- output_info->supports_underscanning =
- output_get_supports_underscanning_xrandr (xdisplay, output_id);
- output_info->supports_color_transform =
- output_get_supports_color_transform_xrandr (xdisplay, output_id);
- output_info_init_backlight_limits_xrandr (output_info, xdisplay, output_id);
-
- output = g_object_new (META_TYPE_OUTPUT_XRANDR,
- "id", (uint64_t) output_id,
- "gpu", gpu_xrandr,
- "info", output_info,
- NULL);
-
- assigned_crtc = find_assigned_crtc (gpu, xrandr_output);
- if (assigned_crtc)
- {
- MetaOutputAssignment output_assignment;
-
- output_assignment = (MetaOutputAssignment) {
- .is_primary = (XID) meta_output_get_id (output) == primary_output,
- .is_presentation = output_get_presentation_xrandr (output),
- .is_underscanning = output_get_underscanning_xrandr (output),
- };
- meta_output_assign_crtc (output, assigned_crtc, &output_assignment);
- }
- else
- {
- meta_output_unassign_crtc (output);
- }
-
- if (!(output_info->backlight_min == 0 && output_info->backlight_max == 0))
- meta_output_set_backlight (output, output_get_backlight_xrandr (output));
-
- if (output_info->n_modes == 0 || output_info->n_possible_crtcs == 0)
- {
- g_object_unref (output);
- return NULL;
- }
- else
- {
- return META_OUTPUT_XRANDR (output);
- }
-}
-
-static void
-meta_output_xrandr_init (MetaOutputXrandr *output_xrandr)
-{
-}
-
-static void
-meta_output_xrandr_class_init (MetaOutputXrandrClass *klass)
-{
-}
diff --git a/src/backends/x11/meta-output-xrandr.h b/src/backends/x11/meta-output-xrandr.h
deleted file mode 100644
index ec5104f30..000000000
--- a/src/backends/x11/meta-output-xrandr.h
+++ /dev/null
@@ -1,52 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2017 Red Hat
- * Copyright (C) 2020 NVIDIA CORPORATION
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-
-#ifndef META_OUTPUT_XRANDR_H
-#define META_OUTPUT_XRANDR_H
-
-#include <X11/extensions/Xrandr.h>
-
-#include "backends/meta-output.h"
-#include "backends/x11/meta-gpu-xrandr.h"
-#include "backends/x11/meta-monitor-manager-xrandr.h"
-
-#define META_TYPE_OUTPUT_XRANDR (meta_output_xrandr_get_type ())
-G_DECLARE_FINAL_TYPE (MetaOutputXrandr, meta_output_xrandr,
- META, OUTPUT_XRANDR,
- MetaOutput)
-
-void meta_output_xrandr_apply_mode (MetaOutputXrandr *output_xrandr);
-
-void meta_output_xrandr_change_backlight (MetaOutputXrandr *output_xrandr,
- int value);
-
-void meta_output_xrandr_set_ctm (MetaOutputXrandr *output_xrandr,
- const MetaOutputCtm *ctm);
-
-GBytes * meta_output_xrandr_read_edid (MetaOutput *output_xrandr);
-
-MetaOutputXrandr * meta_output_xrandr_new (MetaGpuXrandr *gpu_xrandr,
- XRROutputInfo *xrandr_output,
- RROutput output_id,
- RROutput primary_output);
-
-#endif /* META_OUTPUT_XRANDR_H */
diff --git a/src/backends/x11/meta-renderer-x11.c b/src/backends/x11/meta-renderer-x11.c
deleted file mode 100644
index e31faff53..000000000
--- a/src/backends/x11/meta-renderer-x11.c
+++ /dev/null
@@ -1,107 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2016 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Written by:
- * Jonas Ådahl <jadahl@gmail.com>
- */
-
-#include "config.h"
-
-#include <glib-object.h>
-
-#include "backends/meta-backend-private.h"
-#include "backends/meta-logical-monitor.h"
-#include "backends/meta-renderer-view.h"
-#include "backends/meta-renderer.h"
-#include "backends/x11/meta-clutter-backend-x11.h"
-#include "backends/x11/meta-renderer-x11.h"
-#include "cogl/cogl-xlib.h"
-#include "cogl/cogl.h"
-#include "core/boxes-private.h"
-#include "meta/meta-backend.h"
-#include "meta/util.h"
-
-#ifdef COGL_HAS_EGL_SUPPORT
-#include "cogl/winsys/cogl-winsys-egl-x11-private.h"
-#endif
-#ifdef COGL_HAS_GLX_SUPPORT
-#include "cogl/winsys/cogl-winsys-glx-private.h"
-#endif
-
-G_DEFINE_TYPE (MetaRendererX11, meta_renderer_x11, META_TYPE_RENDERER)
-
-static const CoglWinsysVtable *
-get_x11_cogl_winsys_vtable (CoglRenderer *renderer)
-{
-#ifdef COGL_HAS_EGL_PLATFORM_XLIB_SUPPORT
- if (meta_is_wayland_compositor ())
- return _cogl_winsys_egl_xlib_get_vtable ();
-#endif
-
- switch (renderer->driver)
- {
- case COGL_DRIVER_GLES2:
-#ifdef COGL_HAS_EGL_PLATFORM_XLIB_SUPPORT
- return _cogl_winsys_egl_xlib_get_vtable ();
-#else
- break;
-#endif
- case COGL_DRIVER_GL:
- case COGL_DRIVER_GL3:
-#ifdef COGL_HAS_GLX_SUPPORT
- return _cogl_winsys_glx_get_vtable ();
-#else
- break;
-#endif
- case COGL_DRIVER_ANY:
- case COGL_DRIVER_NOP:
- break;
- }
- g_assert_not_reached ();
- return NULL;
-}
-
-static CoglRenderer *
-meta_renderer_x11_create_cogl_renderer (MetaRenderer *renderer)
-{
- CoglRenderer *cogl_renderer;
- Display *xdisplay = meta_clutter_x11_get_default_display ();
-
- cogl_renderer = cogl_renderer_new ();
- cogl_renderer_set_custom_winsys (cogl_renderer, get_x11_cogl_winsys_vtable,
- NULL);
- cogl_xlib_renderer_set_foreign_display (cogl_renderer, xdisplay);
- cogl_xlib_renderer_request_reset_on_video_memory_purge (cogl_renderer, TRUE);
-
- return cogl_renderer;
-}
-
-static void
-meta_renderer_x11_init (MetaRendererX11 *renderer_x11)
-{
-}
-
-static void
-meta_renderer_x11_class_init (MetaRendererX11Class *klass)
-{
- MetaRendererClass *renderer_class = META_RENDERER_CLASS (klass);
-
- renderer_class->create_cogl_renderer = meta_renderer_x11_create_cogl_renderer;
-}
diff --git a/src/backends/x11/meta-renderer-x11.h b/src/backends/x11/meta-renderer-x11.h
deleted file mode 100644
index 5ec0d4bc4..000000000
--- a/src/backends/x11/meta-renderer-x11.h
+++ /dev/null
@@ -1,42 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2016 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Written by:
- * Jonas Ådahl <jadahl@gmail.com>
- */
-
-#ifndef META_RENDERER_X11_H
-#define META_RENDERER_X11_H
-
-#include <glib-object.h>
-
-#include "backends/meta-renderer.h"
-
-struct _MetaRendererX11Class
-{
- MetaRendererClass parent_class;
-};
-
-#define META_TYPE_RENDERER_X11 (meta_renderer_x11_get_type ())
-G_DECLARE_DERIVABLE_TYPE (MetaRendererX11, meta_renderer_x11,
- META, RENDERER_X11,
- MetaRenderer)
-
-#endif /* META_RENDERER_X11_H */
diff --git a/src/backends/x11/meta-seat-x11.c b/src/backends/x11/meta-seat-x11.c
deleted file mode 100644
index 2f2637ac8..000000000
--- a/src/backends/x11/meta-seat-x11.c
+++ /dev/null
@@ -1,2422 +0,0 @@
-/*
- * Copyright (C) 2019 Red Hat Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
- *
- * Author: Carlos Garnacho <carlosg@gnome.org>
- */
-#include "config.h"
-
-#include <linux/input-event-codes.h>
-#include <X11/extensions/XInput2.h>
-#include <X11/extensions/XKB.h>
-
-#include "backends/meta-input-settings-private.h"
-#include "backends/x11/meta-backend-x11.h"
-#include "backends/x11/meta-clutter-backend-x11.h"
-#include "backends/x11/meta-event-x11.h"
-#include "backends/x11/meta-input-device-tool-x11.h"
-#include "backends/x11/meta-input-device-x11.h"
-#include "backends/x11/meta-keymap-x11.h"
-#include "backends/x11/meta-stage-x11.h"
-#include "backends/x11/meta-virtual-input-device-x11.h"
-#include "backends/x11/meta-xkb-a11y-x11.h"
-#include "clutter/clutter-mutter.h"
-#include "core/bell.h"
-#include "meta-seat-x11.h"
-
-enum
-{
- PROP_0,
- PROP_OPCODE,
- PROP_POINTER_ID,
- PROP_KEYBOARD_ID,
- N_PROPS,
-
- /* This property is overridden */
- PROP_TOUCH_MODE,
-};
-
-typedef struct _MetaTouchInfo MetaTouchInfo;
-
-struct _MetaTouchInfo
-{
- ClutterEventSequence *sequence;
- double x;
- double y;
-};
-
-struct _MetaSeatX11
-{
- ClutterSeat parent_instance;
- ClutterInputDevice *core_pointer;
- ClutterInputDevice *core_keyboard;
- GList *devices;
- GHashTable *devices_by_id;
- GHashTable *tools_by_serial;
- GHashTable *touch_coords;
- MetaKeymapX11 *keymap;
-
- int pointer_id;
- int keyboard_id;
- int opcode;
- guint has_touchscreens : 1;
- guint touch_mode : 1;
- guint has_pointer_focus : 1;
-};
-
-static GParamSpec *props[N_PROPS] = { 0 };
-
-G_DEFINE_TYPE (MetaSeatX11, meta_seat_x11, CLUTTER_TYPE_SEAT)
-
-static const char *clutter_input_axis_atom_names[] = {
- "Abs X", /* CLUTTER_INPUT_AXIS_X */
- "Abs Y", /* CLUTTER_INPUT_AXIS_Y */
- "Abs Pressure", /* CLUTTER_INPUT_AXIS_PRESSURE */
- "Abs Tilt X", /* CLUTTER_INPUT_AXIS_XTILT */
- "Abs Tilt Y", /* CLUTTER_INPUT_AXIS_YTILT */
- "Abs Wheel", /* CLUTTER_INPUT_AXIS_WHEEL */
- "Abs Distance", /* CLUTTER_INPUT_AXIS_DISTANCE */
-};
-
-static const char *wacom_type_atoms[] = {
- "STYLUS",
- "CURSOR",
- "ERASER",
- "PAD",
- "TOUCH"
-};
-#define N_WACOM_TYPE_ATOMS G_N_ELEMENTS (wacom_type_atoms)
-
-enum
-{
- WACOM_TYPE_STYLUS,
- WACOM_TYPE_CURSOR,
- WACOM_TYPE_ERASER,
- WACOM_TYPE_PAD,
- WACOM_TYPE_TOUCH,
-};
-
-enum
-{
- PAD_AXIS_FIRST = 3, /* First axes are always x/y/pressure, ignored in pads */
- PAD_AXIS_STRIP1 = PAD_AXIS_FIRST,
- PAD_AXIS_STRIP2,
- PAD_AXIS_RING1,
- PAD_AXIS_RING2,
-};
-
-#define N_AXIS_ATOMS G_N_ELEMENTS (clutter_input_axis_atom_names)
-
-static Atom clutter_input_axis_atoms[N_AXIS_ATOMS] = { 0, };
-
-static void
-translate_valuator_class (Display *xdisplay,
- ClutterInputDevice *device,
- XIValuatorClassInfo *class)
-{
- static gboolean atoms_initialized = FALSE;
- ClutterInputAxis i, axis = CLUTTER_INPUT_AXIS_IGNORE;
-
- if (G_UNLIKELY (!atoms_initialized))
- {
- XInternAtoms (xdisplay,
- (char **) clutter_input_axis_atom_names, N_AXIS_ATOMS,
- False,
- clutter_input_axis_atoms);
-
- atoms_initialized = TRUE;
- }
-
- for (i = 0;
- i < N_AXIS_ATOMS;
- i += 1)
- {
- if (clutter_input_axis_atoms[i] == class->label)
- {
- axis = i + 1;
- break;
- }
- }
-
- meta_input_device_x11_add_axis (device, axis,
- class->min,
- class->max,
- class->resolution);
-
- g_debug ("Added axis '%s' (min:%.2f, max:%.2fd, res:%d) of device %d",
- clutter_input_axis_atom_names[axis],
- class->min,
- class->max,
- class->resolution,
- meta_input_device_x11_get_device_id (device));
-}
-
-static void
-translate_device_classes (Display *xdisplay,
- ClutterInputDevice *device,
- XIAnyClassInfo **classes,
- int n_classes)
-{
- int i;
-
- for (i = 0; i < n_classes; i++)
- {
- XIAnyClassInfo *class_info = classes[i];
-
- switch (class_info->type)
- {
- case XIValuatorClass:
- translate_valuator_class (xdisplay, device,
- (XIValuatorClassInfo *) class_info);
- break;
-
- case XIScrollClass:
- {
- XIScrollClassInfo *scroll_info = (XIScrollClassInfo *) class_info;
- ClutterScrollDirection direction;
-
- if (scroll_info->scroll_type == XIScrollTypeVertical)
- direction = CLUTTER_SCROLL_DOWN;
- else
- direction = CLUTTER_SCROLL_RIGHT;
-
- g_debug ("Scroll valuator %d: %s, increment: %f",
- scroll_info->number,
- scroll_info->scroll_type == XIScrollTypeVertical
- ? "vertical"
- : "horizontal",
- scroll_info->increment);
-
- meta_input_device_x11_add_scroll_info (device,
- scroll_info->number,
- direction,
- scroll_info->increment);
- }
- break;
-
- default:
- break;
- }
- }
-}
-
-static gboolean
-is_touch_device (XIAnyClassInfo **classes,
- int n_classes,
- ClutterInputDeviceType *device_type,
- uint32_t *n_touch_points)
-{
- int i;
-
- for (i = 0; i < n_classes; i++)
- {
- XITouchClassInfo *class = (XITouchClassInfo *) classes[i];
-
- if (class->type != XITouchClass)
- continue;
-
- if (class->num_touches > 0)
- {
- if (class->mode == XIDirectTouch)
- *device_type = CLUTTER_TOUCHSCREEN_DEVICE;
- else if (class->mode == XIDependentTouch)
- *device_type = CLUTTER_TOUCHPAD_DEVICE;
- else
- continue;
-
- *n_touch_points = class->num_touches;
-
- return TRUE;
- }
- }
-
- return FALSE;
-}
-
-static gboolean
-is_touchpad_device (XIDeviceInfo *info)
-{
- gulong nitems, bytes_after;
- uint32_t *data = NULL;
- int rc, format;
- Atom type;
- Atom prop;
-
- prop = XInternAtom (meta_clutter_x11_get_default_display (),
- "libinput Tapping Enabled", True);
- if (prop == None)
- return FALSE;
-
- meta_clutter_x11_trap_x_errors ();
- rc = XIGetProperty (meta_clutter_x11_get_default_display (),
- info->deviceid,
- prop,
- 0, 1, False, XA_INTEGER, &type, &format, &nitems, &bytes_after,
- (guchar **) &data);
- meta_clutter_x11_untrap_x_errors ();
-
- /* We don't care about the data */
- XFree (data);
-
- if (rc != Success || type != XA_INTEGER || format != 8 || nitems != 1)
- return FALSE;
-
- return TRUE;
-}
-
-static gboolean
-get_device_ids (XIDeviceInfo *info,
- char **vendor_id,
- char **product_id)
-{
- gulong nitems, bytes_after;
- uint32_t *data = NULL;
- int rc, format;
- Atom type;
-
- meta_clutter_x11_trap_x_errors ();
- rc = XIGetProperty (meta_clutter_x11_get_default_display (),
- info->deviceid,
- XInternAtom (meta_clutter_x11_get_default_display (), "Device Product ID", False),
- 0, 2, False, XA_INTEGER, &type, &format, &nitems, &bytes_after,
- (guchar **) &data);
- meta_clutter_x11_untrap_x_errors ();
-
- if (rc != Success || type != XA_INTEGER || format != 32 || nitems != 2)
- {
- XFree (data);
- return FALSE;
- }
-
- if (vendor_id)
- *vendor_id = g_strdup_printf ("%.4x", data[0]);
- if (product_id)
- *product_id = g_strdup_printf ("%.4x", data[1]);
-
- XFree (data);
-
- return TRUE;
-}
-
-static char *
-get_device_node_path (XIDeviceInfo *info)
-{
- gulong nitems, bytes_after;
- guchar *data;
- int rc, format;
- Atom prop, type;
- char *node_path;
-
- prop = XInternAtom (meta_clutter_x11_get_default_display (), "Device Node", False);
- if (prop == None)
- return NULL;
-
- meta_clutter_x11_trap_x_errors ();
-
- rc = XIGetProperty (meta_clutter_x11_get_default_display (),
- info->deviceid, prop, 0, 1024, False,
- XA_STRING, &type, &format, &nitems, &bytes_after,
- (guchar **) &data);
-
- if (meta_clutter_x11_untrap_x_errors ())
- return NULL;
-
- if (rc != Success || type != XA_STRING || format != 8)
- {
- XFree (data);
- return FALSE;
- }
-
- node_path = g_strdup ((char *) data);
- XFree (data);
-
- return node_path;
-}
-
-static void
-get_pad_features (XIDeviceInfo *info,
- uint32_t *n_rings,
- uint32_t *n_strips)
-{
- int i, rings = 0, strips = 0;
-
- for (i = PAD_AXIS_FIRST; i < info->num_classes; i++)
- {
- XIValuatorClassInfo *valuator = (XIValuatorClassInfo*) info->classes[i];
- int axis = valuator->number;
-
- if (valuator->type != XIValuatorClass)
- continue;
- if (valuator->max <= 1)
- continue;
-
- /* Ring/strip axes are fixed in pad devices as handled by the
- * wacom driver. Match those to detect pad features.
- */
- if (axis == PAD_AXIS_STRIP1 || axis == PAD_AXIS_STRIP2)
- strips++;
- else if (axis == PAD_AXIS_RING1 || axis == PAD_AXIS_RING2)
- rings++;
- }
-
- *n_rings = rings;
- *n_strips = strips;
-}
-
-/* The Wacom driver exports the tool type as property. Use that over
- guessing based on the device name */
-static gboolean
-guess_source_from_wacom_type (XIDeviceInfo *info,
- ClutterInputDeviceType *source_out)
-{
- gulong nitems, bytes_after;
- uint32_t *data = NULL;
- int rc, format;
- Atom type;
- Atom prop;
- Atom device_type;
- Atom types[N_WACOM_TYPE_ATOMS];
-
- prop = XInternAtom (meta_clutter_x11_get_default_display (), "Wacom Tool Type", True);
- if (prop == None)
- return FALSE;
-
- meta_clutter_x11_trap_x_errors ();
- rc = XIGetProperty (meta_clutter_x11_get_default_display (),
- info->deviceid,
- prop,
- 0, 1, False, XA_ATOM, &type, &format, &nitems, &bytes_after,
- (guchar **) &data);
- meta_clutter_x11_untrap_x_errors ();
-
- if (rc != Success || type != XA_ATOM || format != 32 || nitems != 1)
- {
- XFree (data);
- return FALSE;
- }
-
- device_type = *data;
- XFree (data);
-
- if (device_type == 0)
- return FALSE;
-
- rc = XInternAtoms (meta_clutter_x11_get_default_display (),
- (char **)wacom_type_atoms,
- N_WACOM_TYPE_ATOMS,
- False,
- types);
- if (rc == 0)
- return FALSE;
-
- if (device_type == types[WACOM_TYPE_STYLUS])
- {
- *source_out = CLUTTER_PEN_DEVICE;
- }
- else if (device_type == types[WACOM_TYPE_CURSOR])
- {
- *source_out = CLUTTER_CURSOR_DEVICE;
- }
- else if (device_type == types[WACOM_TYPE_ERASER])
- {
- *source_out = CLUTTER_ERASER_DEVICE;
- }
- else if (device_type == types[WACOM_TYPE_PAD])
- {
- *source_out = CLUTTER_PAD_DEVICE;
- }
- else if (device_type == types[WACOM_TYPE_TOUCH])
- {
- uint32_t num_touches = 0;
-
- if (!is_touch_device (info->classes, info->num_classes,
- source_out, &num_touches))
- *source_out = CLUTTER_TOUCHSCREEN_DEVICE;
- }
- else
- {
- return FALSE;
- }
-
- return TRUE;
-}
-
-static ClutterInputDevice *
-create_device (MetaSeatX11 *seat_x11,
- ClutterBackend *backend,
- XIDeviceInfo *info)
-{
- ClutterInputDeviceType source, touch_source;
- ClutterInputDevice *retval;
- ClutterInputMode mode;
- uint32_t num_touches = 0, num_rings = 0, num_strips = 0;
- char *vendor_id = NULL, *product_id = NULL, *node_path = NULL;
-
- if (info->use == XIMasterKeyboard || info->use == XISlaveKeyboard)
- {
- source = CLUTTER_KEYBOARD_DEVICE;
- }
- else if (is_touchpad_device (info))
- {
- source = CLUTTER_TOUCHPAD_DEVICE;
- }
- else if (info->use == XISlavePointer &&
- is_touch_device (info->classes, info->num_classes,
- &touch_source,
- &num_touches))
- {
- source = touch_source;
- }
- else if (!guess_source_from_wacom_type (info, &source))
- {
- char *name;
-
- name = g_ascii_strdown (info->name, -1);
-
- if (strstr (name, "eraser") != NULL)
- source = CLUTTER_ERASER_DEVICE;
- else if (strstr (name, "cursor") != NULL)
- source = CLUTTER_CURSOR_DEVICE;
- else if (strstr (name, " pad") != NULL)
- source = CLUTTER_PAD_DEVICE;
- else if (strstr (name, "wacom") != NULL || strstr (name, "pen") != NULL)
- source = CLUTTER_PEN_DEVICE;
- else if (strstr (name, "touchpad") != NULL)
- source = CLUTTER_TOUCHPAD_DEVICE;
- else
- source = CLUTTER_POINTER_DEVICE;
-
- g_free (name);
- }
-
- switch (info->use)
- {
- case XIMasterKeyboard:
- case XIMasterPointer:
- mode = CLUTTER_INPUT_MODE_LOGICAL;
- break;
-
- case XISlaveKeyboard:
- case XISlavePointer:
- mode = CLUTTER_INPUT_MODE_PHYSICAL;
- break;
-
- case XIFloatingSlave:
- default:
- mode = CLUTTER_INPUT_MODE_FLOATING;
- break;
- }
-
- if (info->use != XIMasterKeyboard &&
- info->use != XIMasterPointer)
- {
- get_device_ids (info, &vendor_id, &product_id);
- node_path = get_device_node_path (info);
- }
-
- if (source == CLUTTER_PAD_DEVICE)
- get_pad_features (info, &num_rings, &num_strips);
-
- retval = g_object_new (META_TYPE_INPUT_DEVICE_X11,
- "name", info->name,
- "id", info->deviceid,
- "has-cursor", (info->use == XIMasterPointer),
- "device-type", source,
- "device-mode", mode,
- "backend", backend,
- "vendor-id", vendor_id,
- "product-id", product_id,
- "device-node", node_path,
- "n-rings", num_rings,
- "n-strips", num_strips,
- "n-mode-groups", MAX (num_rings, num_strips),
- "seat", seat_x11,
- NULL);
-
- translate_device_classes (meta_clutter_x11_get_default_display (), retval,
- info->classes,
- info->num_classes);
-
- g_free (vendor_id);
- g_free (product_id);
- g_free (node_path);
-
- g_debug ("Created device '%s' (id: %d, has-cursor: %s)",
- info->name,
- info->deviceid,
- info->use == XIMasterPointer ? "yes" : "no");
-
- return retval;
-}
-
-static void
-pad_passive_button_grab (ClutterInputDevice *device)
-{
- XIGrabModifiers xi_grab_mods = { XIAnyModifier, };
- XIEventMask xi_event_mask;
- int device_id, rc;
-
- device_id = meta_input_device_x11_get_device_id (device);
-
- xi_event_mask.deviceid = device_id;
- xi_event_mask.mask_len = XIMaskLen (XI_LASTEVENT);
- xi_event_mask.mask = g_new0 (unsigned char, xi_event_mask.mask_len);
-
- XISetMask (xi_event_mask.mask, XI_Motion);
- XISetMask (xi_event_mask.mask, XI_ButtonPress);
- XISetMask (xi_event_mask.mask, XI_ButtonRelease);
-
- meta_clutter_x11_trap_x_errors ();
- rc = XIGrabButton (meta_clutter_x11_get_default_display (),
- device_id, XIAnyButton,
- meta_clutter_x11_get_root_window (), None,
- XIGrabModeSync, XIGrabModeSync,
- True, &xi_event_mask, 1, &xi_grab_mods);
- if (rc != 0)
- {
- g_warning ("Could not passively grab pad device: %s",
- clutter_input_device_get_device_name (device));
- }
- else
- {
- XIAllowEvents (meta_clutter_x11_get_default_display (),
- device_id, XIAsyncDevice,
- CLUTTER_CURRENT_TIME);
- }
-
- meta_clutter_x11_untrap_x_errors ();
-
- g_free (xi_event_mask.mask);
-}
-
-static void
-update_touch_mode (MetaSeatX11 *seat_x11)
-{
- gboolean touch_mode;
-
- touch_mode = seat_x11->has_touchscreens;
-
- if (seat_x11->touch_mode == touch_mode)
- return;
-
- seat_x11->touch_mode = touch_mode;
- g_object_notify (G_OBJECT (seat_x11), "touch-mode");
-}
-
-static ClutterInputDevice *
-add_device (MetaSeatX11 *seat_x11,
- ClutterBackend *backend,
- XIDeviceInfo *info)
-{
- ClutterInputDevice *device;
-
- device = create_device (seat_x11, backend, info);
-
- g_hash_table_replace (seat_x11->devices_by_id,
- GINT_TO_POINTER (info->deviceid),
- device);
-
- if (info->use == XIMasterPointer &&
- info->deviceid == seat_x11->pointer_id)
- {
- seat_x11->core_pointer = device;
- }
- else if (info->use == XIMasterKeyboard &&
- info->deviceid == seat_x11->keyboard_id)
- {
- seat_x11->core_keyboard = device;
- }
- else if ((info->use == XISlavePointer &&
- info->attachment == seat_x11->pointer_id) ||
- (info->use == XISlaveKeyboard &&
- info->attachment == seat_x11->keyboard_id))
- {
- seat_x11->devices = g_list_prepend (seat_x11->devices, device);
- }
- else
- {
- g_warning ("Unhandled device: %s",
- clutter_input_device_get_device_name (device));
- }
-
- if (clutter_input_device_get_device_type (device) == CLUTTER_PAD_DEVICE)
- pad_passive_button_grab (device);
-
- return device;
-}
-
-static gboolean
-has_touchscreens (MetaSeatX11 *seat_x11)
-{
- GList *l;
-
- for (l = seat_x11->devices; l; l = l->next)
- {
- if (clutter_input_device_get_device_type (l->data) == CLUTTER_TOUCHSCREEN_DEVICE)
- return TRUE;
- }
-
- return FALSE;
-}
-
-static void
-remove_device (MetaSeatX11 *seat_x11,
- ClutterInputDevice *device)
-{
- if (seat_x11->core_pointer == device)
- {
- seat_x11->core_pointer = NULL;
- }
- else if (seat_x11->core_keyboard == device)
- {
- seat_x11->core_keyboard = NULL;
- }
- else
- {
- seat_x11->devices = g_list_remove (seat_x11->devices, device);
- }
-}
-
-static gboolean
-meta_seat_x11_handle_event_post (ClutterSeat *seat,
- const ClutterEvent *event)
-{
- MetaSeatX11 *seat_x11 = META_SEAT_X11 (seat);
- ClutterInputDevice *device;
- MetaInputSettings *input_settings;
- gboolean is_touch;
-
- if (event->type != CLUTTER_DEVICE_ADDED &&
- event->type != CLUTTER_DEVICE_REMOVED)
- return TRUE;
-
- device = clutter_event_get_device (event);
- is_touch =
- clutter_input_device_get_device_type (device) == CLUTTER_TOUCHSCREEN_DEVICE;
- input_settings = meta_backend_get_input_settings (meta_get_backend ());
-
- switch (event->type)
- {
- case CLUTTER_DEVICE_ADDED:
- meta_input_settings_add_device (input_settings, device);
- seat_x11->has_touchscreens |= is_touch;
- break;
- case CLUTTER_DEVICE_REMOVED:
- if (is_touch)
- seat_x11->has_touchscreens = has_touchscreens (seat_x11);
- meta_input_settings_remove_device (input_settings, device);
- break;
- default:
- break;
- }
-
- if (is_touch)
- update_touch_mode (seat_x11);
-
- return TRUE;
-}
-
-static uint
-device_get_tool_serial (ClutterInputDevice *device)
-{
- gulong nitems, bytes_after;
- uint32_t *data = NULL;
- int serial_id = 0;
- int rc, format;
- Atom type;
- Atom prop;
-
- prop = XInternAtom (meta_clutter_x11_get_default_display (),
- "Wacom Serial IDs", True);
- if (prop == None)
- return 0;
-
- meta_clutter_x11_trap_x_errors ();
- rc = XIGetProperty (meta_clutter_x11_get_default_display (),
- meta_input_device_x11_get_device_id (device),
- prop, 0, 4, FALSE, XA_INTEGER, &type, &format, &nitems, &bytes_after,
- (guchar **) &data);
- meta_clutter_x11_untrap_x_errors ();
-
- if (rc == Success && type == XA_INTEGER && format == 32 && nitems >= 4)
- serial_id = data[3];
-
- XFree (data);
-
- return serial_id;
-}
-
-static gboolean
-translate_hierarchy_event (ClutterBackend *backend,
- MetaSeatX11 *seat_x11,
- XIHierarchyEvent *ev,
- ClutterEvent *event)
-{
- int i;
- gboolean retval = FALSE;
-
- for (i = 0; i < ev->num_info; i++)
- {
- if (ev->info[i].flags & XIDeviceEnabled &&
- !g_hash_table_lookup (seat_x11->devices_by_id,
- GINT_TO_POINTER (ev->info[i].deviceid)))
- {
- XIDeviceInfo *info;
- int n_devices;
-
- g_debug ("Hierarchy event: device enabled");
-
- meta_clutter_x11_trap_x_errors ();
- info = XIQueryDevice (meta_clutter_x11_get_default_display (),
- ev->info[i].deviceid,
- &n_devices);
- meta_clutter_x11_untrap_x_errors ();
- if (info != NULL)
- {
- ClutterInputDevice *device;
-
- device = add_device (seat_x11, backend, &info[0]);
-
- event->any.type = CLUTTER_DEVICE_ADDED;
- event->any.time = ev->time;
- clutter_event_set_device (event, device);
-
- retval = TRUE;
- XIFreeDeviceInfo (info);
- }
- }
- else if (ev->info[i].flags & XIDeviceDisabled)
- {
- g_autoptr (ClutterInputDevice) device = NULL;
- g_debug ("Hierarchy event: device disabled");
-
- g_hash_table_steal_extended (seat_x11->devices_by_id,
- GINT_TO_POINTER (ev->info[i].deviceid),
- NULL,
- (gpointer) &device);
-
- if (device != NULL)
- {
- remove_device (seat_x11, device);
-
- event->any.type = CLUTTER_DEVICE_REMOVED;
- event->any.time = ev->time;
- clutter_event_set_device (event, device);
-
- retval = TRUE;
- }
- }
- else if ((ev->info[i].flags & XISlaveAttached) ||
- (ev->info[i].flags & XISlaveDetached))
- {
- g_debug ("Hierarchy event: physical device %s",
- (ev->info[i].flags & XISlaveAttached)
- ? "attached"
- : "detached");
- }
- }
-
- return retval;
-}
-
-static void
-translate_property_event (MetaSeatX11 *seat_x11,
- XIEvent *event)
-{
- XIPropertyEvent *xev = (XIPropertyEvent *) event;
- Atom serial_ids_prop;
- ClutterInputDevice *device;
-
- serial_ids_prop = XInternAtom (meta_clutter_x11_get_default_display (),
- "Wacom Serial IDs", True);
- if (serial_ids_prop == None)
- return;
-
- device = g_hash_table_lookup (seat_x11->devices_by_id,
- GINT_TO_POINTER (xev->deviceid));
- if (!device)
- return;
-
- if (xev->property == serial_ids_prop)
- {
- ClutterInputDeviceTool *tool = NULL;
- ClutterInputDeviceToolType type;
- MetaInputSettings *input_settings;
- int serial_id;
-
- serial_id = device_get_tool_serial (device);
-
- if (serial_id != 0)
- {
- tool = g_hash_table_lookup (seat_x11->tools_by_serial,
- GUINT_TO_POINTER (serial_id));
- if (!tool)
- {
- type = clutter_input_device_get_device_type (device) == CLUTTER_ERASER_DEVICE ?
- CLUTTER_INPUT_DEVICE_TOOL_ERASER : CLUTTER_INPUT_DEVICE_TOOL_PEN;
- tool = meta_input_device_tool_x11_new (serial_id, type);
- g_hash_table_insert (seat_x11->tools_by_serial,
- GUINT_TO_POINTER (serial_id),
- tool);
- }
- }
-
- meta_input_device_x11_update_tool (device, tool);
- input_settings = meta_backend_get_input_settings (meta_get_backend ());
- meta_input_settings_notify_tool_change (input_settings, device, tool);
- }
-}
-
-static void
-emulate_motion (MetaSeatX11 *seat_x11,
- double x,
- double y)
-{
- ClutterInputDevice *pointer;
- ClutterEvent *event;
- ClutterStage *stage;
-
- pointer = clutter_seat_get_pointer (CLUTTER_SEAT (seat_x11));
- stage = CLUTTER_STAGE (meta_backend_get_stage (meta_get_backend ()));
-
- event = clutter_event_new (CLUTTER_MOTION);
- clutter_event_set_flags (event, CLUTTER_EVENT_FLAG_SYNTHETIC);
- clutter_event_set_coords (event, x, y);
- clutter_event_set_device (event, pointer);
- clutter_event_set_source_device (event, NULL);
- clutter_event_set_stage (event, stage);
-
- clutter_event_put (event);
- clutter_event_free (event);
-}
-
-static void
-translate_raw_event (MetaSeatX11 *seat_x11,
- XEvent *xevent)
-{
- ClutterInputDevice *device;
- XGenericEventCookie *cookie;
- XIEvent *xi_event;
- XIRawEvent *xev;
- float x,y;
-
- cookie = &xevent->xcookie;
- xi_event = (XIEvent *) cookie->data;
- xev = (XIRawEvent *) xi_event;
-
- device = g_hash_table_lookup (seat_x11->devices_by_id,
- GINT_TO_POINTER (xev->deviceid));
- if (device == NULL)
- return;
-
- switch (cookie->evtype)
- {
- case XI_RawMotion:
- g_debug ("raw motion: device:%d '%s'",
- meta_input_device_x11_get_device_id (device),
- clutter_input_device_get_device_name (device));
-
- /* We don't get actual pointer location with raw events, and we cannot
- * rely on `clutter_input_device_get_coords()` either because of
- * unreparented toplevels (like all client-side decoration windows),
- * so we need to explicitly query the pointer here...
- */
- if (meta_input_device_x11_get_pointer_location (device, &x, &y))
- {
- if (_clutter_is_input_pointer_a11y_enabled (device))
- _clutter_input_pointer_a11y_on_motion_event (device, x, y);
- if (!seat_x11->has_pointer_focus)
- emulate_motion (seat_x11, x, y);
- }
- break;
- case XI_RawButtonPress:
- case XI_RawButtonRelease:
- g_debug ("raw button %s: device:%d '%s' button %i",
- cookie->evtype == XI_RawButtonPress
- ? "press "
- : "release",
- meta_input_device_x11_get_device_id (device),
- clutter_input_device_get_device_name (device),
- xev->detail);
- if (_clutter_is_input_pointer_a11y_enabled (device))
- {
- _clutter_input_pointer_a11y_on_button_event (device,
- xev->detail,
- (cookie->evtype == XI_RawButtonPress));
- }
- break;
- }
-}
-
-static gboolean
-translate_pad_axis (ClutterInputDevice *device,
- XIValuatorState *valuators,
- ClutterEventType *evtype,
- uint32_t *number,
- double *value)
-{
- double *values;
- int i;
-
- values = valuators->values;
-
- for (i = PAD_AXIS_FIRST; i < valuators->mask_len * 8; i++)
- {
- double val;
- uint32_t axis_number = 0;
-
- if (!XIMaskIsSet (valuators->mask, i))
- continue;
-
- val = *values++;
- if (val <= 0)
- continue;
-
- meta_input_device_x11_translate_axis (device, i, val, value);
-
- if (i == PAD_AXIS_RING1 || i == PAD_AXIS_RING2)
- {
- *evtype = CLUTTER_PAD_RING;
- (*value) *= 360.0;
- }
- else if (i == PAD_AXIS_STRIP1 || i == PAD_AXIS_STRIP2)
- {
- *evtype = CLUTTER_PAD_STRIP;
- }
- else
- continue;
-
- if (i == PAD_AXIS_STRIP2 || i == PAD_AXIS_RING2)
- axis_number++;
-
- *number = axis_number;
- return TRUE;
- }
-
- return FALSE;
-}
-
-static gboolean
-translate_pad_event (ClutterEvent *event,
- XIDeviceEvent *xev,
- ClutterInputDevice *device)
-{
- double value;
- uint32_t number, mode = 0;
-
- if (!translate_pad_axis (device, &xev->valuators,
- &event->any.type,
- &number, &value))
- return FALSE;
-
- /* When touching a ring/strip a first XI_Motion event
- * is generated. Use it to reset the pad state, so
- * later events actually have a directionality.
- */
- if (xev->evtype == XI_Motion)
- value = -1;
-
-#ifdef HAVE_LIBWACOM
- mode = meta_input_device_x11_get_pad_group_mode (device, number);
-#endif
-
- if (event->any.type == CLUTTER_PAD_RING)
- {
- event->pad_ring.ring_number = number;
- event->pad_ring.angle = value;
- event->pad_ring.mode = mode;
- }
- else
- {
- event->pad_strip.strip_number = number;
- event->pad_strip.value = value;
- event->pad_strip.mode = mode;
- }
-
- event->any.time = xev->time;
- clutter_event_set_device (event, device);
- clutter_event_set_source_device (event, device);
-
- g_debug ("%s: win:0x%x, device:%d '%s', time:%d "
- "(value:%f)",
- event->any.type == CLUTTER_PAD_RING
- ? "pad ring "
- : "pad strip",
- (unsigned int) xev->event,
- meta_input_device_x11_get_device_id (device),
- clutter_input_device_get_device_name (device),
- event->any.time, value);
-
- return TRUE;
-}
-
-static ClutterStage *
-get_event_stage (MetaSeatX11 *seat_x11,
- XIEvent *xi_event)
-{
- Window xwindow = None;
-
- switch (xi_event->evtype)
- {
- case XI_KeyPress:
- case XI_KeyRelease:
- case XI_ButtonPress:
- case XI_ButtonRelease:
- case XI_Motion:
- case XI_TouchBegin:
- case XI_TouchUpdate:
- case XI_TouchEnd:
- {
- XIDeviceEvent *xev = (XIDeviceEvent *) xi_event;
-
- xwindow = xev->event;
- }
- break;
-
- case XI_Enter:
- case XI_Leave:
- case XI_FocusIn:
- case XI_FocusOut:
- {
- XIEnterEvent *xev = (XIEnterEvent *) xi_event;
-
- xwindow = xev->event;
- }
- break;
-
- case XI_HierarchyChanged:
- return CLUTTER_STAGE (meta_backend_get_stage (meta_get_backend ()));
-
- default:
- break;
- }
-
- if (xwindow == None)
- return NULL;
-
- return meta_x11_get_stage_from_window (xwindow);
-}
-
-/*
- * print_key_sym: Translate a symbol to its printable form if any
- * @symbol: the symbol to translate
- * @buffer: the buffer where to put the translated string
- * @len: size of the buffer
- *
- * Translates @symbol into a printable representation in @buffer, if possible.
- *
- * Return value: The number of bytes of the translated string, 0 if the
- * symbol can't be printed
- *
- * Note: The code is derived from libX11's src/KeyBind.c
- * Copyright 1985, 1987, 1998 The Open Group
- *
- * Note: This code works for Latin-1 symbols. clutter_keysym_to_unicode()
- * does the work for the other keysyms.
- */
-static int
-print_keysym (uint32_t symbol,
- char *buffer,
- int len)
-{
- unsigned long high_bytes;
- unsigned char c;
-
- high_bytes = symbol >> 8;
- if (!(len &&
- ((high_bytes == 0) ||
- ((high_bytes == 0xFF) &&
- (((symbol >= CLUTTER_KEY_BackSpace) &&
- (symbol <= CLUTTER_KEY_Clear)) ||
- (symbol == CLUTTER_KEY_Return) ||
- (symbol == CLUTTER_KEY_Escape) ||
- (symbol == CLUTTER_KEY_KP_Space) ||
- (symbol == CLUTTER_KEY_KP_Tab) ||
- (symbol == CLUTTER_KEY_KP_Enter) ||
- ((symbol >= CLUTTER_KEY_KP_Multiply) &&
- (symbol <= CLUTTER_KEY_KP_9)) ||
- (symbol == CLUTTER_KEY_KP_Equal) ||
- (symbol == CLUTTER_KEY_Delete))))))
- return 0;
-
- /* if X keysym, convert to ascii by grabbing low 7 bits */
- if (symbol == CLUTTER_KEY_KP_Space)
- c = CLUTTER_KEY_space & 0x7F; /* patch encoding botch */
- else if (high_bytes == 0xFF)
- c = symbol & 0x7F;
- else
- c = symbol & 0xFF;
-
- buffer[0] = c;
- return 1;
-}
-
-static double *
-translate_axes (ClutterInputDevice *device,
- double x,
- double y,
- XIValuatorState *valuators)
-{
- uint32_t i;
- double *retval;
- double *values;
-
- retval = g_new0 (double, CLUTTER_INPUT_AXIS_LAST);
- values = valuators->values;
-
- for (i = 0; i < valuators->mask_len * 8; i++)
- {
- ClutterInputAxis axis;
- double val;
-
- if (!XIMaskIsSet (valuators->mask, i))
- continue;
- if (!meta_input_device_x11_get_axis (device, i, &axis))
- continue;
-
- val = *values++;
-
- switch (axis)
- {
- case CLUTTER_INPUT_AXIS_X:
- retval[axis] = x;
- break;
-
- case CLUTTER_INPUT_AXIS_Y:
- retval[axis] = y;
- break;
-
- default:
- meta_input_device_x11_translate_axis (device, i, val, &retval[axis]);
- break;
- }
- }
-
- return retval;
-}
-
-static double
-scroll_valuators_changed (ClutterInputDevice *device,
- XIValuatorState *valuators,
- double *dx_p,
- double *dy_p)
-{
- gboolean retval = FALSE;
- uint32_t n_axes, n_val, i;
- double *values;
-
- n_axes = meta_input_device_x11_get_n_axes (device);
- values = valuators->values;
-
- *dx_p = *dy_p = 0.0;
-
- n_val = 0;
-
- for (i = 0; i < MIN (valuators->mask_len * 8, n_axes); i++)
- {
- ClutterScrollDirection direction;
- double delta;
-
- if (!XIMaskIsSet (valuators->mask, i))
- continue;
-
- if (meta_input_device_x11_get_scroll_delta (device, i,
- values[n_val],
- &direction,
- &delta))
- {
- retval = TRUE;
-
- if (direction == CLUTTER_SCROLL_UP ||
- direction == CLUTTER_SCROLL_DOWN)
- *dy_p = delta;
- else
- *dx_p = delta;
- }
-
- n_val += 1;
- }
-
- return retval;
-}
-
-static void
-translate_coords (MetaStageX11 *stage_x11,
- double event_x,
- double event_y,
- float *x_out,
- float *y_out)
-{
- MetaStageImpl *stage_impl = META_STAGE_IMPL (stage_x11);
- ClutterActor *stage = CLUTTER_ACTOR (stage_impl->wrapper);
- float stage_width;
- float stage_height;
-
- clutter_actor_get_size (stage, &stage_width, &stage_height);
-
- *x_out = CLAMP (event_x, 0, stage_width);
- *y_out = CLAMP (event_y, 0, stage_height);
-}
-
-static void
-on_keymap_state_change (MetaKeymapX11 *keymap_x11,
- gpointer data)
-{
- ClutterSeat *seat = data;
- MetaInputSettings *input_settings;
- MetaKbdA11ySettings kbd_a11y_settings;
-
- /* On keymaps state change, just reapply the current settings, it'll
- * take care of enabling/disabling mousekeys based on NumLock state.
- */
- input_settings = meta_backend_get_input_settings (meta_get_backend ());
- meta_input_settings_get_kbd_a11y_settings (input_settings, &kbd_a11y_settings);
- meta_seat_x11_apply_kbd_a11y_settings (seat, &kbd_a11y_settings);
-}
-
-static void
-meta_seat_x11_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- MetaSeatX11 *seat_x11 = META_SEAT_X11 (object);
-
- switch (prop_id)
- {
- case PROP_OPCODE:
- seat_x11->opcode = g_value_get_int (value);
- break;
- case PROP_POINTER_ID:
- seat_x11->pointer_id = g_value_get_int (value);
- break;
- case PROP_KEYBOARD_ID:
- seat_x11->keyboard_id = g_value_get_int (value);
- break;
- case PROP_TOUCH_MODE:
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- }
-}
-
-static void
-meta_seat_x11_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- MetaSeatX11 *seat_x11 = META_SEAT_X11 (object);
-
- switch (prop_id)
- {
- case PROP_OPCODE:
- g_value_set_int (value, seat_x11->opcode);
- break;
- case PROP_POINTER_ID:
- g_value_set_int (value, seat_x11->pointer_id);
- break;
- case PROP_KEYBOARD_ID:
- g_value_set_int (value, seat_x11->keyboard_id);
- break;
- case PROP_TOUCH_MODE:
- g_value_set_boolean (value, seat_x11->touch_mode);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- }
-}
-
-void
-meta_seat_x11_notify_devices (MetaSeatX11 *seat_x11,
- ClutterStage *stage)
-{
- GHashTableIter iter;
- ClutterInputDevice *device;
-
- g_hash_table_iter_init (&iter, seat_x11->devices_by_id);
- while (g_hash_table_iter_next (&iter, NULL, (gpointer *) &device))
- {
- ClutterEvent *event;
-
- event = clutter_event_new (CLUTTER_DEVICE_ADDED);
- clutter_event_set_device (event, device);
- clutter_event_set_stage (event, stage);
- clutter_event_put (event);
- clutter_event_free (event);
- }
-}
-
-static void
-meta_seat_x11_constructed (GObject *object)
-{
- MetaSeatX11 *seat_x11 = META_SEAT_X11 (object);
- ClutterBackend *backend = clutter_get_default_backend ();
- XIDeviceInfo *info;
- XIEventMask event_mask;
- unsigned char mask[XIMaskLen(XI_LASTEVENT)] = { 0, };
- int n_devices, i;
- Display *xdisplay;
-
- xdisplay = meta_clutter_x11_get_default_display ();
-
- info = XIQueryDevice (xdisplay, XIAllDevices, &n_devices);
-
- for (i = 0; i < n_devices; i++)
- {
- XIDeviceInfo *xi_device = &info[i];
-
- if (!xi_device->enabled)
- continue;
-
- add_device (seat_x11, backend, xi_device);
- }
-
- XIFreeDeviceInfo (info);
-
- XISetMask (mask, XI_HierarchyChanged);
- XISetMask (mask, XI_DeviceChanged);
- XISetMask (mask, XI_PropertyEvent);
-
- event_mask.deviceid = XIAllDevices;
- event_mask.mask_len = sizeof (mask);
- event_mask.mask = mask;
-
- XISelectEvents (xdisplay, meta_clutter_x11_get_root_window (),
- &event_mask, 1);
-
- memset(mask, 0, sizeof (mask));
- XISetMask (mask, XI_RawMotion);
- XISetMask (mask, XI_RawButtonPress);
- XISetMask (mask, XI_RawButtonRelease);
-
- event_mask.deviceid = XIAllMasterDevices;
- event_mask.mask_len = sizeof (mask);
- event_mask.mask = mask;
-
- XISelectEvents (xdisplay, meta_clutter_x11_get_root_window (),
- &event_mask, 1);
-
- XSync (xdisplay, False);
-
- seat_x11->keymap = g_object_new (META_TYPE_KEYMAP_X11,
- "backend", backend,
- NULL);
- g_signal_connect (seat_x11->keymap,
- "state-changed",
- G_CALLBACK (on_keymap_state_change),
- seat_x11);
-
- meta_seat_x11_a11y_init (CLUTTER_SEAT (seat_x11));
-
- if (G_OBJECT_CLASS (meta_seat_x11_parent_class)->constructed)
- G_OBJECT_CLASS (meta_seat_x11_parent_class)->constructed (object);
-}
-
-static void
-meta_seat_x11_finalize (GObject *object)
-{
- MetaSeatX11 *seat_x11 = META_SEAT_X11 (object);
-
- g_hash_table_unref (seat_x11->devices_by_id);
- g_hash_table_unref (seat_x11->tools_by_serial);
- g_hash_table_unref (seat_x11->touch_coords);
- g_list_free (seat_x11->devices);
-
- G_OBJECT_CLASS (meta_seat_x11_parent_class)->finalize (object);
-}
-
-static ClutterInputDevice *
-meta_seat_x11_get_pointer (ClutterSeat *seat)
-{
- MetaSeatX11 *seat_x11 = META_SEAT_X11 (seat);
-
- return seat_x11->core_pointer;
-}
-
-static ClutterInputDevice *
-meta_seat_x11_get_keyboard (ClutterSeat *seat)
-{
- MetaSeatX11 *seat_x11 = META_SEAT_X11 (seat);
-
- return seat_x11->core_keyboard;
-}
-
-static const GList *
-meta_seat_x11_peek_devices (ClutterSeat *seat)
-{
- MetaSeatX11 *seat_x11 = META_SEAT_X11 (seat);
-
- return (const GList *) seat_x11->devices;
-}
-
-static void
-meta_seat_x11_bell_notify (ClutterSeat *seat)
-{
- MetaDisplay *display = meta_get_display ();
-
- meta_bell_notify (display, NULL);
-}
-
-static ClutterKeymap *
-meta_seat_x11_get_keymap (ClutterSeat *seat)
-{
- return CLUTTER_KEYMAP (META_SEAT_X11 (seat)->keymap);
-}
-
-static ClutterVirtualInputDevice *
-meta_seat_x11_create_virtual_device (ClutterSeat *seat,
- ClutterInputDeviceType device_type)
-{
- return g_object_new (META_TYPE_VIRTUAL_INPUT_DEVICE_X11,
- "seat", seat,
- "device-type", device_type,
- NULL);
-}
-
-static ClutterVirtualDeviceType
-meta_seat_x11_get_supported_virtual_device_types (ClutterSeat *seat)
-{
- return (CLUTTER_VIRTUAL_DEVICE_TYPE_KEYBOARD |
- CLUTTER_VIRTUAL_DEVICE_TYPE_POINTER);
-}
-
-static void
-meta_seat_x11_warp_pointer (ClutterSeat *seat,
- int x,
- int y)
-{
- MetaSeatX11 *seat_x11 = META_SEAT_X11 (seat);
-
- meta_clutter_x11_trap_x_errors ();
- XIWarpPointer (meta_clutter_x11_get_default_display (),
- seat_x11->pointer_id,
- None,
- meta_clutter_x11_get_root_window (),
- 0, 0, 0, 0,
- x, y);
- meta_clutter_x11_untrap_x_errors ();
-}
-
-static uint32_t
-translate_state (XIButtonState *button_state,
- XIModifierState *modifier_state,
- XIGroupState *group_state)
-{
- uint32_t state = 0;
- int i;
-
- if (modifier_state)
- state |= modifier_state->effective;
-
- if (button_state)
- {
- for (i = 1; i < button_state->mask_len * 8; i++)
- {
- if (!XIMaskIsSet (button_state->mask, i))
- continue;
-
- switch (i)
- {
- case 1:
- state |= CLUTTER_BUTTON1_MASK;
- break;
- case 2:
- state |= CLUTTER_BUTTON2_MASK;
- break;
- case 3:
- state |= CLUTTER_BUTTON3_MASK;
- break;
- case 8:
- state |= CLUTTER_BUTTON4_MASK;
- break;
- case 9:
- state |= CLUTTER_BUTTON5_MASK;
- break;
- default:
- break;
- }
- }
- }
-
- if (group_state)
- state |= XkbBuildCoreState (0, group_state->effective);
-
- return state;
-}
-
-static gboolean
-meta_seat_x11_query_state (ClutterSeat *seat,
- ClutterInputDevice *device,
- ClutterEventSequence *sequence,
- graphene_point_t *coords,
- ClutterModifierType *modifiers)
-{
- MetaBackendX11 *backend_x11 = META_BACKEND_X11 (meta_get_backend ());
- MetaSeatX11 *seat_x11 = META_SEAT_X11 (seat);
- Window root_ret, child_ret;
- double root_x, root_y, win_x, win_y;
- XIButtonState button_state = { 0 };
- XIModifierState modifier_state;
- XIGroupState group_state;
-
- meta_clutter_x11_trap_x_errors ();
- XIQueryPointer (meta_clutter_x11_get_default_display (),
- seat_x11->pointer_id,
- meta_backend_x11_get_xwindow (backend_x11),
- &root_ret, &child_ret,
- &root_x, &root_y, &win_x, &win_y,
- &button_state, &modifier_state, &group_state);
- if (meta_clutter_x11_untrap_x_errors ())
- {
- g_free (button_state.mask);
- return FALSE;
- }
-
- if (sequence)
- {
- MetaTouchInfo *touch_info;
-
- touch_info = g_hash_table_lookup (seat_x11->touch_coords, sequence);
- if (!touch_info)
- {
- g_free (button_state.mask);
- return FALSE;
- }
-
- if (coords)
- {
- coords->x = touch_info->x;
- coords->y = touch_info->y;
- }
- }
- else
- {
- if (coords)
- {
- coords->x = win_x;
- coords->y = win_y;
- }
- }
-
- if (modifiers)
- *modifiers = translate_state (&button_state, &modifier_state, &group_state);
-
- g_free (button_state.mask);
- return TRUE;
-}
-
-static void
-meta_seat_x11_update_touchpoint (MetaSeatX11 *seat,
- ClutterEventSequence *sequence,
- double x,
- double y)
-{
- MetaTouchInfo *touch_info;
-
- touch_info = g_hash_table_lookup (seat->touch_coords, sequence);
- if (!touch_info)
- {
- touch_info = g_new0 (MetaTouchInfo, 1);
- touch_info->sequence = sequence;
- g_hash_table_insert (seat->touch_coords, sequence, touch_info);
- }
-
- touch_info->x = x;
- touch_info->y = y;
-}
-
-static void
-meta_seat_x11_remove_touchpoint (MetaSeatX11 *seat,
- ClutterEventSequence *sequence)
-{
- g_hash_table_remove (seat->touch_coords, sequence);
-}
-
-static void
-meta_touch_info_free (MetaTouchInfo *touch_info)
-{
- g_free (touch_info);
-}
-
-static void
-meta_seat_x11_class_init (MetaSeatX11Class *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
- ClutterSeatClass *seat_class = CLUTTER_SEAT_CLASS (klass);
-
- object_class->set_property = meta_seat_x11_set_property;
- object_class->get_property = meta_seat_x11_get_property;
- object_class->constructed = meta_seat_x11_constructed;
- object_class->finalize = meta_seat_x11_finalize;
-
- seat_class->get_pointer = meta_seat_x11_get_pointer;
- seat_class->get_keyboard = meta_seat_x11_get_keyboard;
- seat_class->peek_devices = meta_seat_x11_peek_devices;
- seat_class->bell_notify = meta_seat_x11_bell_notify;
- seat_class->get_keymap = meta_seat_x11_get_keymap;
- seat_class->create_virtual_device = meta_seat_x11_create_virtual_device;
- seat_class->get_supported_virtual_device_types = meta_seat_x11_get_supported_virtual_device_types;
- seat_class->warp_pointer = meta_seat_x11_warp_pointer;
- seat_class->handle_event_post = meta_seat_x11_handle_event_post;
- seat_class->query_state = meta_seat_x11_query_state;
-
- props[PROP_OPCODE] =
- g_param_spec_int ("opcode",
- "Opcode",
- "Opcode",
- 0, G_MAXINT, 0,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT_ONLY);
- props[PROP_POINTER_ID] =
- g_param_spec_int ("pointer-id",
- "Pointer ID",
- "Pointer ID",
- 2, G_MAXINT, 2,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT_ONLY);
- props[PROP_KEYBOARD_ID] =
- g_param_spec_int ("keyboard-id",
- "Keyboard ID",
- "Keyboard ID",
- 2, G_MAXINT, 2,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT_ONLY);
-
- g_object_class_install_properties (object_class, N_PROPS, props);
-
- g_object_class_override_property (object_class, PROP_TOUCH_MODE,
- "touch-mode");
-}
-
-static void
-meta_seat_x11_init (MetaSeatX11 *seat)
-{
- seat->devices_by_id = g_hash_table_new_full (NULL, NULL,
- NULL,
- (GDestroyNotify) g_object_unref);
- seat->tools_by_serial = g_hash_table_new_full (NULL, NULL, NULL,
- (GDestroyNotify) g_object_unref);
- seat->touch_coords = g_hash_table_new_full (NULL, NULL, NULL,
- (GDestroyNotify) meta_touch_info_free);
-}
-
-MetaSeatX11 *
-meta_seat_x11_new (int opcode,
- int logical_pointer,
- int logical_keyboard)
-{
- return g_object_new (META_TYPE_SEAT_X11,
- "opcode", opcode,
- "pointer-id", logical_pointer,
- "keyboard-id", logical_keyboard,
- NULL);
-}
-
-static ClutterInputDevice *
-get_source_device_checked (MetaSeatX11 *seat,
- XIDeviceEvent *xev)
-{
- ClutterInputDevice *source_device;
-
- source_device = g_hash_table_lookup (seat->devices_by_id,
- GINT_TO_POINTER (xev->sourceid));
-
- if (!source_device)
- g_warning ("Impossible to get the source device with id %d for event of "
- "type %d", xev->sourceid, xev->evtype);
-
- return source_device;
-}
-
-static uint32_t
-evdev_button_code (uint32_t x_button)
-{
- uint32_t button;
-
- switch (x_button)
- {
- case 1:
- button = BTN_LEFT;
- break;
-
- /* The evdev input right and middle button numbers are swapped
- relative to how Clutter numbers them */
- case 2:
- button = BTN_MIDDLE;
- break;
-
- case 3:
- button = BTN_RIGHT;
- break;
-
- default:
- button = x_button + (BTN_LEFT - 1) + 4;
- break;
- }
-
- return button;
-}
-
-gboolean
-meta_seat_x11_translate_event (MetaSeatX11 *seat,
- XEvent *xevent,
- ClutterEvent *event)
-{
- gboolean retval = FALSE;
- ClutterBackend *backend = clutter_get_default_backend ();
- ClutterStage *stage = NULL;
- MetaStageX11 *stage_x11 = NULL;
- ClutterInputDevice *device, *source_device;
- XGenericEventCookie *cookie;
- XIEvent *xi_event;
-
- if (meta_keymap_x11_handle_event (seat->keymap, xevent))
- return FALSE;
-
- cookie = &xevent->xcookie;
-
- if (cookie->type != GenericEvent ||
- cookie->extension != seat->opcode)
- return FALSE;
-
- xi_event = (XIEvent *) cookie->data;
-
- if (!xi_event)
- return FALSE;
-
- if (cookie->evtype == XI_RawMotion ||
- cookie->evtype == XI_RawButtonPress ||
- cookie->evtype == XI_RawButtonRelease)
- {
- translate_raw_event (seat, xevent);
- return FALSE;
- }
-
- if (!(xi_event->evtype == XI_DeviceChanged ||
- xi_event->evtype == XI_PropertyEvent))
- {
- stage = get_event_stage (seat, xi_event);
- if (stage == NULL || CLUTTER_ACTOR_IN_DESTRUCTION (stage))
- return FALSE;
- else
- stage_x11 = META_STAGE_X11 (_clutter_stage_get_window (stage));
- }
-
- event->any.stage = stage;
-
- switch (xi_event->evtype)
- {
- case XI_HierarchyChanged:
- {
- XIHierarchyEvent *xev = (XIHierarchyEvent *) xi_event;
-
- retval = translate_hierarchy_event (backend, seat, xev, event);
- }
- break;
-
- case XI_DeviceChanged:
- {
- XIDeviceChangedEvent *xev = (XIDeviceChangedEvent *) xi_event;
-
- device = g_hash_table_lookup (seat->devices_by_id,
- GINT_TO_POINTER (xev->deviceid));
- source_device = g_hash_table_lookup (seat->devices_by_id,
- GINT_TO_POINTER (xev->sourceid));
- if (device)
- {
- meta_input_device_x11_reset_axes (device);
- translate_device_classes (meta_clutter_x11_get_default_display (),
- device,
- xev->classes,
- xev->num_classes);
- }
-
- if (source_device)
- meta_input_device_x11_reset_scroll_info (source_device);
- }
- retval = FALSE;
- break;
- case XI_KeyPress:
- case XI_KeyRelease:
- {
- XIDeviceEvent *xev = (XIDeviceEvent *) xi_event;
- MetaKeymapX11 *keymap_x11 = seat->keymap;
- char buffer[7] = { 0, };
- gunichar n;
-
- source_device = get_source_device_checked (seat, xev);
- if (!source_device)
- return FALSE;
-
- event->key.type = event->type = (xev->evtype == XI_KeyPress)
- ? CLUTTER_KEY_PRESS
- : CLUTTER_KEY_RELEASE;
-
- if (xev->evtype == XI_KeyPress && xev->flags & XIKeyRepeat)
- clutter_event_set_flags (event, CLUTTER_EVENT_FLAG_REPEATED);
-
- event->key.time = xev->time;
- event->key.stage = stage;
- meta_input_device_x11_translate_state (event, &xev->mods, &xev->buttons, &xev->group);
- event->key.hardware_keycode = xev->detail;
-
- /* clutter-xkb-utils.c adds a fixed offset of 8 to go into XKB's
- * range, so we do the reverse here. */
- event->key.evdev_code = event->key.hardware_keycode - 8;
-
- /* keyval is the key ignoring all modifiers ('1' vs. '!') */
- event->key.keyval =
- meta_keymap_x11_translate_key_state (keymap_x11,
- event->key.hardware_keycode,
- &event->key.modifier_state,
- NULL);
-
- clutter_event_set_source_device (event, source_device);
-
- device = g_hash_table_lookup (seat->devices_by_id,
- GINT_TO_POINTER (xev->deviceid));
- clutter_event_set_device (event, device);
-
- /* XXX keep this in sync with the evdev device manager */
- n = print_keysym (event->key.keyval, buffer, sizeof (buffer));
- if (n == 0)
- {
- /* not printable */
- event->key.unicode_value = (gunichar) '\0';
- }
- else
- {
- event->key.unicode_value = g_utf8_get_char_validated (buffer, n);
- if (event->key.unicode_value == -1 ||
- event->key.unicode_value == -2)
- event->key.unicode_value = (gunichar) '\0';
- }
-
- g_debug ("%s: win:0x%x device:%d source:%d, key: %12s (%d)",
- event->any.type == CLUTTER_KEY_PRESS
- ? "key press "
- : "key release",
- (unsigned int) stage_x11->xwin,
- xev->deviceid,
- xev->sourceid,
- event->key.keyval ? buffer : "(none)",
- event->key.keyval);
-
- if (xi_event->evtype == XI_KeyPress)
- meta_stage_x11_set_user_time (stage_x11, event->key.time);
-
- retval = TRUE;
- }
- break;
-
- case XI_ButtonPress:
- case XI_ButtonRelease:
- {
- XIDeviceEvent *xev = (XIDeviceEvent *) xi_event;
-
- source_device = get_source_device_checked (seat, xev);
- if (!source_device)
- return FALSE;
-
- device = g_hash_table_lookup (seat->devices_by_id,
- GINT_TO_POINTER (xev->deviceid));
-
- if (clutter_input_device_get_device_type (source_device) == CLUTTER_PAD_DEVICE)
- {
- /* We got these events because of the passive button grab */
- XIAllowEvents (meta_clutter_x11_get_default_display (),
- xev->sourceid,
- XIAsyncDevice,
- xev->time);
-
- event->any.stage = stage;
-
- if (xev->detail >= 4 && xev->detail <= 7)
- {
- retval = FALSE;
-
- if (xi_event->evtype == XI_ButtonPress &&
- translate_pad_event (event, xev, source_device))
- retval = TRUE;
-
- break;
- }
-
- event->any.type =
- (xi_event->evtype == XI_ButtonPress) ? CLUTTER_PAD_BUTTON_PRESS
- : CLUTTER_PAD_BUTTON_RELEASE;
- event->any.time = xev->time;
-
- /* The 4-7 button range is taken as non-existent on pad devices,
- * let the buttons above that take over this range.
- */
- if (xev->detail > 7)
- xev->detail -= 4;
-
- /* Pad buttons are 0-indexed */
- event->pad_button.button = xev->detail - 1;
-#ifdef HAVE_LIBWACOM
- meta_input_device_x11_update_pad_state (device,
- event->pad_button.button,
- (xi_event->evtype == XI_ButtonPress),
- &event->pad_button.group,
- &event->pad_button.mode);
-#endif
- clutter_event_set_device (event, device);
- clutter_event_set_source_device (event, source_device);
-
- g_debug ("%s: win:0x%x, device:%d '%s', time:%d "
- "(button:%d)",
- event->any.type == CLUTTER_BUTTON_PRESS
- ? "pad button press "
- : "pad button release",
- (unsigned int) stage_x11->xwin,
- meta_input_device_x11_get_device_id (device),
- clutter_input_device_get_device_name (device),
- event->any.time,
- event->pad_button.button);
- retval = TRUE;
- break;
- }
-
- switch (xev->detail)
- {
- case 4:
- case 5:
- case 6:
- case 7:
- /* we only generate Scroll events on ButtonPress */
- if (xi_event->evtype == XI_ButtonRelease)
- return FALSE;
-
- event->scroll.type = event->type = CLUTTER_SCROLL;
-
- if (xev->detail == 4)
- event->scroll.direction = CLUTTER_SCROLL_UP;
- else if (xev->detail == 5)
- event->scroll.direction = CLUTTER_SCROLL_DOWN;
- else if (xev->detail == 6)
- event->scroll.direction = CLUTTER_SCROLL_LEFT;
- else
- event->scroll.direction = CLUTTER_SCROLL_RIGHT;
-
- event->scroll.stage = stage;
-
- event->scroll.time = xev->time;
- translate_coords (stage_x11, xev->event_x, xev->event_y, &event->scroll.x, &event->scroll.y);
- meta_input_device_x11_translate_state (event,
- &xev->mods,
- &xev->buttons,
- &xev->group);
-
- clutter_event_set_source_device (event, source_device);
- clutter_event_set_device (event, device);
-
- event->scroll.axes = translate_axes (event->scroll.device,
- event->scroll.x,
- event->scroll.y,
- &xev->valuators);
- g_debug ("scroll: win:0x%x, device:%d '%s', time:%d "
- "(direction:%s, "
- "x:%.2f, y:%.2f, "
- "emulated:%s)",
- (unsigned int) stage_x11->xwin,
- meta_input_device_x11_get_device_id (device),
- clutter_input_device_get_device_name (device),
- event->any.time,
- event->scroll.direction == CLUTTER_SCROLL_UP ? "up" :
- event->scroll.direction == CLUTTER_SCROLL_DOWN ? "down" :
- event->scroll.direction == CLUTTER_SCROLL_LEFT ? "left" :
- event->scroll.direction == CLUTTER_SCROLL_RIGHT ? "right" :
- "invalid",
- event->scroll.x,
- event->scroll.y,
- (xev->flags & XIPointerEmulated) ? "yes" : "no");
- break;
-
- default:
- event->button.type = event->type =
- (xi_event->evtype == XI_ButtonPress) ? CLUTTER_BUTTON_PRESS
- : CLUTTER_BUTTON_RELEASE;
-
- event->button.stage = stage;
-
- event->button.time = xev->time;
- translate_coords (stage_x11, xev->event_x, xev->event_y, &event->button.x, &event->button.y);
- event->button.button = xev->detail;
- event->button.evdev_code = evdev_button_code (xev->detail);
- meta_input_device_x11_translate_state (event,
- &xev->mods,
- &xev->buttons,
- &xev->group);
-
- clutter_event_set_source_device (event, source_device);
- clutter_event_set_device (event, device);
- clutter_event_set_device_tool (event,
- meta_input_device_x11_get_current_tool (source_device));
-
- event->button.axes = translate_axes (event->button.device,
- event->button.x,
- event->button.y,
- &xev->valuators);
- g_debug ("%s: win:0x%x, device:%d '%s', time:%d "
- "(button:%d, "
- "x:%.2f, y:%.2f, "
- "axes:%s, "
- "emulated:%s)",
- event->any.type == CLUTTER_BUTTON_PRESS
- ? "button press "
- : "button release",
- (unsigned int) stage_x11->xwin,
- meta_input_device_x11_get_device_id (device),
- clutter_input_device_get_device_name (device),
- event->any.time,
- event->button.button,
- event->button.x,
- event->button.y,
- event->button.axes != NULL ? "yes" : "no",
- (xev->flags & XIPointerEmulated) ? "yes" : "no");
- break;
- }
-
- if (xev->flags & XIPointerEmulated)
- _clutter_event_set_pointer_emulated (event, TRUE);
-
- if (xi_event->evtype == XI_ButtonPress)
- meta_stage_x11_set_user_time (stage_x11, event->button.time);
-
- retval = TRUE;
- }
- break;
-
- case XI_Motion:
- {
- XIDeviceEvent *xev = (XIDeviceEvent *) xi_event;
- double delta_x, delta_y;
-
- source_device = get_source_device_checked (seat, xev);
- if (!source_device)
- return FALSE;
-
- device = g_hash_table_lookup (seat->devices_by_id,
- GINT_TO_POINTER (xev->deviceid));
-
- if (clutter_input_device_get_device_type (source_device) == CLUTTER_PAD_DEVICE)
- {
- event->any.stage = stage;
-
- if (translate_pad_event (event, xev, source_device))
- retval = TRUE;
- break;
- }
-
- if (scroll_valuators_changed (source_device,
- &xev->valuators,
- &delta_x, &delta_y))
- {
- event->scroll.type = event->type = CLUTTER_SCROLL;
- event->scroll.direction = CLUTTER_SCROLL_SMOOTH;
-
- event->scroll.stage = stage;
- event->scroll.time = xev->time;
- translate_coords (stage_x11, xev->event_x, xev->event_y, &event->scroll.x, &event->scroll.y);
- meta_input_device_x11_translate_state (event,
- &xev->mods,
- &xev->buttons,
- &xev->group);
-
- clutter_event_set_scroll_delta (event, delta_x, delta_y);
- clutter_event_set_source_device (event, source_device);
- clutter_event_set_device (event, device);
-
- g_debug ("smooth scroll: win:0x%x device:%d '%s' (x:%.2f, y:%.2f, delta:%f, %f)",
- (unsigned int) stage_x11->xwin,
- meta_input_device_x11_get_device_id (event->scroll.device),
- clutter_input_device_get_device_name (event->scroll.device),
- event->scroll.x,
- event->scroll.y,
- delta_x, delta_y);
-
- retval = TRUE;
- break;
- }
-
- event->motion.type = event->type = CLUTTER_MOTION;
-
- event->motion.stage = stage;
-
- event->motion.time = xev->time;
- translate_coords (stage_x11, xev->event_x, xev->event_y, &event->motion.x, &event->motion.y);
- meta_input_device_x11_translate_state (event,
- &xev->mods,
- &xev->buttons,
- &xev->group);
-
- clutter_event_set_source_device (event, source_device);
- clutter_event_set_device (event, device);
- clutter_event_set_device_tool (event,
- meta_input_device_x11_get_current_tool (source_device));
-
- event->motion.axes = translate_axes (event->motion.device,
- event->motion.x,
- event->motion.y,
- &xev->valuators);
-
- if (xev->flags & XIPointerEmulated)
- _clutter_event_set_pointer_emulated (event, TRUE);
-
- g_debug ("motion: win:0x%x device:%d '%s' (x:%.2f, y:%.2f, axes:%s)",
- (unsigned int) stage_x11->xwin,
- meta_input_device_x11_get_device_id (event->motion.device),
- clutter_input_device_get_device_name (event->motion.device),
- event->motion.x,
- event->motion.y,
- event->motion.axes != NULL ? "yes" : "no");
-
- retval = TRUE;
- }
- break;
-
- case XI_TouchBegin:
- {
- XIDeviceEvent *xev = (XIDeviceEvent *) xi_event;
- device = g_hash_table_lookup (seat->devices_by_id,
- GINT_TO_POINTER (xev->deviceid));
- }
- /* Fall through */
- case XI_TouchEnd:
- {
- XIDeviceEvent *xev = (XIDeviceEvent *) xi_event;
-
- source_device = g_hash_table_lookup (seat->devices_by_id,
- GINT_TO_POINTER (xev->sourceid));
-
- if (xi_event->evtype == XI_TouchBegin)
- event->touch.type = event->type = CLUTTER_TOUCH_BEGIN;
- else
- event->touch.type = event->type = CLUTTER_TOUCH_END;
-
- event->touch.stage = stage;
- event->touch.time = xev->time;
- translate_coords (stage_x11, xev->event_x, xev->event_y, &event->touch.x, &event->touch.y);
- meta_input_device_x11_translate_state (event,
- &xev->mods,
- &xev->buttons,
- &xev->group);
-
- clutter_event_set_source_device (event, source_device);
-
- device = g_hash_table_lookup (seat->devices_by_id,
- GINT_TO_POINTER (xev->deviceid));
- clutter_event_set_device (event, device);
-
- event->touch.axes = translate_axes (event->touch.device,
- event->motion.x,
- event->motion.y,
- &xev->valuators);
-
- if (xi_event->evtype == XI_TouchBegin)
- {
- event->touch.modifier_state |= CLUTTER_BUTTON1_MASK;
-
- meta_stage_x11_set_user_time (stage_x11, event->touch.time);
- meta_seat_x11_update_touchpoint (seat,
- GUINT_TO_POINTER (xev->detail),
- xev->root_x,
- xev->root_y);
- }
- else if (xi_event->evtype == XI_TouchEnd)
- {
- meta_seat_x11_remove_touchpoint (seat,
- GUINT_TO_POINTER (xev->detail));
- }
-
- /* "NULL" sequences are special cased in clutter */
- event->touch.sequence = GINT_TO_POINTER (MAX (1, xev->detail + 1));
-
- if (xev->flags & XITouchEmulatingPointer)
- _clutter_event_set_pointer_emulated (event, TRUE);
-
- g_debug ("touch %s: win:0x%x device:%d '%s' (seq:%d, x:%.2f, y:%.2f, axes:%s)",
- event->type == CLUTTER_TOUCH_BEGIN ? "begin" : "end",
- (unsigned int) stage_x11->xwin,
- meta_input_device_x11_get_device_id (event->touch.device),
- clutter_input_device_get_device_name (event->touch.device),
- GPOINTER_TO_UINT (event->touch.sequence),
- event->touch.x,
- event->touch.y,
- event->touch.axes != NULL ? "yes" : "no");
-
- retval = TRUE;
- }
- break;
-
- case XI_TouchUpdate:
- {
- XIDeviceEvent *xev = (XIDeviceEvent *) xi_event;
-
- source_device = g_hash_table_lookup (seat->devices_by_id,
- GINT_TO_POINTER (xev->sourceid));
-
- event->touch.type = event->type = CLUTTER_TOUCH_UPDATE;
- event->touch.stage = stage;
- event->touch.time = xev->time;
- /* "NULL" sequences are special cased in clutter */
- event->touch.sequence = GINT_TO_POINTER (MAX (1, xev->detail + 1));
- translate_coords (stage_x11, xev->event_x, xev->event_y, &event->touch.x, &event->touch.y);
-
- clutter_event_set_source_device (event, source_device);
-
- device = g_hash_table_lookup (seat->devices_by_id,
- GINT_TO_POINTER (xev->deviceid));
- clutter_event_set_device (event, device);
-
- event->touch.axes = translate_axes (event->touch.device,
- event->motion.x,
- event->motion.y,
- &xev->valuators);
-
- meta_input_device_x11_translate_state (event,
- &xev->mods,
- &xev->buttons,
- &xev->group);
- event->touch.modifier_state |= CLUTTER_BUTTON1_MASK;
-
- if (xev->flags & XITouchEmulatingPointer)
- _clutter_event_set_pointer_emulated (event, TRUE);
-
- meta_seat_x11_update_touchpoint (seat,
- event->touch.sequence,
- xev->root_x,
- xev->root_y);
-
- g_debug ("touch update: win:0x%x device:%d '%s' (seq:%d, x:%.2f, y:%.2f, axes:%s)",
- (unsigned int) stage_x11->xwin,
- meta_input_device_x11_get_device_id (event->touch.device),
- clutter_input_device_get_device_name (event->touch.device),
- GPOINTER_TO_UINT (event->touch.sequence),
- event->touch.x,
- event->touch.y,
- event->touch.axes != NULL ? "yes" : "no");
-
- retval = TRUE;
- }
- break;
-
- case XI_Enter:
- case XI_Leave:
- {
- XIEnterEvent *xev = (XIEnterEvent *) xi_event;
-
- device = g_hash_table_lookup (seat->devices_by_id,
- GINT_TO_POINTER (xev->deviceid));
-
- source_device = g_hash_table_lookup (seat->devices_by_id,
- GINT_TO_POINTER (xev->sourceid));
-
- if (xi_event->evtype == XI_Enter)
- {
- event->crossing.type = event->type = CLUTTER_ENTER;
-
- event->crossing.stage = stage;
- event->crossing.source = CLUTTER_ACTOR (stage);
- event->crossing.related = NULL;
-
- event->crossing.time = xev->time;
- translate_coords (stage_x11, xev->event_x, xev->event_y, &event->crossing.x, &event->crossing.y);
-
- if (xev->deviceid == seat->pointer_id)
- seat->has_pointer_focus = TRUE;
- }
- else
- {
- event->crossing.type = event->type = CLUTTER_LEAVE;
-
- event->crossing.stage = stage;
- event->crossing.source = CLUTTER_ACTOR (stage);
- event->crossing.related = NULL;
-
- event->crossing.time = xev->time;
- translate_coords (stage_x11, xev->event_x, xev->event_y, &event->crossing.x, &event->crossing.y);
-
- if (xev->deviceid == seat->pointer_id)
- seat->has_pointer_focus = FALSE;
- }
-
- meta_input_device_x11_reset_scroll_info (source_device);
-
- clutter_event_set_device (event, device);
- clutter_event_set_source_device (event, source_device);
-
- retval = TRUE;
- }
- break;
-
- case XI_FocusIn:
- case XI_FocusOut:
- retval = FALSE;
- break;
- case XI_PropertyEvent:
- translate_property_event (seat, xi_event);
- retval = FALSE;
- break;
- }
-
- return retval;
-}
-
-ClutterInputDevice *
-meta_seat_x11_lookup_device_id (MetaSeatX11 *seat_x11,
- int device_id)
-{
- return g_hash_table_lookup (seat_x11->devices_by_id,
- GINT_TO_POINTER (device_id));
-}
-
-void
-meta_seat_x11_select_stage_events (MetaSeatX11 *seat,
- ClutterStage *stage)
-{
- MetaStageX11 *stage_x11;
- XIEventMask xi_event_mask;
- unsigned char *mask;
- int len;
-
- stage_x11 = META_STAGE_X11 (_clutter_stage_get_window (stage));
-
- len = XIMaskLen (XI_LASTEVENT);
- mask = g_new0 (unsigned char, len);
-
- XISetMask (mask, XI_Motion);
- XISetMask (mask, XI_ButtonPress);
- XISetMask (mask, XI_ButtonRelease);
- XISetMask (mask, XI_KeyPress);
- XISetMask (mask, XI_KeyRelease);
- XISetMask (mask, XI_Enter);
- XISetMask (mask, XI_Leave);
-
- XISetMask (mask, XI_TouchBegin);
- XISetMask (mask, XI_TouchUpdate);
- XISetMask (mask, XI_TouchEnd);
-
- xi_event_mask.deviceid = XIAllMasterDevices;
- xi_event_mask.mask = mask;
- xi_event_mask.mask_len = len;
-
- XISelectEvents (meta_clutter_x11_get_default_display (),
- stage_x11->xwin, &xi_event_mask, 1);
-
- g_free (mask);
-}
diff --git a/src/backends/x11/meta-seat-x11.h b/src/backends/x11/meta-seat-x11.h
deleted file mode 100644
index 326db4a45..000000000
--- a/src/backends/x11/meta-seat-x11.h
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Copyright (C) 2019 Red Hat Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
- *
- * Author: Carlos Garnacho <carlosg@gnome.org>
- */
-#ifndef META_SEAT_X11_H
-#define META_SEAT_X11_H
-
-#include "clutter/clutter.h"
-
-G_BEGIN_DECLS
-
-#define META_TYPE_SEAT_X11 meta_seat_x11_get_type ()
-G_DECLARE_FINAL_TYPE (MetaSeatX11, meta_seat_x11, META, SEAT_X11, ClutterSeat)
-
-MetaSeatX11 * meta_seat_x11_new (int opcode,
- int logical_pointer,
- int logical_keyboard);
-gboolean meta_seat_x11_translate_event (MetaSeatX11 *seat,
- XEvent *xevent,
- ClutterEvent *event);
-ClutterInputDevice * meta_seat_x11_lookup_device_id (MetaSeatX11 *seat_x11,
- int device_id);
-void meta_seat_x11_select_stage_events (MetaSeatX11 *seat,
- ClutterStage *stage);
-void meta_seat_x11_notify_devices (MetaSeatX11 *seat_x11,
- ClutterStage *stage);
-
-G_END_DECLS
-
-#endif /* META_SEAT_X11_H */
diff --git a/src/backends/x11/meta-stage-x11.c b/src/backends/x11/meta-stage-x11.c
deleted file mode 100644
index 87e7ffec6..000000000
--- a/src/backends/x11/meta-stage-x11.c
+++ /dev/null
@@ -1,853 +0,0 @@
-/*
- * Authored By Matthew Allum <mallum@openedhand.com>
- * Copyright (C) 2006-2007 OpenedHand
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-#include "config.h"
-
-#include <math.h>
-#include <stdlib.h>
-
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-
-#include "backends/meta-stage-private.h"
-#include "backends/x11/cm/meta-backend-x11-cm.h"
-#include "backends/x11/cm/meta-renderer-x11-cm.h"
-#include "backends/x11/meta-backend-x11.h"
-#include "backends/x11/meta-clutter-backend-x11.h"
-#include "backends/x11/meta-seat-x11.h"
-#include "backends/x11/meta-stage-x11.h"
-#include "backends/x11/nested/meta-stage-x11-nested.h"
-#include "clutter/clutter-mutter.h"
-#include "cogl/cogl-mutter.h"
-#include "cogl/cogl.h"
-#include "core/display-private.h"
-#include "meta/meta-context.h"
-#include "meta/meta-x11-errors.h"
-
-#define STAGE_X11_IS_MAPPED(s) ((((MetaStageX11 *) (s))->wm_state & STAGE_X11_WITHDRAWN) == 0)
-
-static ClutterStageWindowInterface *clutter_stage_window_parent_iface = NULL;
-
-static void
-clutter_stage_window_iface_init (ClutterStageWindowInterface *iface);
-
-static MetaStageImpl *meta_x11_get_stage_window_from_window (Window win);
-
-static GHashTable *clutter_stages_by_xid = NULL;
-
-G_DEFINE_TYPE_WITH_CODE (MetaStageX11,
- meta_stage_x11,
- META_TYPE_STAGE_IMPL,
- G_IMPLEMENT_INTERFACE (CLUTTER_TYPE_STAGE_WINDOW,
- clutter_stage_window_iface_init));
-
-#define _NET_WM_STATE_REMOVE 0 /* remove/unset property */
-#define _NET_WM_STATE_ADD 1 /* add/set property */
-#define _NET_WM_STATE_TOGGLE 2 /* toggle property */
-
-#define META_STAGE_X11_EVENT_MASK \
- StructureNotifyMask | \
- FocusChangeMask | \
- ExposureMask | \
- PropertyChangeMask | \
- EnterWindowMask | \
- LeaveWindowMask | \
- KeyPressMask | \
- KeyReleaseMask | \
- ButtonPressMask | \
- ButtonReleaseMask | \
- PointerMotionMask
-
-static void
-meta_stage_x11_fix_window_size (MetaStageX11 *stage_x11,
- int new_width,
- int new_height)
-{
- MetaStageImpl *stage_impl = META_STAGE_IMPL (stage_x11);
-
- if (stage_x11->xwin != None)
- {
- Display *xdisplay = meta_clutter_x11_get_default_display ();
- uint32_t min_width, min_height;
- XSizeHints *size_hints;
-
- size_hints = XAllocSizeHints();
-
- clutter_stage_get_minimum_size (stage_impl->wrapper,
- &min_width,
- &min_height);
-
- if (new_width <= 0)
- new_width = min_width;
-
- if (new_height <= 0)
- new_height = min_height;
-
- size_hints->min_width = new_width;
- size_hints->min_height = new_height;
- size_hints->max_width = new_width;
- size_hints->max_height = new_height;
- size_hints->flags = PMinSize | PMaxSize;
-
- XSetWMNormalHints (xdisplay, stage_x11->xwin, size_hints);
-
- XFree(size_hints);
- }
-}
-
-static void
-meta_stage_x11_set_wm_protocols (MetaStageX11 *stage_x11)
-{
- MetaStageImpl *stage_impl = META_STAGE_IMPL (stage_x11);
- MetaClutterBackendX11 *backend_x11 =
- META_CLUTTER_BACKEND_X11 (stage_impl->backend);
- Display *xdisplay = meta_clutter_x11_get_default_display ();
- Atom protocols[2];
- int n = 0;
-
- protocols[n++] = backend_x11->atom_WM_DELETE_WINDOW;
- protocols[n++] = backend_x11->atom_NET_WM_PING;
-
- XSetWMProtocols (xdisplay, stage_x11->xwin, protocols, n);
-}
-
-static void
-meta_stage_x11_get_geometry (ClutterStageWindow *stage_window,
- cairo_rectangle_int_t *geometry)
-{
- MetaStageX11 *stage_x11 = META_STAGE_X11 (stage_window);
-
- geometry->x = geometry->y = 0;
- geometry->width = stage_x11->xwin_width;
- geometry->height = stage_x11->xwin_height;
-}
-
-static void
-meta_stage_x11_resize (ClutterStageWindow *stage_window,
- int width,
- int height)
-{
- MetaStageX11 *stage_x11 = META_STAGE_X11 (stage_window);
-
- if (width == 0 || height == 0)
- {
- /* Should not happen, if this turns up we need to debug it and
- * determine the cleanest way to fix.
- */
- g_warning ("X11 stage not allowed to have 0 width or height");
- width = 1;
- height = 1;
- }
-
- if (stage_x11->xwin != None)
- {
- meta_stage_x11_fix_window_size (stage_x11, width, height);
-
- if (width != stage_x11->xwin_width ||
- height != stage_x11->xwin_height)
- {
- Display *xdisplay = meta_clutter_x11_get_default_display ();
-
- /* XXX: in this case we can rely on a subsequent
- * ConfigureNotify that will result in the stage
- * being reallocated so we don't actively do anything
- * to affect the stage allocation here. */
- XResizeWindow (xdisplay,
- stage_x11->xwin,
- width,
- height);
- }
- }
- else
- {
- /* if the backing window hasn't been created yet, we just
- * need to store the new window size
- */
- stage_x11->xwin_width = width;
- stage_x11->xwin_height = height;
- }
-}
-
-static inline void
-set_wm_pid (MetaStageX11 *stage_x11)
-{
- MetaStageImpl *stage_impl = META_STAGE_IMPL (stage_x11);
- MetaClutterBackendX11 *backend_x11 =
- META_CLUTTER_BACKEND_X11 (stage_impl->backend);
- Display *xdisplay = meta_clutter_x11_get_default_display ();
- long pid;
-
- if (stage_x11->xwin == None)
- return;
-
- /* this will take care of WM_CLIENT_MACHINE and WM_LOCALE_NAME */
- XSetWMProperties (xdisplay, stage_x11->xwin,
- NULL,
- NULL,
- NULL, 0,
- NULL, NULL, NULL);
-
- pid = getpid ();
- XChangeProperty (xdisplay,
- stage_x11->xwin,
- backend_x11->atom_NET_WM_PID, XA_CARDINAL, 32,
- PropModeReplace,
- (guchar *) &pid, 1);
-}
-
-static inline void
-set_wm_title (MetaStageX11 *stage_x11)
-{
- MetaStageImpl *stage_impl = META_STAGE_IMPL (stage_x11);
- MetaClutterBackendX11 *backend_x11 =
- META_CLUTTER_BACKEND_X11 (stage_impl->backend);
- Display *xdisplay = meta_clutter_x11_get_default_display ();
-
- if (stage_x11->xwin == None)
- return;
-
- if (stage_x11->title == NULL)
- {
- XDeleteProperty (xdisplay,
- stage_x11->xwin,
- backend_x11->atom_NET_WM_NAME);
- }
- else
- {
- XChangeProperty (xdisplay,
- stage_x11->xwin,
- backend_x11->atom_NET_WM_NAME,
- backend_x11->atom_UTF8_STRING,
- 8,
- PropModeReplace,
- (unsigned char *) stage_x11->title,
- (int) strlen (stage_x11->title));
- }
-}
-
-static void
-meta_stage_x11_unrealize (ClutterStageWindow *stage_window)
-{
- MetaStageX11 *stage_x11 = META_STAGE_X11 (stage_window);
-
- if (clutter_stages_by_xid != NULL)
- {
- g_hash_table_remove (clutter_stages_by_xid,
- GINT_TO_POINTER (stage_x11->xwin));
- }
-
- clutter_stage_window_parent_iface->unrealize (stage_window);
-
- g_clear_object (&stage_x11->onscreen);
-}
-
-static CoglOnscreen *
-create_onscreen (CoglContext *cogl_context,
- int width,
- int height)
-{
- CoglDisplay *cogl_display = cogl_context_get_display (cogl_context);
- CoglRenderer *cogl_renderer = cogl_display_get_renderer (cogl_display);
-
- switch (cogl_renderer_get_winsys_id (cogl_renderer))
- {
- case COGL_WINSYS_ID_GLX:
-#ifdef COGL_HAS_GLX_SUPPORT
- return COGL_ONSCREEN (cogl_onscreen_glx_new (cogl_context,
- width, height));
-#else
- g_assert_not_reached ();
- break;
-#endif
- case COGL_WINSYS_ID_EGL_XLIB:
-#ifdef COGL_HAS_EGL_SUPPORT
- return COGL_ONSCREEN (cogl_onscreen_xlib_new (cogl_context,
- width, height));
-#else
- g_assert_not_reached ();
- break;
-#endif
- default:
- g_assert_not_reached ();
- return NULL;
- }
-}
-
-static gboolean
-meta_stage_x11_realize (ClutterStageWindow *stage_window)
-{
- MetaStageX11 *stage_x11 = META_STAGE_X11 (stage_window);
- MetaStageImpl *stage_impl = META_STAGE_IMPL (stage_window);
- ClutterBackend *backend = CLUTTER_BACKEND (stage_impl->backend);
- MetaSeatX11 *seat_x11 = META_SEAT_X11 (clutter_backend_get_default_seat (backend));
- Display *xdisplay = meta_clutter_x11_get_default_display ();
- float width, height;
- GError *error = NULL;
-
- clutter_actor_get_size (CLUTTER_ACTOR (stage_impl->wrapper), &width, &height);
-
- stage_x11->onscreen = create_onscreen (backend->cogl_context, width, height);
-
- if (META_IS_BACKEND_X11_CM (stage_x11->backend))
- {
- MetaRenderer *renderer = meta_backend_get_renderer (stage_x11->backend);
- MetaRendererX11Cm *renderer_x11_cm = META_RENDERER_X11_CM (renderer);
-
- meta_renderer_x11_cm_init_screen_view (renderer_x11_cm,
- stage_x11->onscreen,
- stage_x11->xwin_width,
- stage_x11->xwin_height);
- }
-
- /* We just created a window of the size of the actor. No need to fix
- the size of the stage, just update it. */
- stage_x11->xwin_width = width;
- stage_x11->xwin_height = height;
-
- if (!cogl_framebuffer_allocate (COGL_FRAMEBUFFER (stage_x11->onscreen), &error))
- {
- g_warning ("Failed to allocate stage: %s", error->message);
- g_error_free (error);
- g_object_unref (stage_x11->onscreen);
- abort();
- }
-
- if (!(clutter_stage_window_parent_iface->realize (stage_window)))
- return FALSE;
-
- stage_x11->xwin =
- cogl_x11_onscreen_get_x11_window (COGL_X11_ONSCREEN (stage_x11->onscreen));
-
- if (clutter_stages_by_xid == NULL)
- clutter_stages_by_xid = g_hash_table_new (NULL, NULL);
-
- g_hash_table_insert (clutter_stages_by_xid,
- GINT_TO_POINTER (stage_x11->xwin),
- stage_x11);
-
- set_wm_pid (stage_x11);
- set_wm_title (stage_x11);
-
- /* we unconditionally select input events even with event retrieval
- * disabled because we need to guarantee that the Clutter internal
- * state is maintained when calling meta_clutter_x11_handle_event() without
- * requiring applications or embedding toolkits to select events
- * themselves. if we did that, we'd have to document the events to be
- * selected, and also update applications and embedding toolkits each
- * time we added a new mask, or a new class of events.
- *
- * see: http://bugzilla.clutter-project.org/show_bug.cgi?id=998
- * for the rationale of why we did conditional selection. it is now
- * clear that a compositor should clear out the input region, since
- * it cannot assume a perfectly clean slate coming from us.
- *
- * see: http://bugzilla.clutter-project.org/show_bug.cgi?id=2228
- * for an example of things that break if we do conditional event
- * selection.
- */
- XSelectInput (xdisplay, stage_x11->xwin, META_STAGE_X11_EVENT_MASK);
-
- meta_seat_x11_select_stage_events (seat_x11, stage_impl->wrapper);
-
- meta_stage_x11_fix_window_size (stage_x11,
- stage_x11->xwin_width,
- stage_x11->xwin_height);
- meta_stage_x11_set_wm_protocols (stage_x11);
-
- return TRUE;
-}
-
-static void
-meta_stage_x11_set_title (ClutterStageWindow *stage_window,
- const char *title)
-{
- MetaStageX11 *stage_x11 = META_STAGE_X11 (stage_window);
-
- g_free (stage_x11->title);
- stage_x11->title = g_strdup (title);
- set_wm_title (stage_x11);
-}
-
-static inline void
-update_wm_hints (MetaStageX11 *stage_x11)
-{
- Display *xdisplay = meta_clutter_x11_get_default_display ();
- XWMHints wm_hints;
-
- if (stage_x11->wm_state & STAGE_X11_WITHDRAWN)
- return;
-
- wm_hints.flags = StateHint | InputHint;
- wm_hints.initial_state = NormalState;
- wm_hints.input = True;
-
- XSetWMHints (xdisplay, stage_x11->xwin, &wm_hints);
-}
-
-static void
-set_stage_x11_state (MetaStageX11 *stage_x11,
- MetaStageX11State unset_flags,
- MetaStageX11State set_flags)
-{
- MetaStageX11State new_stage_state, old_stage_state;
-
- old_stage_state = stage_x11->wm_state;
-
- new_stage_state = old_stage_state;
- new_stage_state |= set_flags;
- new_stage_state &= ~unset_flags;
-
- if (new_stage_state == old_stage_state)
- return;
-
- stage_x11->wm_state = new_stage_state;
-}
-
-static void
-meta_stage_x11_show (ClutterStageWindow *stage_window,
- gboolean do_raise)
-{
- MetaStageX11 *stage_x11 = META_STAGE_X11 (stage_window);
- MetaStageImpl *stage_impl = META_STAGE_IMPL (stage_x11);
-
- if (stage_x11->xwin != None)
- {
- Display *xdisplay = meta_clutter_x11_get_default_display ();
-
- if (do_raise)
- {
- XRaiseWindow (xdisplay, stage_x11->xwin);
- }
-
- if (!STAGE_X11_IS_MAPPED (stage_x11))
- {
- set_stage_x11_state (stage_x11, STAGE_X11_WITHDRAWN, 0);
-
- update_wm_hints (stage_x11);
- }
-
- g_assert (STAGE_X11_IS_MAPPED (stage_x11));
-
- clutter_actor_map (CLUTTER_ACTOR (stage_impl->wrapper));
-
- XMapWindow (xdisplay, stage_x11->xwin);
- }
-}
-
-static void
-meta_stage_x11_hide (ClutterStageWindow *stage_window)
-{
- MetaStageX11 *stage_x11 = META_STAGE_X11 (stage_window);
- MetaStageImpl *stage_impl = META_STAGE_IMPL (stage_x11);
-
- if (stage_x11->xwin != None)
- {
- Display *xdisplay = meta_clutter_x11_get_default_display ();
-
- if (STAGE_X11_IS_MAPPED (stage_x11))
- set_stage_x11_state (stage_x11, 0, STAGE_X11_WITHDRAWN);
-
- g_assert (!STAGE_X11_IS_MAPPED (stage_x11));
-
- clutter_actor_unmap (CLUTTER_ACTOR (stage_impl->wrapper));
-
- XWithdrawWindow (xdisplay, stage_x11->xwin, 0);
- }
-}
-
-static gboolean
-meta_stage_x11_can_clip_redraws (ClutterStageWindow *stage_window)
-{
- MetaStageX11 *stage_x11 = META_STAGE_X11 (stage_window);
-
- /* while resizing a window, clipped redraws are disabled in order to
- * avoid artefacts.
- */
- return stage_x11->clipped_redraws_cool_off == 0;
-}
-
-static GList *
-meta_stage_x11_get_views (ClutterStageWindow *stage_window)
-{
- MetaStageX11 *stage_x11 = META_STAGE_X11 (stage_window);
- MetaRenderer *renderer = meta_backend_get_renderer (stage_x11->backend);
-
- return meta_renderer_get_views (renderer);
-}
-
-static void
-meta_stage_x11_redraw_view (ClutterStageWindow *stage_window,
- ClutterStageView *view,
- ClutterFrame *frame)
-{
- clutter_stage_window_parent_iface->redraw_view (stage_window, view, frame);
- clutter_frame_set_result (frame, CLUTTER_FRAME_RESULT_PENDING_PRESENTED);
-}
-
-static void
-meta_stage_x11_finalize (GObject *object)
-{
- MetaStageX11 *stage_x11 = META_STAGE_X11 (object);
-
- g_free (stage_x11->title);
-
- G_OBJECT_CLASS (meta_stage_x11_parent_class)->finalize (object);
-}
-
-static void
-meta_stage_x11_class_init (MetaStageX11Class *klass)
-{
- GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
-
- gobject_class->finalize = meta_stage_x11_finalize;
-}
-
-static void
-meta_stage_x11_init (MetaStageX11 *stage)
-{
- stage->xwin = None;
- stage->xwin_width = 640;
- stage->xwin_height = 480;
-
- stage->wm_state = STAGE_X11_WITHDRAWN;
-
- stage->title = NULL;
-
- stage->backend = meta_get_backend ();
- g_assert (stage->backend);
-}
-
-static void
-clutter_stage_window_iface_init (ClutterStageWindowInterface *iface)
-{
- clutter_stage_window_parent_iface = g_type_interface_peek_parent (iface);
-
- iface->set_title = meta_stage_x11_set_title;
- iface->show = meta_stage_x11_show;
- iface->hide = meta_stage_x11_hide;
- iface->resize = meta_stage_x11_resize;
- iface->get_geometry = meta_stage_x11_get_geometry;
- iface->realize = meta_stage_x11_realize;
- iface->unrealize = meta_stage_x11_unrealize;
- iface->can_clip_redraws = meta_stage_x11_can_clip_redraws;
- iface->get_views = meta_stage_x11_get_views;
- iface->redraw_view = meta_stage_x11_redraw_view;
-}
-
-static inline void
-set_user_time (MetaClutterBackendX11 *backend_x11,
- MetaStageX11 *stage_x11,
- long timestamp)
-{
- if (timestamp != CLUTTER_CURRENT_TIME)
- {
- Display *xdisplay = meta_clutter_x11_get_default_display ();
-
- XChangeProperty (xdisplay,
- stage_x11->xwin,
- backend_x11->atom_NET_WM_USER_TIME,
- XA_CARDINAL, 32,
- PropModeReplace,
- (unsigned char *) &timestamp, 1);
- }
-}
-
-static gboolean
-handle_wm_protocols_event (MetaClutterBackendX11 *backend_x11,
- MetaStageX11 *stage_x11,
- XEvent *xevent)
-{
- Atom atom = (Atom) xevent->xclient.data.l[0];
-
- if (atom == backend_x11->atom_WM_DELETE_WINDOW &&
- xevent->xany.window == stage_x11->xwin)
- {
- set_user_time (backend_x11, stage_x11, xevent->xclient.data.l[1]);
-
- return TRUE;
- }
- else if (atom == backend_x11->atom_NET_WM_PING &&
- xevent->xany.window == stage_x11->xwin)
- {
- XClientMessageEvent xclient = xevent->xclient;
- Display *xdisplay = meta_clutter_x11_get_default_display ();
-
- xclient.window = backend_x11->xwin_root;
- XSendEvent (xdisplay, xclient.window,
- False,
- SubstructureRedirectMask | SubstructureNotifyMask,
- (XEvent *) &xclient);
- return FALSE;
- }
-
- /* do not send any of the WM_PROTOCOLS events to the queue */
- return FALSE;
-}
-
-static gboolean
-clipped_redraws_cool_off_cb (void *data)
-{
- MetaStageX11 *stage_x11 = data;
-
- stage_x11->clipped_redraws_cool_off = 0;
-
- return G_SOURCE_REMOVE;
-}
-
-gboolean
-meta_stage_x11_translate_event (MetaStageX11 *stage_x11,
- XEvent *xevent,
- ClutterEvent *event)
-{
- MetaStageImpl *stage_impl;
- gboolean res = FALSE;
- MetaClutterBackendX11 *clutter_backend_x11;
- ClutterStage *stage;
- MetaBackend *backend;
-
- stage_impl = meta_x11_get_stage_window_from_window (xevent->xany.window);
- if (stage_impl == NULL)
- return FALSE;
-
- stage = stage_impl->wrapper;
- backend = stage_x11->backend;
- clutter_backend_x11 = META_CLUTTER_BACKEND_X11 (stage_impl->backend);
-
- switch (xevent->type)
- {
- case ConfigureNotify:
- {
- gboolean size_changed = FALSE;
- int stage_width;
- int stage_height;
-
- g_debug ("ConfigureNotify[%x] (%d, %d)",
- (unsigned int) stage_x11->xwin,
- xevent->xconfigure.width,
- xevent->xconfigure.height);
-
- if ((stage_x11->xwin_width != xevent->xconfigure.width) ||
- (stage_x11->xwin_height != xevent->xconfigure.height))
- {
- size_changed = TRUE;
- stage_x11->xwin_width = xevent->xconfigure.width;
- stage_x11->xwin_height = xevent->xconfigure.height;
- }
-
- stage_width = xevent->xconfigure.width;
- stage_height = xevent->xconfigure.height;
-
- if (META_IS_BACKEND_X11_CM (stage_x11->backend))
- {
- clutter_actor_set_size (CLUTTER_ACTOR (stage),
- stage_width,
- stage_height);
- }
-
- if (size_changed)
- {
- /* XXX: This is a workaround for a race condition when
- * resizing windows while there are in-flight
- * glXCopySubBuffer blits happening.
- *
- * The problem stems from the fact that rectangles for the
- * blits are described relative to the bottom left of the
- * window and because we can't guarantee control over the X
- * window gravity used when resizing so the gravity is
- * typically NorthWest not SouthWest.
- *
- * This means if you grow a window vertically the server
- * will make sure to place the old contents of the window
- * at the top-left/north-west of your new larger window, but
- * that may happen asynchronous to GLX preparing to do a
- * blit specified relative to the bottom-left/south-west of
- * the window (based on the old smaller window geometry).
- *
- * When the GLX issued blit finally happens relative to the
- * new bottom of your window, the destination will have
- * shifted relative to the top-left where all the pixels you
- * care about are so it will result in a nasty artefact
- * making resizing look very ugly!
- *
- * We can't currently fix this completely, in-part because
- * the window manager tends to trample any gravity we might
- * set. This workaround instead simply disables blits for a
- * while if we are notified of any resizes happening so if
- * the user is resizing a window via the window manager then
- * they may see an artefact for one frame but then we will
- * fallback to redrawing the full stage until the cooling
- * off period is over.
- */
- g_clear_handle_id (&stage_x11->clipped_redraws_cool_off,
- g_source_remove);
-
- stage_x11->clipped_redraws_cool_off =
- clutter_threads_add_timeout (1000,
- clipped_redraws_cool_off_cb,
- stage_x11);
-
- /* Queue a relayout - we want glViewport to be called
- * with the correct values, and this is done in ClutterStage
- * via cogl_onscreen_clutter_backend_set_size ().
- *
- * We queue a relayout, because if this ConfigureNotify is
- * in response to a size we set in the application, the
- * set_size() call above is essentially a null-op.
- *
- * Make sure we do this only when the size has changed,
- * otherwise we end up relayouting on window moves.
- */
- clutter_actor_queue_relayout (CLUTTER_ACTOR (stage));
-
- /* the resize process is complete, so we can ask the stage
- * to set up the GL viewport with the new size
- */
- clutter_stage_ensure_viewport (stage);
-
- /* If this was a result of the Xrandr change when running as a
- * X11 compositing manager, we need to reset the legacy
- * stage view, now that it has a new size.
- */
- if (META_IS_BACKEND_X11_CM (stage_x11->backend))
- {
- MetaRenderer *renderer = meta_backend_get_renderer (backend);
- MetaRendererX11Cm *renderer_x11_cm =
- META_RENDERER_X11_CM (renderer);
-
- meta_renderer_x11_cm_resize (renderer_x11_cm,
- stage_width,
- stage_height);
- }
- }
- }
- break;
-
- case FocusIn:
- meta_stage_set_active ((MetaStage *) stage_impl->wrapper, TRUE);
- break;
-
- case FocusOut:
- meta_stage_set_active ((MetaStage *) stage_impl->wrapper, FALSE);
- break;
-
- case Expose:
- {
- XExposeEvent *expose = (XExposeEvent *) xevent;
- cairo_rectangle_int_t clip;
-
- g_debug ("expose for stage: win:0x%x - "
- "redrawing area (x: %d, y: %d, width: %d, height: %d)",
- (unsigned int) xevent->xany.window,
- expose->x,
- expose->y,
- expose->width,
- expose->height);
-
- clip.x = expose->x;
- clip.y = expose->y;
- clip.width = expose->width;
- clip.height = expose->height;
- clutter_actor_queue_redraw_with_clip (CLUTTER_ACTOR (stage), &clip);
- }
- break;
-
- case DestroyNotify:
- g_debug ("Destroy notification received for stage, win:0x%x",
- (unsigned int) xevent->xany.window);
-
- g_return_val_if_fail (META_IS_STAGE_X11_NESTED (stage_x11),
- FALSE);
- meta_context_terminate (meta_backend_get_context (backend));
- res = FALSE;
- break;
-
- case ClientMessage:
- g_debug ("Client message for stage, win:0x%x",
- (unsigned int) xevent->xany.window);
-
- if (xevent->xclient.message_type == clutter_backend_x11->atom_WM_PROTOCOLS)
- {
- if (handle_wm_protocols_event (clutter_backend_x11,
- stage_x11,
- xevent))
- {
- g_return_val_if_fail (META_IS_STAGE_X11_NESTED (stage_x11),
- FALSE);
- meta_context_terminate (meta_backend_get_context (backend));
- res = FALSE;
- }
- }
-
- break;
-
- default:
- res = FALSE;
- break;
- }
-
- return res;
-}
-
-Window
-meta_x11_get_stage_window (ClutterStage *stage)
-{
- ClutterStageWindow *impl;
-
- g_return_val_if_fail (CLUTTER_IS_STAGE (stage), None);
-
- impl = _clutter_stage_get_window (stage);
- g_assert (META_IS_STAGE_X11 (impl));
-
- return META_STAGE_X11 (impl)->xwin;
-}
-
-static MetaStageImpl *
-meta_x11_get_stage_window_from_window (Window win)
-{
- if (clutter_stages_by_xid == NULL)
- return NULL;
-
- return g_hash_table_lookup (clutter_stages_by_xid,
- GINT_TO_POINTER (win));
-}
-
-ClutterStage *
-meta_x11_get_stage_from_window (Window win)
-{
- MetaStageImpl *stage_impl;
-
- stage_impl = meta_x11_get_stage_window_from_window (win);
-
- if (stage_impl != NULL)
- return stage_impl->wrapper;
-
- return NULL;
-}
-
-void
-meta_stage_x11_set_user_time (MetaStageX11 *stage_x11,
- uint32_t user_time)
-{
- MetaStageImpl *stage_impl = META_STAGE_IMPL (stage_x11);
- MetaClutterBackendX11 *backend_x11 =
- META_CLUTTER_BACKEND_X11 (stage_impl->backend);
-
- set_user_time (backend_x11, stage_x11, user_time);
-}
diff --git a/src/backends/x11/meta-stage-x11.h b/src/backends/x11/meta-stage-x11.h
deleted file mode 100644
index 041767167..000000000
--- a/src/backends/x11/meta-stage-x11.h
+++ /dev/null
@@ -1,96 +0,0 @@
-/* Clutter.
- * An OpenGL based 'interactive canvas' library.
- * Authored By Matthew Allum <mallum@openedhand.com>
- * Copyright (C) 2006-2007 OpenedHand
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
- *
- *
- */
-
-#ifndef META_STAGE_X11_H
-#define META_STAGE_X11_H
-
-#include <X11/Xlib.h>
-#include <X11/Xatom.h>
-
-#include "backends/meta-backend-private.h"
-#include "backends/x11/meta-clutter-backend-x11.h"
-#include "clutter/clutter-mutter.h"
-
-G_BEGIN_DECLS
-
-#define META_TYPE_STAGE_X11 (meta_stage_x11_get_type ())
-#define META_STAGE_X11(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), META_TYPE_STAGE_X11, MetaStageX11))
-#define META_IS_STAGE_X11(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), META_TYPE_STAGE_X11))
-#define META_STAGE_X11_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), META_TYPE_STAGE_X11, MetaStageX11Class))
-#define META_IS_STAGE_X11_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), META_TYPE_STAGE_X11))
-#define META_STAGE_X11_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), META_TYPE_STAGE_X11, MetaStageX11Class))
-
-typedef struct _MetaStageX11 MetaStageX11;
-typedef struct _MetaStageX11Class MetaStageX11Class;
-
-G_DEFINE_AUTOPTR_CLEANUP_FUNC (MetaStageX11, g_object_unref)
-
-typedef enum
-{
- STAGE_X11_WITHDRAWN = 1 << 1
-} MetaStageX11State;
-
-struct _MetaStageX11
-{
- MetaStageImpl parent_instance;
-
- MetaBackend *backend;
-
- CoglOnscreen *onscreen;
- Window xwin;
- gint xwin_width;
- gint xwin_height; /* FIXME target_width / height */
-
- CoglFrameClosure *frame_closure;
-
- gchar *title;
-
- guint clipped_redraws_cool_off;
-
- MetaStageX11State wm_state;
-
- guint viewport_initialized : 1;
-};
-
-struct _MetaStageX11Class
-{
- MetaStageImplClass parent_class;
-};
-
-CLUTTER_EXPORT
-GType meta_stage_x11_get_type (void) G_GNUC_CONST;
-
-/* Private to subclasses */
-void meta_stage_x11_set_user_time (MetaStageX11 *stage_x11,
- guint32 user_time);
-
-gboolean meta_stage_x11_translate_event (MetaStageX11 *stage_x11,
- XEvent *xevent,
- ClutterEvent *event);
-
-ClutterStage *meta_x11_get_stage_from_window (Window win);
-
-Window meta_x11_get_stage_window (ClutterStage *stage);
-
-
-G_END_DECLS
-
-#endif /* META_STAGE_H */
diff --git a/src/backends/x11/meta-virtual-input-device-x11.c b/src/backends/x11/meta-virtual-input-device-x11.c
deleted file mode 100644
index 54bb43ad1..000000000
--- a/src/backends/x11/meta-virtual-input-device-x11.c
+++ /dev/null
@@ -1,253 +0,0 @@
-/*
- * Copyright (C) 2016 Red Hat Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
- *
- * Author: Jonas Ådahl <jadahl@gmail.com>
- */
-
-#include "config.h"
-
-#include <glib-object.h>
-
-#include <X11/extensions/XTest.h>
-
-#include "backends/x11/meta-clutter-backend-x11.h"
-#include "clutter/clutter.h"
-#include "meta-keymap-x11.h"
-#include "meta-virtual-input-device-x11.h"
-
-#define DISCRETE_SCROLL_STEP 10.0
-
-struct _MetaVirtualInputDeviceX11
-{
- ClutterVirtualInputDevice parent;
-
- double accum_scroll_dx;
- double accum_scroll_dy;
-};
-
-G_DEFINE_TYPE (MetaVirtualInputDeviceX11,
- meta_virtual_input_device_x11,
- CLUTTER_TYPE_VIRTUAL_INPUT_DEVICE)
-
-static void
-meta_virtual_input_device_x11_notify_relative_motion (ClutterVirtualInputDevice *virtual_device,
- uint64_t time_us,
- double dx,
- double dy)
-{
- XTestFakeRelativeMotionEvent (meta_clutter_x11_get_default_display (),
- (int) dx,
- (int) dy,
- 0);
-}
-
-static void
-meta_virtual_input_device_x11_notify_absolute_motion (ClutterVirtualInputDevice *virtual_device,
- uint64_t time_us,
- double x,
- double y)
-{
- XTestFakeMotionEvent (meta_clutter_x11_get_default_display (),
- meta_clutter_x11_get_default_screen (),
- (int) x,
- (int) y,
- 0);
-}
-
-static void
-meta_virtual_input_device_x11_notify_button (ClutterVirtualInputDevice *virtual_device,
- uint64_t time_us,
- uint32_t button,
- ClutterButtonState button_state)
-{
- XTestFakeButtonEvent (meta_clutter_x11_get_default_display (),
- button, button_state == CLUTTER_BUTTON_STATE_PRESSED, 0);
-}
-
-static void
-meta_virtual_input_device_x11_notify_discrete_scroll (ClutterVirtualInputDevice *virtual_device,
- uint64_t time_us,
- ClutterScrollDirection direction,
- ClutterScrollSource scroll_source)
-{
- Display *xdisplay = meta_clutter_x11_get_default_display ();
- int button;
-
- switch (direction)
- {
- case CLUTTER_SCROLL_UP:
- button = 4;
- break;
- case CLUTTER_SCROLL_DOWN:
- button = 5;
- break;
- case CLUTTER_SCROLL_LEFT:
- button = 6;
- break;
- case CLUTTER_SCROLL_RIGHT:
- button = 7;
- break;
- default:
- g_warn_if_reached ();
- return;
- }
-
- XTestFakeButtonEvent (xdisplay, button, True, 0);
- XTestFakeButtonEvent (xdisplay, button, False, 0);
-}
-
-static void
-meta_virtual_input_device_x11_notify_scroll_continuous (ClutterVirtualInputDevice *virtual_device,
- uint64_t time_us,
- double dx,
- double dy,
- ClutterScrollSource scroll_source,
- ClutterScrollFinishFlags finish_flags)
-{
- MetaVirtualInputDeviceX11 *virtual_device_x11;
- ClutterScrollDirection direction;
- int i, n_xscrolls, n_yscrolls;
-
- virtual_device_x11 = META_VIRTUAL_INPUT_DEVICE_X11 (virtual_device);
-
- virtual_device_x11->accum_scroll_dx += dx;
- virtual_device_x11->accum_scroll_dy += dy;
- n_xscrolls = floor ((fabs (virtual_device_x11->accum_scroll_dx) + DBL_EPSILON) /
- DISCRETE_SCROLL_STEP);
- n_yscrolls = floor ((fabs (virtual_device_x11->accum_scroll_dy) + DBL_EPSILON) /
- DISCRETE_SCROLL_STEP);
-
- direction = virtual_device_x11->accum_scroll_dx > 0 ? CLUTTER_SCROLL_RIGHT
- : CLUTTER_SCROLL_LEFT;
- for (i = 0; i < n_xscrolls; ++i)
- {
- meta_virtual_input_device_x11_notify_discrete_scroll (
- virtual_device, time_us, direction, CLUTTER_SCROLL_SOURCE_WHEEL);
- }
-
- direction = virtual_device_x11->accum_scroll_dy > 0 ? CLUTTER_SCROLL_DOWN
- : CLUTTER_SCROLL_UP;
- for (i = 0; i < n_yscrolls; ++i)
- {
- meta_virtual_input_device_x11_notify_discrete_scroll (
- virtual_device, time_us, direction, CLUTTER_SCROLL_SOURCE_WHEEL);
- }
-
- virtual_device_x11->accum_scroll_dx =
- fmod (virtual_device_x11->accum_scroll_dx, DISCRETE_SCROLL_STEP);
- virtual_device_x11->accum_scroll_dy =
- fmod (virtual_device_x11->accum_scroll_dy, DISCRETE_SCROLL_STEP);
-}
-
-static void
-meta_virtual_input_device_x11_notify_key (ClutterVirtualInputDevice *virtual_device,
- uint64_t time_us,
- uint32_t key,
- ClutterKeyState key_state)
-{
- XTestFakeKeyEvent (meta_clutter_x11_get_default_display (),
- key + 8, key_state == CLUTTER_KEY_STATE_PRESSED, 0);
-}
-
-static void
-meta_virtual_input_device_x11_notify_keyval (ClutterVirtualInputDevice *virtual_device,
- uint64_t time_us,
- uint32_t keyval,
- ClutterKeyState key_state)
-{
- ClutterBackend *backend = clutter_get_default_backend ();
- ClutterSeat *seat = clutter_backend_get_default_seat (backend);
- MetaKeymapX11 *keymap = META_KEYMAP_X11 (clutter_seat_get_keymap (seat));
- uint32_t keycode, level;
-
- if (!meta_keymap_x11_keycode_for_keyval (keymap, keyval, &keycode, &level))
- {
- level = 0;
-
- if (!meta_keymap_x11_reserve_keycode (keymap, keyval, &keycode))
- {
- g_warning ("No keycode found for keyval %x in current group", keyval);
- return;
- }
- }
-
- if (!meta_keymap_x11_get_is_modifier (keymap, keycode) &&
- key_state == CLUTTER_KEY_STATE_PRESSED)
- meta_keymap_x11_latch_modifiers (keymap, level, TRUE);
-
- XTestFakeKeyEvent (meta_clutter_x11_get_default_display (),
- (KeyCode) keycode,
- key_state == CLUTTER_KEY_STATE_PRESSED, 0);
-
-
- if (key_state == CLUTTER_KEY_STATE_RELEASED)
- {
- if (!meta_keymap_x11_get_is_modifier (keymap, keycode))
- meta_keymap_x11_latch_modifiers (keymap, level, FALSE);
- meta_keymap_x11_release_keycode_if_needed (keymap, keycode);
- }
-}
-
-static void
-meta_virtual_input_device_x11_notify_touch_down (ClutterVirtualInputDevice *virtual_device,
- uint64_t time_us,
- int device_slot,
- double x,
- double y)
-{
- g_warning ("Virtual touch motion not implemented under X11");
-}
-
-static void
-meta_virtual_input_device_x11_notify_touch_motion (ClutterVirtualInputDevice *virtual_device,
- uint64_t time_us,
- int device_slot,
- double x,
- double y)
-{
- g_warning ("Virtual touch motion not implemented under X11");
-}
-
-static void
-meta_virtual_input_device_x11_notify_touch_up (ClutterVirtualInputDevice *virtual_device,
- uint64_t time_us,
- int device_slot)
-{
- g_warning ("Virtual touch motion not implemented under X11");
-}
-
-static void
-meta_virtual_input_device_x11_init (MetaVirtualInputDeviceX11 *virtual_device_x11)
-{
-}
-
-static void
-meta_virtual_input_device_x11_class_init (MetaVirtualInputDeviceX11Class *klass)
-{
- ClutterVirtualInputDeviceClass *virtual_input_device_class =
- CLUTTER_VIRTUAL_INPUT_DEVICE_CLASS (klass);
-
- virtual_input_device_class->notify_relative_motion = meta_virtual_input_device_x11_notify_relative_motion;
- virtual_input_device_class->notify_absolute_motion = meta_virtual_input_device_x11_notify_absolute_motion;
- virtual_input_device_class->notify_button = meta_virtual_input_device_x11_notify_button;
- virtual_input_device_class->notify_discrete_scroll = meta_virtual_input_device_x11_notify_discrete_scroll;
- virtual_input_device_class->notify_scroll_continuous = meta_virtual_input_device_x11_notify_scroll_continuous;
- virtual_input_device_class->notify_key = meta_virtual_input_device_x11_notify_key;
- virtual_input_device_class->notify_keyval = meta_virtual_input_device_x11_notify_keyval;
- virtual_input_device_class->notify_touch_down = meta_virtual_input_device_x11_notify_touch_down;
- virtual_input_device_class->notify_touch_motion = meta_virtual_input_device_x11_notify_touch_motion;
- virtual_input_device_class->notify_touch_up = meta_virtual_input_device_x11_notify_touch_up;
-}
diff --git a/src/backends/x11/meta-virtual-input-device-x11.h b/src/backends/x11/meta-virtual-input-device-x11.h
deleted file mode 100644
index 88c41ae8d..000000000
--- a/src/backends/x11/meta-virtual-input-device-x11.h
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * Copyright (C) 2016 Red Hat Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
- *
- * Author: Jonas Ådahl <jadahl@gmail.com>
- */
-
-#ifndef META_VIRTUAL_INPUT_DEVICE_X11_H
-#define META_VIRTUAL_INPUT_DEVICE_X11_H
-
-#include "clutter/clutter.h"
-
-#define META_TYPE_VIRTUAL_INPUT_DEVICE_X11 (meta_virtual_input_device_x11_get_type ())
-G_DECLARE_FINAL_TYPE (MetaVirtualInputDeviceX11,
- meta_virtual_input_device_x11,
- META, VIRTUAL_INPUT_DEVICE_X11,
- ClutterVirtualInputDevice)
-
-#endif /* META_VIRTUAL_INPUT_DEVICE_X11_H */
diff --git a/src/backends/x11/meta-xkb-a11y-x11.c b/src/backends/x11/meta-xkb-a11y-x11.c
deleted file mode 100644
index c73b9dc4f..000000000
--- a/src/backends/x11/meta-xkb-a11y-x11.c
+++ /dev/null
@@ -1,339 +0,0 @@
-/*
- * Copyright © 2001 Ximian, Inc.
- * Copyright (C) 2007 William Jon McCann <mccann@jhu.edu>
- * Copyright (C) 2017 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- */
-
-#include "config.h"
-
-#include <X11/XKBlib.h>
-#include <X11/extensions/XKBstr.h>
-
-#include "backends/x11/meta-clutter-backend-x11.h"
-#include "backends/x11/meta-xkb-a11y-x11.h"
-#include "core/display-private.h"
-#include "meta/meta-x11-errors.h"
-
-#define DEFAULT_XKB_SET_CONTROLS_MASK XkbSlowKeysMask | \
- XkbBounceKeysMask | \
- XkbStickyKeysMask | \
- XkbMouseKeysMask | \
- XkbMouseKeysAccelMask | \
- XkbAccessXKeysMask | \
- XkbAccessXTimeoutMask | \
- XkbAccessXFeedbackMask | \
- XkbControlsEnabledMask
-
-static int _xkb_event_base;
-
-static XkbDescRec *
-get_xkb_desc_rec (Display *xdisplay)
-{
- XkbDescRec *desc;
- Status status = Success;
-
- meta_clutter_x11_trap_x_errors ();
- desc = XkbGetMap (xdisplay, XkbAllMapComponentsMask, XkbUseCoreKbd);
- if (desc != NULL)
- {
- desc->ctrls = NULL;
- status = XkbGetControls (xdisplay, XkbAllControlsMask, desc);
- }
- meta_clutter_x11_untrap_x_errors ();
-
- g_return_val_if_fail (desc != NULL, NULL);
- g_return_val_if_fail (desc->ctrls != NULL, NULL);
- g_return_val_if_fail (status == Success, NULL);
-
- return desc;
-}
-
-static void
-set_xkb_desc_rec (Display *xdisplay,
- XkbDescRec *desc)
-{
- meta_clutter_x11_trap_x_errors ();
- XkbSetControls (xdisplay, DEFAULT_XKB_SET_CONTROLS_MASK, desc);
- XSync (xdisplay, FALSE);
- meta_clutter_x11_untrap_x_errors ();
-}
-
-static void
-check_settings_changed (ClutterSeat *seat)
-{
- Display *xdisplay = meta_clutter_x11_get_default_display ();
- MetaKbdA11ySettings kbd_a11y_settings;
- MetaKeyboardA11yFlags what_changed = 0;
- MetaInputSettings *input_settings;
- XkbDescRec *desc;
-
- desc = get_xkb_desc_rec (xdisplay);
- if (!desc)
- return;
-
- input_settings = meta_backend_get_input_settings (meta_get_backend ());
- meta_input_settings_get_kbd_a11y_settings (input_settings,
- &kbd_a11y_settings);
-
- if (desc->ctrls->enabled_ctrls & XkbSlowKeysMask &&
- !(kbd_a11y_settings.controls & META_A11Y_SLOW_KEYS_ENABLED))
- {
- what_changed |= META_A11Y_SLOW_KEYS_ENABLED;
- kbd_a11y_settings.controls |= META_A11Y_SLOW_KEYS_ENABLED;
- }
- else if (!(desc->ctrls->enabled_ctrls & XkbSlowKeysMask) &&
- kbd_a11y_settings.controls & META_A11Y_SLOW_KEYS_ENABLED)
- {
- what_changed |= META_A11Y_SLOW_KEYS_ENABLED;
- kbd_a11y_settings.controls &= ~META_A11Y_SLOW_KEYS_ENABLED;
- }
-
- if (desc->ctrls->enabled_ctrls & XkbStickyKeysMask &&
- !(kbd_a11y_settings.controls & META_A11Y_STICKY_KEYS_ENABLED))
- {
- what_changed |= META_A11Y_STICKY_KEYS_ENABLED;
- kbd_a11y_settings.controls |= META_A11Y_STICKY_KEYS_ENABLED;
- }
- else if (!(desc->ctrls->enabled_ctrls & XkbStickyKeysMask) &&
- kbd_a11y_settings.controls & META_A11Y_STICKY_KEYS_ENABLED)
- {
- what_changed |= META_A11Y_STICKY_KEYS_ENABLED;
- kbd_a11y_settings.controls &= ~META_A11Y_STICKY_KEYS_ENABLED;
- }
-
- if (what_changed)
- {
- meta_input_settings_notify_kbd_a11y_change (input_settings,
- kbd_a11y_settings.controls,
- what_changed);
- g_signal_emit_by_name (seat,
- "kbd-a11y-flags-changed",
- kbd_a11y_settings.controls,
- what_changed);
- }
-
- XkbFreeKeyboard (desc, XkbAllComponentsMask, TRUE);
-}
-
-static MetaX11FilterReturn
-xkb_a11y_event_filter (XEvent *xevent,
- ClutterEvent *clutter_event,
- gpointer data)
-{
- ClutterSeat *seat = CLUTTER_SEAT (data);
- XkbEvent *xkbev = (XkbEvent *) xevent;
-
- /* 'event_type' is set to zero on notifying us of updates in
- * response to client requests (including our own) and non-zero
- * to notify us of key/mouse events causing changes (like
- * pressing shift 5 times to enable sticky keys).
- *
- * We only want to update out settings when it's in response to an
- * explicit user input event, so require a non-zero event_type.
- */
- if (xevent->xany.type == (_xkb_event_base + XkbEventCode) &&
- xkbev->any.xkb_type == XkbControlsNotify && xkbev->ctrls.event_type != 0)
- check_settings_changed (seat);
-
- return META_X11_FILTER_CONTINUE;
-}
-
-static gboolean
-is_xkb_available (Display *xdisplay)
-{
- int opcode, error_base, event_base, major, minor;
-
- if (_xkb_event_base)
- return TRUE;
-
- if (!XkbQueryExtension (xdisplay,
- &opcode,
- &event_base,
- &error_base,
- &major,
- &minor))
- return FALSE;
-
- if (!XkbUseExtension (xdisplay, &major, &minor))
- return FALSE;
-
- _xkb_event_base = event_base;
-
- return TRUE;
-}
-
-static unsigned long
-set_value_mask (gboolean flag,
- unsigned long value,
- unsigned long mask)
-{
- if (flag)
- return value | mask;
-
- return value & ~mask;
-}
-
-static gboolean
-set_xkb_ctrl (XkbDescRec *desc,
- MetaKeyboardA11yFlags settings,
- MetaKeyboardA11yFlags flag,
- unsigned long mask)
-{
- gboolean result = (settings & flag) == flag;
- desc->ctrls->enabled_ctrls = set_value_mask (result, desc->ctrls->enabled_ctrls, mask);
-
- return result;
-}
-
-void
-meta_seat_x11_apply_kbd_a11y_settings (ClutterSeat *seat,
- MetaKbdA11ySettings *kbd_a11y_settings)
-{
- Display *xdisplay = meta_clutter_x11_get_default_display ();
- XkbDescRec *desc;
- gboolean enable_accessX;
-
- desc = get_xkb_desc_rec (xdisplay);
- if (!desc)
- return;
-
- /* general */
- enable_accessX = kbd_a11y_settings->controls & META_A11Y_KEYBOARD_ENABLED;
-
- desc->ctrls->enabled_ctrls = set_value_mask (enable_accessX,
- desc->ctrls->enabled_ctrls,
- XkbAccessXKeysMask);
-
- if (set_xkb_ctrl (desc, kbd_a11y_settings->controls, META_A11Y_TIMEOUT_ENABLED,
- XkbAccessXTimeoutMask))
- {
- desc->ctrls->ax_timeout = kbd_a11y_settings->timeout_delay;
- /* disable only the master flag via the server we will disable
- * the rest on the rebound without affecting settings state
- * don't change the option flags at all.
- */
- desc->ctrls->axt_ctrls_mask = XkbAccessXKeysMask | XkbAccessXFeedbackMask;
- desc->ctrls->axt_ctrls_values = 0;
- desc->ctrls->axt_opts_mask = 0;
- }
-
- desc->ctrls->ax_options =
- set_value_mask (kbd_a11y_settings->controls & META_A11Y_FEATURE_STATE_CHANGE_BEEP,
- desc->ctrls->ax_options,
- XkbAccessXFeedbackMask | XkbAX_FeatureFBMask | XkbAX_SlowWarnFBMask);
-
- /* bounce keys */
- if (set_xkb_ctrl (desc, kbd_a11y_settings->controls,
- META_A11Y_BOUNCE_KEYS_ENABLED, XkbBounceKeysMask))
- {
- desc->ctrls->debounce_delay = kbd_a11y_settings->debounce_delay;
- desc->ctrls->ax_options =
- set_value_mask (kbd_a11y_settings->controls & META_A11Y_BOUNCE_KEYS_BEEP_REJECT,
- desc->ctrls->ax_options,
- XkbAccessXFeedbackMask | XkbAX_BKRejectFBMask);
- }
-
- /* mouse keys */
- if (clutter_keymap_get_num_lock_state (clutter_seat_get_keymap (seat)))
- {
- /* Disable mousekeys when NumLock is ON */
- desc->ctrls->enabled_ctrls &= ~(XkbMouseKeysMask | XkbMouseKeysAccelMask);
- }
- else if (set_xkb_ctrl (desc, kbd_a11y_settings->controls,
- META_A11Y_MOUSE_KEYS_ENABLED, XkbMouseKeysMask | XkbMouseKeysAccelMask))
- {
- int mk_max_speed;
- int mk_accel_time;
-
- desc->ctrls->mk_interval = 100; /* msec between mousekey events */
- desc->ctrls->mk_curve = 50;
-
- /* We store pixels / sec, XKB wants pixels / event */
- mk_max_speed = kbd_a11y_settings->mousekeys_max_speed;
- desc->ctrls->mk_max_speed = mk_max_speed / (1000 / desc->ctrls->mk_interval);
- if (desc->ctrls->mk_max_speed <= 0)
- desc->ctrls->mk_max_speed = 1;
-
- mk_accel_time = kbd_a11y_settings->mousekeys_accel_time;
- desc->ctrls->mk_time_to_max = mk_accel_time / desc->ctrls->mk_interval;
-
- if (desc->ctrls->mk_time_to_max <= 0)
- desc->ctrls->mk_time_to_max = 1;
-
- desc->ctrls->mk_delay = kbd_a11y_settings->mousekeys_init_delay;
- }
-
- /* slow keys */
- if (set_xkb_ctrl (desc, kbd_a11y_settings->controls,
- META_A11Y_SLOW_KEYS_ENABLED, XkbSlowKeysMask))
- {
- desc->ctrls->ax_options =
- set_value_mask (kbd_a11y_settings->controls & META_A11Y_SLOW_KEYS_BEEP_PRESS,
- desc->ctrls->ax_options, XkbAccessXFeedbackMask | XkbAX_SKPressFBMask);
- desc->ctrls->ax_options =
- set_value_mask (kbd_a11y_settings->controls & META_A11Y_SLOW_KEYS_BEEP_ACCEPT,
- desc->ctrls->ax_options, XkbAccessXFeedbackMask | XkbAX_SKAcceptFBMask);
- desc->ctrls->ax_options =
- set_value_mask (kbd_a11y_settings->controls & META_A11Y_SLOW_KEYS_BEEP_REJECT,
- desc->ctrls->ax_options, XkbAccessXFeedbackMask | XkbAX_SKRejectFBMask);
- desc->ctrls->slow_keys_delay = kbd_a11y_settings->slowkeys_delay;
- /* anything larger than 500 seems to loose all keyboard input */
- if (desc->ctrls->slow_keys_delay > 500)
- desc->ctrls->slow_keys_delay = 500;
- }
-
- /* sticky keys */
- if (set_xkb_ctrl (desc, kbd_a11y_settings->controls,
- META_A11Y_STICKY_KEYS_ENABLED, XkbStickyKeysMask))
- {
- desc->ctrls->ax_options |= XkbAX_LatchToLockMask;
- desc->ctrls->ax_options =
- set_value_mask (kbd_a11y_settings->controls & META_A11Y_STICKY_KEYS_TWO_KEY_OFF,
- desc->ctrls->ax_options, XkbAccessXFeedbackMask | XkbAX_TwoKeysMask);
- desc->ctrls->ax_options =
- set_value_mask (kbd_a11y_settings->controls & META_A11Y_STICKY_KEYS_BEEP,
- desc->ctrls->ax_options, XkbAccessXFeedbackMask | XkbAX_StickyKeysFBMask);
- }
-
- /* toggle keys */
- desc->ctrls->ax_options =
- set_value_mask (kbd_a11y_settings->controls & META_A11Y_TOGGLE_KEYS_ENABLED,
- desc->ctrls->ax_options, XkbAccessXFeedbackMask | XkbAX_IndicatorFBMask);
-
- set_xkb_desc_rec (xdisplay, desc);
- XkbFreeKeyboard (desc, XkbAllComponentsMask, TRUE);
-}
-
-gboolean
-meta_seat_x11_a11y_init (ClutterSeat *seat)
-{
- Display *xdisplay = meta_clutter_x11_get_default_display ();
- guint event_mask;
-
- if (!is_xkb_available (xdisplay))
- return FALSE;
-
- event_mask = XkbControlsNotifyMask | XkbAccessXNotifyMask;
-
- XkbSelectEvents (xdisplay, XkbUseCoreKbd, event_mask, event_mask);
-
- meta_clutter_x11_add_filter (xkb_a11y_event_filter, seat);
-
- return TRUE;
-}
diff --git a/src/backends/x11/meta-xkb-a11y-x11.h b/src/backends/x11/meta-xkb-a11y-x11.h
deleted file mode 100644
index 58a4e1766..000000000
--- a/src/backends/x11/meta-xkb-a11y-x11.h
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- *
- * Copyright © 2001 Ximian, Inc.
- * Copyright (C) 2007 William Jon McCann <mccann@jhu.edu>
- * Copyright (C) 2017 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- */
-
-#ifndef META_XKB_A11Y_X11_H
-#define META_XKB_A11Y_X11_H
-
-#include <X11/Xlib.h>
-
-#include "backends/meta-input-settings-private.h"
-#include "clutter/clutter.h"
-
-void
-meta_seat_x11_apply_kbd_a11y_settings (ClutterSeat *seat,
- MetaKbdA11ySettings *kbd_a11y_settings);
-
-gboolean
-meta_seat_x11_a11y_init (ClutterSeat *seat);
-
-#endif /* META_XKB_A11Y_X11_H */
diff --git a/src/backends/x11/nested/meta-backend-x11-nested.c b/src/backends/x11/nested/meta-backend-x11-nested.c
deleted file mode 100644
index 041b42860..000000000
--- a/src/backends/x11/nested/meta-backend-x11-nested.c
+++ /dev/null
@@ -1,320 +0,0 @@
-/*
- * Copyright (C) 2017 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-
-#include "config.h"
-
-#include "backends/x11/nested/meta-backend-x11-nested.h"
-
-#include "backends/meta-input-settings-dummy.h"
-#include "backends/meta-monitor-manager-dummy.h"
-#include "backends/x11/nested/meta-backend-x11-nested.h"
-#include "backends/x11/nested/meta-cursor-renderer-x11-nested.h"
-#include "backends/x11/nested/meta-renderer-x11-nested.h"
-
-#include "wayland/meta-wayland.h"
-
-typedef struct _MetaBackendX11NestedPrivate
-{
- MetaGpu *gpu;
- MetaCursorRenderer *cursor_renderer;
- MetaInputSettings *input_settings;
-} MetaBackendX11NestedPrivate;
-
-static GInitableIface *initable_parent_iface;
-
-static void
-initable_iface_init (GInitableIface *initable_iface);
-
-G_DEFINE_TYPE_WITH_CODE (MetaBackendX11Nested, meta_backend_x11_nested,
- META_TYPE_BACKEND_X11,
- G_ADD_PRIVATE (MetaBackendX11Nested)
- G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE,
- initable_iface_init));
-
-static MetaRenderer *
-meta_backend_x11_nested_create_renderer (MetaBackend *backend,
- GError **error)
-{
- return g_object_new (META_TYPE_RENDERER_X11_NESTED,
- "backend", backend,
- NULL);
-}
-
-static MetaMonitorManager *
-meta_backend_x11_nested_create_monitor_manager (MetaBackend *backend,
- GError **error)
-{
- return g_object_new (META_TYPE_MONITOR_MANAGER_DUMMY,
- "backend", backend,
- NULL);
-}
-
-static MetaCursorRenderer *
-meta_backend_x11_nested_get_cursor_renderer (MetaBackend *backend,
- ClutterInputDevice *device)
-{
- MetaBackendX11Nested *backend_x11_nested = META_BACKEND_X11_NESTED (backend);
- MetaBackendX11NestedPrivate *priv =
- meta_backend_x11_nested_get_instance_private (backend_x11_nested);
-
- if (!priv->cursor_renderer)
- {
- priv->cursor_renderer =
- g_object_new (META_TYPE_CURSOR_RENDERER_X11_NESTED,
- "backend", backend,
- "device", device,
- NULL);
- }
-
- return priv->cursor_renderer;
-}
-
-static MetaInputSettings *
-meta_backend_x11_nested_get_input_settings (MetaBackend *backend)
-{
- MetaBackendX11Nested *backend_x11_nested = META_BACKEND_X11_NESTED (backend);
- MetaBackendX11NestedPrivate *priv =
- meta_backend_x11_nested_get_instance_private (backend_x11_nested);
-
- if (!priv->input_settings)
- {
- priv->input_settings =
- g_object_new (META_TYPE_INPUT_SETTINGS_DUMMY, NULL);
- }
-
- return priv->input_settings;
-}
-
-static void
-meta_backend_x11_nested_update_screen_size (MetaBackend *backend,
- int width,
- int height)
-{
- ClutterActor *stage = meta_backend_get_stage (backend);
- MetaRenderer *renderer = meta_backend_get_renderer (backend);
-
- if (meta_is_stage_views_enabled ())
- {
- meta_renderer_rebuild_views (renderer);
- clutter_stage_clear_stage_views (CLUTTER_STAGE (stage));
- }
- clutter_actor_set_size (stage, width, height);
-}
-
-static void
-meta_backend_x11_nested_select_stage_events (MetaBackend *backend)
-{
- MetaBackendX11 *x11 = META_BACKEND_X11 (backend);
- Display *xdisplay = meta_backend_x11_get_xdisplay (x11);
- Window xwin = meta_backend_x11_get_xwindow (x11);
- unsigned char mask_bits[XIMaskLen (XI_LASTEVENT)] = { 0 };
- XIEventMask mask = { XIAllMasterDevices, sizeof (mask_bits), mask_bits };
-
- XISetMask (mask.mask, XI_KeyPress);
- XISetMask (mask.mask, XI_KeyRelease);
- XISetMask (mask.mask, XI_ButtonPress);
- XISetMask (mask.mask, XI_ButtonRelease);
- XISetMask (mask.mask, XI_Enter);
- XISetMask (mask.mask, XI_Leave);
- XISetMask (mask.mask, XI_FocusIn);
- XISetMask (mask.mask, XI_FocusOut);
- XISetMask (mask.mask, XI_Motion);
-
- /*
- * When we're an X11 compositor, we can't take these events or else replaying
- * events from our passive root window grab will cause them to come back to
- * us.
- *
- * When we're a nested application, we want to behave like any other
- * application, so select these events like normal apps do.
- */
- XISetMask (mask.mask, XI_TouchBegin); XISetMask (mask.mask, XI_TouchEnd);
- XISetMask (mask.mask, XI_TouchUpdate);
-
- XISelectEvents (xdisplay, xwin, &mask, 1);
-
- /*
- * We have no way of tracking key changes when the stage doesn't have focus,
- * so we select for KeymapStateMask so that we get a complete dump of the
- * keyboard state in a KeymapNotify event that immediately follows each
- * FocusIn (and EnterNotify, but we ignore that.)
- */
- XWindowAttributes xwa;
-
- XGetWindowAttributes(xdisplay, xwin, &xwa);
- XSelectInput(xdisplay, xwin,
- xwa.your_event_mask | FocusChangeMask | KeymapStateMask);
-}
-
-static void
-meta_backend_x11_nested_lock_layout_group (MetaBackend *backend,
- guint idx)
-{
-}
-
-static void
-meta_backend_x11_nested_set_keymap (MetaBackend *backend,
- const char *layouts,
- const char *variants,
- const char *options)
-{
-}
-
-static gboolean
-meta_backend_x11_nested_is_lid_closed (MetaBackend *backend)
-{
- return FALSE;
-}
-
-static gboolean
-meta_backend_x11_nested_handle_host_xevent (MetaBackendX11 *x11,
- XEvent *event)
-{
-#ifdef HAVE_WAYLAND
- if (event->type == FocusIn)
- {
- Window xwin = meta_backend_x11_get_xwindow (x11);
- XEvent xev;
-
- if (event->xfocus.window == xwin)
- {
- MetaWaylandCompositor *compositor =
- meta_wayland_compositor_get_default ();
- Display *xdisplay = meta_backend_x11_get_xdisplay (x11);
-
- /*
- * Since we've selected for KeymapStateMask, every FocusIn is
- * followed immediately by a KeymapNotify event.
- */
- XMaskEvent (xdisplay, KeymapStateMask, &xev);
- meta_wayland_compositor_update_key_state (compositor,
- xev.xkeymap.key_vector,
- 32, 8);
- }
- }
-#endif
-
- return FALSE;
-}
-
-static void
-meta_backend_x11_nested_translate_device_event (MetaBackendX11 *x11,
- XIDeviceEvent *device_event)
-{
- /* This codepath should only ever trigger as an X11 compositor,
- * and never under nested, as under nested all backend events
- * should be reported with respect to the stage window.
- */
- g_assert (device_event->event == meta_backend_x11_get_xwindow (x11));
-}
-
-static void
-meta_backend_x11_nested_real_init_gpus (MetaBackendX11Nested *backend_x11_nested)
-{
- MetaBackendX11NestedPrivate *priv =
- meta_backend_x11_nested_get_instance_private (backend_x11_nested);
-
- priv->gpu = g_object_new (META_TYPE_GPU_DUMMY,
- "backend", backend_x11_nested,
- NULL);
- meta_backend_add_gpu (META_BACKEND (backend_x11_nested), priv->gpu);
-}
-
-static void
-meta_backend_x11_nested_post_init (MetaBackend *backend)
-{
- MetaBackendClass *backend_class =
- META_BACKEND_CLASS (meta_backend_x11_nested_parent_class);
-
- backend_class->post_init (backend);
-}
-
-static gboolean
-meta_backend_x11_nested_initable_init (GInitable *initable,
- GCancellable *cancellable,
- GError **error)
-{
- return initable_parent_iface->init (initable, cancellable, error);
-}
-
-static void
-initable_iface_init (GInitableIface *initable_iface)
-{
- initable_parent_iface = g_type_interface_peek_parent (initable_iface);
-
- initable_iface->init = meta_backend_x11_nested_initable_init;
-}
-
-static void
-meta_backend_x11_nested_constructed (GObject *object)
-{
- MetaBackendX11Nested *backend_x11_nested = META_BACKEND_X11_NESTED (object);
- MetaBackendX11NestedClass *backend_x11_nested_class =
- META_BACKEND_X11_NESTED_GET_CLASS (backend_x11_nested);
- GObjectClass *parent_class =
- G_OBJECT_CLASS (meta_backend_x11_nested_parent_class);
-
- parent_class->constructed (object);
-
- backend_x11_nested_class->init_gpus (backend_x11_nested);
-}
-
-static void
-meta_backend_x11_nested_dispose (GObject *object)
-{
- MetaBackendX11Nested *backend_x11_nested = META_BACKEND_X11_NESTED (object);
- MetaBackendX11NestedPrivate *priv =
- meta_backend_x11_nested_get_instance_private (backend_x11_nested);
-
- g_clear_object (&priv->input_settings);
-
- G_OBJECT_CLASS (meta_backend_x11_nested_parent_class)->dispose (object);
-}
-
-static void
-meta_backend_x11_nested_init (MetaBackendX11Nested *backend_x11_nested)
-{
-}
-
-static void
-meta_backend_x11_nested_class_init (MetaBackendX11NestedClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
- MetaBackendClass *backend_class = META_BACKEND_CLASS (klass);
- MetaBackendX11Class *backend_x11_class = META_BACKEND_X11_CLASS (klass);
-
- object_class->constructed = meta_backend_x11_nested_constructed;
- object_class->dispose = meta_backend_x11_nested_dispose;
-
- backend_class->post_init = meta_backend_x11_nested_post_init;
- backend_class->create_renderer = meta_backend_x11_nested_create_renderer;
- backend_class->create_monitor_manager = meta_backend_x11_nested_create_monitor_manager;
- backend_class->get_cursor_renderer = meta_backend_x11_nested_get_cursor_renderer;
- backend_class->get_input_settings = meta_backend_x11_nested_get_input_settings;
- backend_class->update_screen_size = meta_backend_x11_nested_update_screen_size;
- backend_class->select_stage_events = meta_backend_x11_nested_select_stage_events;
- backend_class->lock_layout_group = meta_backend_x11_nested_lock_layout_group;
- backend_class->set_keymap = meta_backend_x11_nested_set_keymap;
- backend_class->is_lid_closed = meta_backend_x11_nested_is_lid_closed;
-
- backend_x11_class->handle_host_xevent = meta_backend_x11_nested_handle_host_xevent;
- backend_x11_class->translate_device_event = meta_backend_x11_nested_translate_device_event;
-
- klass->init_gpus = meta_backend_x11_nested_real_init_gpus;
-}
diff --git a/src/backends/x11/nested/meta-backend-x11-nested.h b/src/backends/x11/nested/meta-backend-x11-nested.h
deleted file mode 100644
index 4f19ff54a..000000000
--- a/src/backends/x11/nested/meta-backend-x11-nested.h
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright (C) 2017 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- */
-
-#ifndef META_BACKEND_X11_NESTED_H
-#define META_BACKEND_X11_NESTED_H
-
-#include <glib-object.h>
-
-#include "backends/x11/meta-backend-x11.h"
-#include "core/util-private.h"
-
-#define META_TYPE_BACKEND_X11_NESTED (meta_backend_x11_nested_get_type ())
-META_EXPORT_TEST
-G_DECLARE_DERIVABLE_TYPE (MetaBackendX11Nested, meta_backend_x11_nested,
- META, BACKEND_X11_NESTED, MetaBackendX11)
-
-struct _MetaBackendX11NestedClass
-{
- MetaBackendX11Class parent_class;
-
- void (* init_gpus) (MetaBackendX11Nested *backend_x11_nested);
-};
-
-#endif /* META_BACKEND_X11_NESTED_H */
diff --git a/src/backends/x11/nested/meta-cursor-renderer-x11-nested.c b/src/backends/x11/nested/meta-cursor-renderer-x11-nested.c
deleted file mode 100644
index 0daae683c..000000000
--- a/src/backends/x11/nested/meta-cursor-renderer-x11-nested.c
+++ /dev/null
@@ -1,91 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2015 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Written by:
- * Jonas Ådahl <jadahl@gmail.com>
- */
-
-#include "config.h"
-
-#include "backends/x11/nested/meta-cursor-renderer-x11-nested.h"
-
-#include <X11/Xcursor/Xcursor.h>
-
-#include "backends/x11/meta-backend-x11.h"
-
-struct _MetaCursorRendererX11Nested
-{
- MetaCursorRenderer parent;
-};
-
-G_DEFINE_TYPE (MetaCursorRendererX11Nested, meta_cursor_renderer_x11_nested,
- META_TYPE_CURSOR_RENDERER);
-
-static gboolean
-meta_cursor_renderer_x11_nested_update_cursor (MetaCursorRenderer *renderer,
- MetaCursorSprite *cursor_sprite)
-{
- if (cursor_sprite)
- meta_cursor_sprite_realize_texture (cursor_sprite);
- return FALSE;
-}
-
-static Cursor
-create_empty_cursor (Display *xdisplay)
-{
- XcursorImage *image;
- XcursorPixel *pixels;
- Cursor xcursor;
-
- image = XcursorImageCreate (1, 1);
- if (image == NULL)
- return None;
-
- image->xhot = 0;
- image->yhot = 0;
-
- pixels = image->pixels;
- pixels[0] = 0;
-
- xcursor = XcursorImageLoadCursor (xdisplay, image);
- XcursorImageDestroy (image);
-
- return xcursor;
-}
-
-static void
-meta_cursor_renderer_x11_nested_init (MetaCursorRendererX11Nested *x11_nested)
-{
- MetaBackendX11 *backend = META_BACKEND_X11 (meta_get_backend ());
- Window xwindow = meta_backend_x11_get_xwindow (backend);
- Display *xdisplay = meta_backend_x11_get_xdisplay (backend);
-
- Cursor empty_xcursor = create_empty_cursor (xdisplay);
- XDefineCursor (xdisplay, xwindow, empty_xcursor);
- XFreeCursor (xdisplay, empty_xcursor);
-}
-
-static void
-meta_cursor_renderer_x11_nested_class_init (MetaCursorRendererX11NestedClass *klass)
-{
- MetaCursorRendererClass *renderer_class = META_CURSOR_RENDERER_CLASS (klass);
-
- renderer_class->update_cursor = meta_cursor_renderer_x11_nested_update_cursor;
-}
diff --git a/src/backends/x11/nested/meta-cursor-renderer-x11-nested.h b/src/backends/x11/nested/meta-cursor-renderer-x11-nested.h
deleted file mode 100644
index 32f816629..000000000
--- a/src/backends/x11/nested/meta-cursor-renderer-x11-nested.h
+++ /dev/null
@@ -1,38 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2015 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Written by:
- * Jonas Ådahl <jadahl@gmail.com>
- */
-
-#ifndef META_CURSOR_RENDERER_X11_NESTED_NESTED_H
-#define META_CURSOR_RENDERER_X11_NESTED_NESTED_H
-
-#include <glib-object.h>
-
-#include "backends/meta-cursor-renderer.h"
-
-#define META_TYPE_CURSOR_RENDERER_X11_NESTED (meta_cursor_renderer_x11_nested_get_type ())
-G_DECLARE_FINAL_TYPE (MetaCursorRendererX11Nested,
- meta_cursor_renderer_x11_nested,
- META, CURSOR_RENDERER_X11_NESTED,
- MetaCursorRenderer);
-
-#endif /* META_CURSOR_RENDERER_X11_NESTED_NESTED_H */
diff --git a/src/backends/x11/nested/meta-renderer-x11-nested.c b/src/backends/x11/nested/meta-renderer-x11-nested.c
deleted file mode 100644
index 7c1a4facf..000000000
--- a/src/backends/x11/nested/meta-renderer-x11-nested.c
+++ /dev/null
@@ -1,248 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2016 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- */
-
-#include "config.h"
-
-#include "backends/x11/nested/meta-renderer-x11-nested.h"
-
-#include <glib-object.h>
-
-#include "backends/meta-backend-private.h"
-#include "backends/meta-logical-monitor.h"
-#include "backends/meta-output.h"
-#include "backends/meta-renderer.h"
-#include "backends/meta-renderer-view.h"
-#include "backends/x11/meta-clutter-backend-x11.h"
-#include "core/boxes-private.h"
-#include "meta/meta-backend.h"
-#include "meta/util.h"
-
-struct _MetaRendererX11Nested
-{
- MetaRendererX11 parent;
-};
-
-G_DEFINE_TYPE (MetaRendererX11Nested, meta_renderer_x11_nested,
- META_TYPE_RENDERER_X11)
-
-static MetaMonitorTransform
-calculate_view_transform (MetaMonitorManager *monitor_manager,
- MetaLogicalMonitor *logical_monitor)
-{
- MetaMonitor *main_monitor;
- MetaOutput *main_output;
- MetaCrtc *crtc;
- MetaMonitorTransform crtc_transform;
-
- main_monitor = meta_logical_monitor_get_monitors (logical_monitor)->data;
- main_output = meta_monitor_get_main_output (main_monitor);
- crtc = meta_output_get_assigned_crtc (main_output);
- crtc_transform =
- meta_monitor_logical_to_crtc_transform (main_monitor,
- logical_monitor->transform);
- /*
- * Pick any monitor and output and check; all CRTCs of a logical monitor will
- * always have the same transform assigned to them.
- */
-
- if (meta_monitor_manager_is_transform_handled (monitor_manager,
- crtc,
- crtc_transform))
- return META_MONITOR_TRANSFORM_NORMAL;
- else
- return crtc_transform;
-}
-
-static MetaRendererView *
-get_legacy_view (MetaRenderer *renderer)
-{
- GList *views;
-
- views = meta_renderer_get_views (renderer);
- if (views)
- return META_RENDERER_VIEW (views->data);
- else
- return NULL;
-}
-
-static CoglOffscreen *
-create_offscreen (CoglContext *cogl_context,
- int width,
- int height)
-{
- CoglTexture2D *texture_2d;
- CoglOffscreen *offscreen;
- GError *error = NULL;
-
- texture_2d = cogl_texture_2d_new_with_size (cogl_context, width, height);
- offscreen = cogl_offscreen_new_with_texture (COGL_TEXTURE (texture_2d));
-
- if (!cogl_framebuffer_allocate (COGL_FRAMEBUFFER (offscreen), &error))
- meta_fatal ("Couldn't allocate framebuffer: %s", error->message);
-
- return offscreen;
-}
-
-static void
-meta_renderer_x11_nested_resize_legacy_view (MetaRendererX11Nested *renderer_x11_nested,
- int width,
- int height)
-{
- MetaRenderer *renderer = META_RENDERER (renderer_x11_nested);
- MetaBackend *backend = meta_get_backend ();
- ClutterBackend *clutter_backend = meta_backend_get_clutter_backend (backend);
- CoglContext *cogl_context = clutter_backend_get_cogl_context (clutter_backend);
- MetaRendererView *legacy_view;
- cairo_rectangle_int_t view_layout;
- CoglOffscreen *fake_onscreen;
-
- legacy_view = get_legacy_view (renderer);
-
- clutter_stage_view_get_layout (CLUTTER_STAGE_VIEW (legacy_view),
- &view_layout);
- if (view_layout.width == width &&
- view_layout.height == height)
- return;
-
- view_layout = (cairo_rectangle_int_t) {
- .width = width,
- .height = height
- };
-
- fake_onscreen = create_offscreen (cogl_context, width, height);
-
- g_object_set (G_OBJECT (legacy_view),
- "layout", &view_layout,
- "framebuffer", COGL_FRAMEBUFFER (fake_onscreen),
- NULL);
-}
-
-void
-meta_renderer_x11_nested_ensure_legacy_view (MetaRendererX11Nested *renderer_x11_nested,
- int width,
- int height)
-{
- MetaRenderer *renderer = META_RENDERER (renderer_x11_nested);
- MetaBackend *backend = meta_get_backend ();
- ClutterBackend *clutter_backend = meta_backend_get_clutter_backend (backend);
- CoglContext *cogl_context = clutter_backend_get_cogl_context (clutter_backend);
- cairo_rectangle_int_t view_layout;
- CoglOffscreen *fake_onscreen;
- MetaRendererView *legacy_view;
-
- if (get_legacy_view (renderer))
- {
- meta_renderer_x11_nested_resize_legacy_view (renderer_x11_nested,
- width, height);
- return;
- }
-
- fake_onscreen = create_offscreen (cogl_context, width, height);
-
- view_layout = (cairo_rectangle_int_t) {
- .width = width,
- .height = height
- };
- legacy_view = g_object_new (META_TYPE_RENDERER_VIEW,
- "name", "legacy nested",
- "stage", meta_backend_get_stage (backend),
- "layout", &view_layout,
- "framebuffer", COGL_FRAMEBUFFER (fake_onscreen),
- NULL);
-
- g_assert (!meta_renderer_get_views (renderer));
- meta_renderer_add_view (renderer, legacy_view);
-}
-
-static MetaRendererView *
-meta_renderer_x11_nested_create_view (MetaRenderer *renderer,
- MetaLogicalMonitor *logical_monitor,
- MetaOutput *output,
- MetaCrtc *crtc)
-{
- MetaBackend *backend = meta_get_backend ();
- MetaMonitorManager *monitor_manager =
- meta_backend_get_monitor_manager (backend);
- ClutterBackend *clutter_backend = meta_backend_get_clutter_backend (backend);
- CoglContext *cogl_context = clutter_backend_get_cogl_context (clutter_backend);
- MetaMonitorTransform view_transform;
- float view_scale;
- const MetaCrtcConfig *crtc_config;
- int width, height;
- CoglOffscreen *fake_onscreen;
- CoglOffscreen *offscreen;
- MetaRectangle view_layout;
- const MetaCrtcModeInfo *mode_info;
- MetaRendererView *view;
-
- view_transform = calculate_view_transform (monitor_manager, logical_monitor);
-
- if (meta_is_stage_views_scaled ())
- view_scale = logical_monitor->scale;
- else
- view_scale = 1.0;
-
- crtc_config = meta_crtc_get_config (crtc);
- width = roundf (crtc_config->layout.size.width * view_scale);
- height = roundf (crtc_config->layout.size.height * view_scale);
-
- fake_onscreen = create_offscreen (cogl_context, width, height);
-
- if (view_transform != META_MONITOR_TRANSFORM_NORMAL)
- offscreen = create_offscreen (cogl_context, width, height);
- else
- offscreen = NULL;
-
- meta_rectangle_from_graphene_rect (&crtc_config->layout,
- META_ROUNDING_STRATEGY_ROUND,
- &view_layout);
-
- mode_info = meta_crtc_mode_get_info (crtc_config->mode);
-
- view = g_object_new (META_TYPE_RENDERER_VIEW,
- "name", meta_output_get_name (output),
- "stage", meta_backend_get_stage (backend),
- "layout", &view_layout,
- "crtc", crtc,
- "refresh-rate", mode_info->refresh_rate,
- "framebuffer", COGL_FRAMEBUFFER (fake_onscreen),
- "offscreen", COGL_FRAMEBUFFER (offscreen),
- "transform", view_transform,
- "scale", view_scale,
- NULL);
- g_object_set_data (G_OBJECT (view), "crtc", crtc);
-
- return view;
-}
-
-static void
-meta_renderer_x11_nested_init (MetaRendererX11Nested *renderer_x11_nested)
-{
-}
-
-static void
-meta_renderer_x11_nested_class_init (MetaRendererX11NestedClass *klass)
-{
- MetaRendererClass *renderer_class = META_RENDERER_CLASS (klass);
-
- renderer_class->create_view = meta_renderer_x11_nested_create_view;
-}
diff --git a/src/backends/x11/nested/meta-renderer-x11-nested.h b/src/backends/x11/nested/meta-renderer-x11-nested.h
deleted file mode 100644
index 9fc88e85b..000000000
--- a/src/backends/x11/nested/meta-renderer-x11-nested.h
+++ /dev/null
@@ -1,37 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2016 Red Hat
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- */
-
-#ifndef META_RENDERER_X11_NESTED_H
-#define META_RENDERER_X11_NESTED_H
-
-#include "backends/x11/meta-renderer-x11.h"
-
-#define META_TYPE_RENDERER_X11_NESTED (meta_renderer_x11_nested_get_type ())
-G_DECLARE_FINAL_TYPE (MetaRendererX11Nested, meta_renderer_x11_nested,
- META, RENDERER_X11_NESTED,
- MetaRendererX11)
-
-void meta_renderer_x11_nested_ensure_legacy_view (MetaRendererX11Nested *renderer_x11_nested,
- int width,
- int height);
-
-#endif /* META_RENDERER_X11_NESTED_H */
diff --git a/src/backends/x11/nested/meta-stage-x11-nested.c b/src/backends/x11/nested/meta-stage-x11-nested.c
deleted file mode 100644
index dbf3b7bbf..000000000
--- a/src/backends/x11/nested/meta-stage-x11-nested.c
+++ /dev/null
@@ -1,236 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2016 Red Hat Inc.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Written by:
- * Jonas Ådahl <jadahl@gmail.com>
- */
-
-#include "config.h"
-
-#include "backends/x11/nested/meta-stage-x11-nested.h"
-
-#include "backends/meta-backend-private.h"
-#include "backends/meta-crtc.h"
-#include "backends/meta-logical-monitor.h"
-#include "backends/meta-monitor.h"
-#include "backends/meta-output.h"
-#include "backends/meta-renderer.h"
-#include "backends/x11/nested/meta-renderer-x11-nested.h"
-#include "clutter/clutter-mutter.h"
-
-static ClutterStageWindowInterface *clutter_stage_window_parent_iface = NULL;
-
-struct _MetaStageX11Nested
-{
- MetaStageX11 parent;
-
- CoglPipeline *pipeline;
-};
-
-static void
-clutter_stage_window_iface_init (ClutterStageWindowInterface *iface);
-
-G_DEFINE_TYPE_WITH_CODE (MetaStageX11Nested, meta_stage_x11_nested,
- META_TYPE_STAGE_X11,
- G_IMPLEMENT_INTERFACE (CLUTTER_TYPE_STAGE_WINDOW,
- clutter_stage_window_iface_init))
-
-typedef struct _MetaStageX11View
-{
- CoglTexture *texture;
- MetaStageView *view;
-} MetaStageX11NestedView;
-
-static void
-meta_stage_x11_nested_resize (ClutterStageWindow *stage_window,
- gint width,
- gint height)
-{
- if (!meta_is_stage_views_enabled ())
- {
- MetaBackend *backend = meta_get_backend ();
- MetaRenderer *renderer = meta_backend_get_renderer (backend);
- MetaRendererX11Nested *renderer_x11_nested =
- META_RENDERER_X11_NESTED (renderer);
-
- meta_renderer_x11_nested_ensure_legacy_view (renderer_x11_nested,
- width, height);
- }
-
- clutter_stage_window_parent_iface->resize (stage_window, width, height);
-}
-
-static gboolean
-meta_stage_x11_nested_can_clip_redraws (ClutterStageWindow *stage_window)
-{
- return FALSE;
-}
-
-static GList *
-meta_stage_x11_nested_get_views (ClutterStageWindow *stage_window)
-{
- MetaBackend *backend = meta_get_backend ();
- MetaRenderer *renderer = meta_backend_get_renderer (backend);
-
- return meta_renderer_get_views (renderer);
-}
-
-typedef struct
-{
- MetaStageX11Nested *stage_nested;
- CoglTexture *texture;
- ClutterStageView *view;
- MetaLogicalMonitor *logical_monitor;
-} DrawCrtcData;
-
-static gboolean
-draw_view (MetaStageX11Nested *stage_nested,
- MetaRendererView *renderer_view,
- CoglTexture *texture)
-{
- MetaStageX11 *stage_x11 = META_STAGE_X11 (stage_nested);
- CoglFramebuffer *onscreen = COGL_FRAMEBUFFER (stage_x11->onscreen);
- ClutterStageView *stage_view = CLUTTER_STAGE_VIEW (renderer_view);
- MetaCrtc *crtc;
- const MetaCrtcConfig *crtc_config;
- graphene_matrix_t projection_matrix;
- graphene_matrix_t transform;
- float texture_width, texture_height;
- float sample_x, sample_y, sample_width, sample_height;
- float s_1, t_1, s_2, t_2;
-
- texture_width = cogl_texture_get_width (texture);
- texture_height = cogl_texture_get_height (texture);
-
- crtc = g_object_get_data (G_OBJECT (renderer_view), "crtc");
- crtc_config = meta_crtc_get_config (crtc);
-
- sample_x = 0;
- sample_y = 0;
- sample_width = texture_width;
- sample_height = texture_height;
-
- clutter_stage_view_get_offscreen_transformation_matrix (stage_view,
- &transform);
-
- cogl_framebuffer_push_matrix (onscreen);
- graphene_matrix_init_scale (&projection_matrix, 2, -2, 0);
- graphene_matrix_translate (&projection_matrix,
- &GRAPHENE_POINT3D_INIT (-1, 1, 0));
- graphene_matrix_multiply (&transform, &projection_matrix, &projection_matrix);
- cogl_framebuffer_set_projection_matrix (onscreen, &projection_matrix);
-
- s_1 = sample_x / texture_width;
- t_1 = sample_y / texture_height;
- s_2 = (sample_x + sample_width) / texture_width;
- t_2 = (sample_y + sample_height) / texture_height;
-
- cogl_framebuffer_set_viewport (onscreen,
- crtc_config->layout.origin.x,
- crtc_config->layout.origin.y,
- crtc_config->layout.size.width,
- crtc_config->layout.size.height);
-
- cogl_framebuffer_draw_textured_rectangle (onscreen,
- stage_nested->pipeline,
- 0, 0, 1, 1,
- s_1, t_1, s_2, t_2);
-
- cogl_framebuffer_pop_matrix (onscreen);
- return TRUE;
-}
-
-static void
-meta_stage_x11_nested_finish_frame (ClutterStageWindow *stage_window,
- ClutterStageView *stage_view,
- ClutterFrame *frame)
-{
- MetaStageX11Nested *stage_nested = META_STAGE_X11_NESTED (stage_window);
- MetaStageX11 *stage_x11 = META_STAGE_X11 (stage_window);
- MetaBackend *backend = meta_get_backend ();
- MetaRenderer *renderer = meta_backend_get_renderer (backend);
- ClutterBackend *clutter_backend = meta_backend_get_clutter_backend (backend);
- CoglFramebuffer *onscreen = COGL_FRAMEBUFFER (stage_x11->onscreen);
- CoglContext *context = cogl_framebuffer_get_context (onscreen);
- GList *l;
- CoglFrameInfo *frame_info;
-
- if (!stage_nested->pipeline)
- stage_nested->pipeline = cogl_pipeline_new (clutter_backend->cogl_context);
-
- cogl_framebuffer_clear4f (onscreen,
- COGL_BUFFER_BIT_COLOR,
- 0.0f, 0.0f, 0.0f, 1.0f);
-
- for (l = meta_renderer_get_views (renderer); l; l = l->next)
- {
- ClutterStageView *view = l->data;
- MetaRendererView *renderer_view = META_RENDERER_VIEW (view);
- CoglFramebuffer *framebuffer;
- CoglTexture *texture;
-
- framebuffer = clutter_stage_view_get_onscreen (view);
- texture = cogl_offscreen_get_texture (COGL_OFFSCREEN (framebuffer));
-
- cogl_pipeline_set_layer_texture (stage_nested->pipeline, 0, texture);
- cogl_pipeline_set_layer_wrap_mode (stage_nested->pipeline, 0,
- COGL_PIPELINE_WRAP_MODE_CLAMP_TO_EDGE);
-
- draw_view (stage_nested, renderer_view, texture);
- }
-
- frame_info = cogl_frame_info_new (context, 0);
- cogl_onscreen_swap_buffers (stage_x11->onscreen, frame_info, frame);
-
- if (!clutter_frame_has_result (frame))
- clutter_frame_set_result (frame, CLUTTER_FRAME_RESULT_IDLE);
-}
-
-static void
-meta_stage_x11_nested_unrealize (ClutterStageWindow *stage_window)
-{
- MetaStageX11Nested *stage_nested = META_STAGE_X11_NESTED (stage_window);
-
- g_clear_pointer (&stage_nested->pipeline, cogl_object_unref);
-
- clutter_stage_window_parent_iface->unrealize (stage_window);
-}
-
-static void
-meta_stage_x11_nested_init (MetaStageX11Nested *stage_x11_nested)
-{
-}
-
-static void
-meta_stage_x11_nested_class_init (MetaStageX11NestedClass *klass)
-{
-}
-
-static void
-clutter_stage_window_iface_init (ClutterStageWindowInterface *iface)
-{
- clutter_stage_window_parent_iface = g_type_interface_peek_parent (iface);
-
- iface->resize = meta_stage_x11_nested_resize;
- iface->can_clip_redraws = meta_stage_x11_nested_can_clip_redraws;
- iface->unrealize = meta_stage_x11_nested_unrealize;
- iface->get_views = meta_stage_x11_nested_get_views;
- iface->finish_frame = meta_stage_x11_nested_finish_frame;
-}
diff --git a/src/backends/x11/nested/meta-stage-x11-nested.h b/src/backends/x11/nested/meta-stage-x11-nested.h
deleted file mode 100644
index 76678465b..000000000
--- a/src/backends/x11/nested/meta-stage-x11-nested.h
+++ /dev/null
@@ -1,35 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/*
- * Copyright (C) 2016 Red Hat Inc.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Written by:
- * Jonas Ådahl <jadahl@gmail.com>
- */
-
-#ifndef META_STAGE_X11_NESTED_H
-#define META_STAGE_X11_NESTED_H
-
-#include "clutter/clutter-mutter.h"
-#include "backends/x11/meta-stage-x11.h"
-
-#define META_TYPE_STAGE_X11_NESTED (meta_stage_x11_nested_get_type ())
-G_DECLARE_FINAL_TYPE (MetaStageX11Nested, meta_stage_x11_nested,
- META, STAGE_X11_NESTED, MetaStageX11)
-
-#endif /* META_STAGE_X11_NESTED_H */