Marc-André Lureau | 142ca62 | 2021-07-15 11:53:53 +0400 | [diff] [blame] | 1 | /* |
| 2 | * QEMU DBus display |
| 3 | * |
| 4 | * Copyright (c) 2021 Marc-André Lureau <marcandre.lureau@redhat.com> |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | * of this software and associated documentation files (the "Software"), to deal |
| 8 | * in the Software without restriction, including without limitation the rights |
| 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 10 | * copies of the Software, and to permit persons to whom the Software is |
| 11 | * furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included in |
| 14 | * all copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 22 | * THE SOFTWARE. |
| 23 | */ |
Markus Armbruster | 9c09280 | 2022-05-06 15:49:09 +0200 | [diff] [blame] | 24 | |
| 25 | #ifndef UI_DBUS_H |
| 26 | #define UI_DBUS_H |
Marc-André Lureau | 142ca62 | 2021-07-15 11:53:53 +0400 | [diff] [blame] | 27 | |
Marc-André Lureau | 3e301c8 | 2021-07-22 19:43:29 +0400 | [diff] [blame] | 28 | #include "chardev/char-socket.h" |
Marc-André Lureau | 142ca62 | 2021-07-15 11:53:53 +0400 | [diff] [blame] | 29 | #include "qemu/dbus.h" |
| 30 | #include "qom/object.h" |
| 31 | #include "ui/console.h" |
Marc-André Lureau | ff1a581 | 2021-07-20 16:02:52 +0400 | [diff] [blame] | 32 | #include "ui/clipboard.h" |
Marc-André Lureau | 142ca62 | 2021-07-15 11:53:53 +0400 | [diff] [blame] | 33 | |
Paolo Bonzini | 0e902f5 | 2022-07-27 12:19:03 +0200 | [diff] [blame] | 34 | #include "ui/dbus-display1.h" |
Marc-André Lureau | 142ca62 | 2021-07-15 11:53:53 +0400 | [diff] [blame] | 35 | |
Marc-André Lureau | ff1a581 | 2021-07-20 16:02:52 +0400 | [diff] [blame] | 36 | typedef struct DBusClipboardRequest { |
| 37 | GDBusMethodInvocation *invocation; |
| 38 | QemuClipboardType type; |
| 39 | guint timeout_id; |
| 40 | } DBusClipboardRequest; |
| 41 | |
Marc-André Lureau | 142ca62 | 2021-07-15 11:53:53 +0400 | [diff] [blame] | 42 | struct DBusDisplay { |
| 43 | Object parent; |
| 44 | |
| 45 | DisplayGLMode gl_mode; |
Marc-André Lureau | 9999782 | 2021-10-10 00:16:57 +0400 | [diff] [blame] | 46 | bool p2p; |
Marc-André Lureau | 142ca62 | 2021-07-15 11:53:53 +0400 | [diff] [blame] | 47 | char *dbus_addr; |
Marc-André Lureau | 739362d | 2021-03-09 17:15:28 +0400 | [diff] [blame] | 48 | char *audiodev; |
Marc-André Lureau | 142ca62 | 2021-07-15 11:53:53 +0400 | [diff] [blame] | 49 | DisplayGLCtx glctx; |
| 50 | |
| 51 | GDBusConnection *bus; |
| 52 | GDBusObjectManagerServer *server; |
| 53 | QemuDBusDisplay1VM *iface; |
| 54 | GPtrArray *consoles; |
Marc-André Lureau | 9999782 | 2021-10-10 00:16:57 +0400 | [diff] [blame] | 55 | GCancellable *add_client_cancellable; |
Marc-André Lureau | ff1a581 | 2021-07-20 16:02:52 +0400 | [diff] [blame] | 56 | |
| 57 | QemuClipboardPeer clipboard_peer; |
| 58 | QemuDBusDisplay1Clipboard *clipboard; |
| 59 | QemuDBusDisplay1Clipboard *clipboard_proxy; |
| 60 | DBusClipboardRequest clipboard_request[QEMU_CLIPBOARD_SELECTION__COUNT]; |
Marc-André Lureau | 3e301c8 | 2021-07-22 19:43:29 +0400 | [diff] [blame] | 61 | |
| 62 | Notifier notifier; |
Marc-André Lureau | 142ca62 | 2021-07-15 11:53:53 +0400 | [diff] [blame] | 63 | }; |
| 64 | |
Marc-André Lureau | 6cc5a61 | 2023-06-06 15:56:42 +0400 | [diff] [blame] | 65 | #ifdef WIN32 |
| 66 | bool |
| 67 | dbus_win32_import_socket(GDBusMethodInvocation *invocation, |
| 68 | GVariant *arg_listener, int *socket); |
| 69 | #endif |
| 70 | |
Marc-André Lureau | 142ca62 | 2021-07-15 11:53:53 +0400 | [diff] [blame] | 71 | #define TYPE_DBUS_DISPLAY "dbus-display" |
| 72 | OBJECT_DECLARE_SIMPLE_TYPE(DBusDisplay, DBUS_DISPLAY) |
| 73 | |
Marc-André Lureau | 3e301c8 | 2021-07-22 19:43:29 +0400 | [diff] [blame] | 74 | void dbus_display_notifier_add(Notifier *notifier); |
| 75 | |
Marc-André Lureau | 142ca62 | 2021-07-15 11:53:53 +0400 | [diff] [blame] | 76 | #define DBUS_DISPLAY_TYPE_CONSOLE dbus_display_console_get_type() |
| 77 | G_DECLARE_FINAL_TYPE(DBusDisplayConsole, |
| 78 | dbus_display_console, |
| 79 | DBUS_DISPLAY, |
| 80 | CONSOLE, |
| 81 | GDBusObjectSkeleton) |
| 82 | |
| 83 | DBusDisplayConsole * |
| 84 | dbus_display_console_new(DBusDisplay *display, QemuConsole *con); |
| 85 | |
| 86 | int |
| 87 | dbus_display_console_get_index(DBusDisplayConsole *ddc); |
| 88 | |
Marc-André Lureau | 417a231 | 2022-02-16 22:52:14 +0400 | [diff] [blame] | 89 | |
| 90 | extern const DisplayChangeListenerOps dbus_console_dcl_ops; |
| 91 | |
Marc-André Lureau | 142ca62 | 2021-07-15 11:53:53 +0400 | [diff] [blame] | 92 | #define DBUS_DISPLAY_TYPE_LISTENER dbus_display_listener_get_type() |
| 93 | G_DECLARE_FINAL_TYPE(DBusDisplayListener, |
| 94 | dbus_display_listener, |
| 95 | DBUS_DISPLAY, |
| 96 | LISTENER, |
| 97 | GObject) |
| 98 | |
| 99 | DBusDisplayListener * |
| 100 | dbus_display_listener_new(const char *bus_name, |
| 101 | GDBusConnection *conn, |
| 102 | DBusDisplayConsole *console); |
| 103 | |
| 104 | DBusDisplayConsole * |
| 105 | dbus_display_listener_get_console(DBusDisplayListener *ddl); |
| 106 | |
| 107 | const char * |
| 108 | dbus_display_listener_get_bus_name(DBusDisplayListener *ddl); |
| 109 | |
| 110 | extern const DisplayChangeListenerOps dbus_gl_dcl_ops; |
| 111 | extern const DisplayChangeListenerOps dbus_dcl_ops; |
| 112 | |
Marc-André Lureau | 3e301c8 | 2021-07-22 19:43:29 +0400 | [diff] [blame] | 113 | #define TYPE_CHARDEV_DBUS "chardev-dbus" |
| 114 | |
| 115 | typedef struct DBusChardevClass { |
| 116 | SocketChardevClass parent_class; |
| 117 | |
| 118 | void (*parent_chr_be_event)(Chardev *s, QEMUChrEvent event); |
| 119 | } DBusChardevClass; |
| 120 | |
| 121 | DECLARE_CLASS_CHECKERS(DBusChardevClass, DBUS_CHARDEV, |
| 122 | TYPE_CHARDEV_DBUS) |
| 123 | |
| 124 | typedef struct DBusChardev { |
| 125 | SocketChardev parent; |
| 126 | |
| 127 | bool exported; |
| 128 | QemuDBusDisplay1Chardev *iface; |
| 129 | } DBusChardev; |
| 130 | |
| 131 | DECLARE_INSTANCE_CHECKER(DBusChardev, DBUS_CHARDEV, TYPE_CHARDEV_DBUS) |
| 132 | |
| 133 | #define CHARDEV_IS_DBUS(chr) \ |
| 134 | object_dynamic_cast(OBJECT(chr), TYPE_CHARDEV_DBUS) |
| 135 | |
| 136 | typedef enum { |
| 137 | DBUS_DISPLAY_CHARDEV_OPEN, |
| 138 | DBUS_DISPLAY_CHARDEV_CLOSE, |
| 139 | } DBusDisplayEventType; |
| 140 | |
| 141 | typedef struct DBusDisplayEvent { |
| 142 | DBusDisplayEventType type; |
| 143 | union { |
| 144 | DBusChardev *chardev; |
| 145 | }; |
| 146 | } DBusDisplayEvent; |
| 147 | |
| 148 | void dbus_display_notify(DBusDisplayEvent *event); |
| 149 | |
| 150 | void dbus_chardev_init(DBusDisplay *dpy); |
| 151 | |
Marc-André Lureau | ff1a581 | 2021-07-20 16:02:52 +0400 | [diff] [blame] | 152 | void dbus_clipboard_init(DBusDisplay *dpy); |
| 153 | |
Markus Armbruster | 9c09280 | 2022-05-06 15:49:09 +0200 | [diff] [blame] | 154 | #endif /* UI_DBUS_H */ |