bellard | 5b0753e | 2005-03-01 21:37:28 +0000 | [diff] [blame] | 1 | /* |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 2 | * QEMU Cocoa CG display driver |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 3 | * |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 4 | * Copyright (c) 2008 Mike Kronenberg |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 5 | * |
bellard | 5b0753e | 2005-03-01 21:37:28 +0000 | [diff] [blame] | 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 | */ |
bellard | da4dbf7 | 2005-03-02 22:22:43 +0000 | [diff] [blame] | 24 | |
Peter Maydell | e4a096b | 2016-01-29 16:23:34 +0000 | [diff] [blame] | 25 | #include "qemu/osdep.h" |
| 26 | |
bellard | 5b0753e | 2005-03-01 21:37:28 +0000 | [diff] [blame] | 27 | #import <Cocoa/Cocoa.h> |
Andreas Färber | 3bbbee1 | 2011-05-29 19:42:51 +0200 | [diff] [blame] | 28 | #include <crt_externs.h> |
bellard | 5b0753e | 2005-03-01 21:37:28 +0000 | [diff] [blame] | 29 | |
Marc-André Lureau | 49f9522 | 2022-04-20 17:25:49 +0400 | [diff] [blame] | 30 | #include "qemu/help-texts.h" |
Marc-André Lureau | 88c39c8 | 2022-04-20 17:25:47 +0400 | [diff] [blame] | 31 | #include "qemu-main.h" |
Akihiko Odaki | 7e3e20d | 2021-06-16 23:19:54 +0900 | [diff] [blame] | 32 | #include "ui/clipboard.h" |
Paolo Bonzini | 28ecbae | 2012-11-28 12:06:30 +0100 | [diff] [blame] | 33 | #include "ui/console.h" |
Gerd Hoffmann | 21bae11 | 2013-12-04 14:08:04 +0100 | [diff] [blame] | 34 | #include "ui/input.h" |
Akihiko Odaki | 6d73bb6 | 2021-03-10 23:46:02 +0900 | [diff] [blame] | 35 | #include "ui/kbd-state.h" |
Paolo Bonzini | 9c17d61 | 2012-12-17 18:20:04 +0100 | [diff] [blame] | 36 | #include "sysemu/sysemu.h" |
Markus Armbruster | 54d3123 | 2019-08-12 07:23:59 +0200 | [diff] [blame] | 37 | #include "sysemu/runstate.h" |
Akihiko Odaki | 2910abd | 2022-05-29 17:25:08 +0900 | [diff] [blame] | 38 | #include "sysemu/runstate-action.h" |
Claudio Fontana | b0c3cf9 | 2020-06-29 11:35:03 +0200 | [diff] [blame] | 39 | #include "sysemu/cpu-throttle.h" |
Markus Armbruster | e688df6 | 2018-02-01 12:18:31 +0100 | [diff] [blame] | 40 | #include "qapi/error.h" |
Markus Armbruster | 16bf523 | 2018-12-20 09:45:59 +0100 | [diff] [blame] | 41 | #include "qapi/qapi-commands-block.h" |
Philippe Mathieu-Daudé | 90f8c0f | 2020-10-12 14:15:33 +0200 | [diff] [blame] | 42 | #include "qapi/qapi-commands-machine.h" |
Markus Armbruster | 16bf523 | 2018-12-20 09:45:59 +0100 | [diff] [blame] | 43 | #include "qapi/qapi-commands-misc.h" |
John Arbuckle | 693a3e0 | 2015-06-19 10:53:27 +0100 | [diff] [blame] | 44 | #include "sysemu/blockdev.h" |
Programmingkid | 9e8204b | 2016-08-15 22:11:06 -0400 | [diff] [blame] | 45 | #include "qemu-version.h" |
Akihiko Odaki | e31746e | 2021-03-09 21:22:25 +0900 | [diff] [blame] | 46 | #include "qemu/cutils.h" |
Markus Armbruster | db72581 | 2019-08-12 07:23:50 +0200 | [diff] [blame] | 47 | #include "qemu/main-loop.h" |
Markus Armbruster | 0b8fa32 | 2019-05-23 16:35:07 +0200 | [diff] [blame] | 48 | #include "qemu/module.h" |
John Arbuckle | aaac714 | 2016-03-23 14:26:18 +0000 | [diff] [blame] | 49 | #include <Carbon/Carbon.h> |
Markus Armbruster | 2e5b09f | 2019-07-09 17:20:52 +0200 | [diff] [blame] | 50 | #include "hw/core/cpu.h" |
bellard | da4dbf7 | 2005-03-02 22:22:43 +0000 | [diff] [blame] | 51 | |
Brendan Shanks | 5e24600 | 2019-01-31 23:12:25 -0800 | [diff] [blame] | 52 | #ifndef MAC_OS_X_VERSION_10_13 |
| 53 | #define MAC_OS_X_VERSION_10_13 101300 |
| 54 | #endif |
Andreas Färber | 44e4c0b | 2009-12-13 00:45:40 +0100 | [diff] [blame] | 55 | |
Brendan Shanks | 5e24600 | 2019-01-31 23:12:25 -0800 | [diff] [blame] | 56 | /* 10.14 deprecates NSOnState and NSOffState in favor of |
| 57 | * NSControlStateValueOn/Off, which were introduced in 10.13. |
| 58 | * Define for older versions |
| 59 | */ |
| 60 | #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_13 |
| 61 | #define NSControlStateValueOn NSOnState |
| 62 | #define NSControlStateValueOff NSOffState |
| 63 | #endif |
bellard | 5b0753e | 2005-03-01 21:37:28 +0000 | [diff] [blame] | 64 | |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 65 | //#define DEBUG |
| 66 | |
| 67 | #ifdef DEBUG |
| 68 | #define COCOA_DEBUG(...) { (void) fprintf (stdout, __VA_ARGS__); } |
| 69 | #else |
| 70 | #define COCOA_DEBUG(...) ((void) 0) |
| 71 | #endif |
| 72 | |
| 73 | #define cgrect(nsrect) (*(CGRect *)&(nsrect)) |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 74 | |
| 75 | typedef struct { |
| 76 | int width; |
| 77 | int height; |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 78 | } QEMUScreen; |
| 79 | |
Akihiko Odaki | cc7859c | 2021-02-19 17:44:19 +0900 | [diff] [blame] | 80 | static void cocoa_update(DisplayChangeListener *dcl, |
| 81 | int x, int y, int w, int h); |
| 82 | |
| 83 | static void cocoa_switch(DisplayChangeListener *dcl, |
| 84 | DisplaySurface *surface); |
| 85 | |
| 86 | static void cocoa_refresh(DisplayChangeListener *dcl); |
| 87 | |
Akihiko Odaki | 99eb313 | 2022-02-27 13:22:41 +0900 | [diff] [blame] | 88 | static NSWindow *normalWindow; |
Akihiko Odaki | cc7859c | 2021-02-19 17:44:19 +0900 | [diff] [blame] | 89 | static const DisplayChangeListenerOps dcl_ops = { |
| 90 | .dpy_name = "cocoa", |
| 91 | .dpy_gfx_update = cocoa_update, |
| 92 | .dpy_gfx_switch = cocoa_switch, |
| 93 | .dpy_refresh = cocoa_refresh, |
| 94 | }; |
| 95 | static DisplayChangeListener dcl = { |
| 96 | .ops = &dcl_ops, |
| 97 | }; |
Gerd Hoffmann | 21bae11 | 2013-12-04 14:08:04 +0100 | [diff] [blame] | 98 | static int last_buttons; |
Gerd Hoffmann | 3487da6 | 2020-02-06 12:27:50 +0100 | [diff] [blame] | 99 | static int cursor_hide = 1; |
Carwyn Ellis | 48941a5 | 2022-01-02 17:41:52 +0000 | [diff] [blame] | 100 | static int left_command_key_enabled = 1; |
Gustavo Noronha Silva | 4797adc | 2022-03-06 21:11:19 +0900 | [diff] [blame] | 101 | static bool swap_opt_cmd; |
bellard | 5b0753e | 2005-03-01 21:37:28 +0000 | [diff] [blame] | 102 | |
Akihiko Odaki | cb82340 | 2021-02-25 17:42:02 +0900 | [diff] [blame] | 103 | static int gArgc; |
| 104 | static char **gArgv; |
| 105 | static bool stretch_video; |
| 106 | static NSTextField *pauseLabel; |
bellard | 5b0753e | 2005-03-01 21:37:28 +0000 | [diff] [blame] | 107 | |
Peter Maydell | 5588840 | 2019-02-25 10:24:33 +0000 | [diff] [blame] | 108 | static QemuSemaphore display_init_sem; |
| 109 | static QemuSemaphore app_started_sem; |
Hikaru Nishida | dff742a | 2019-10-15 10:07:34 +0900 | [diff] [blame] | 110 | static bool allow_events; |
Peter Maydell | 5588840 | 2019-02-25 10:24:33 +0000 | [diff] [blame] | 111 | |
Akihiko Odaki | 7e3e20d | 2021-06-16 23:19:54 +0900 | [diff] [blame] | 112 | static NSInteger cbchangecount = -1; |
| 113 | static QemuClipboardInfo *cbinfo; |
| 114 | static QemuEvent cbevent; |
| 115 | |
Peter Maydell | 60105d7 | 2019-02-25 10:24:31 +0000 | [diff] [blame] | 116 | // Utility functions to run specified code block with iothread lock held |
Peter Maydell | 31819e9 | 2019-02-25 10:24:27 +0000 | [diff] [blame] | 117 | typedef void (^CodeBlock)(void); |
Peter Maydell | 60105d7 | 2019-02-25 10:24:31 +0000 | [diff] [blame] | 118 | typedef bool (^BoolCodeBlock)(void); |
Peter Maydell | 31819e9 | 2019-02-25 10:24:27 +0000 | [diff] [blame] | 119 | |
| 120 | static void with_iothread_lock(CodeBlock block) |
| 121 | { |
| 122 | bool locked = qemu_mutex_iothread_locked(); |
| 123 | if (!locked) { |
| 124 | qemu_mutex_lock_iothread(); |
| 125 | } |
| 126 | block(); |
| 127 | if (!locked) { |
| 128 | qemu_mutex_unlock_iothread(); |
| 129 | } |
| 130 | } |
| 131 | |
Peter Maydell | 60105d7 | 2019-02-25 10:24:31 +0000 | [diff] [blame] | 132 | static bool bool_with_iothread_lock(BoolCodeBlock block) |
| 133 | { |
| 134 | bool locked = qemu_mutex_iothread_locked(); |
| 135 | bool val; |
| 136 | |
| 137 | if (!locked) { |
| 138 | qemu_mutex_lock_iothread(); |
| 139 | } |
| 140 | val = block(); |
| 141 | if (!locked) { |
| 142 | qemu_mutex_unlock_iothread(); |
| 143 | } |
| 144 | return val; |
| 145 | } |
| 146 | |
John Arbuckle | aaac714 | 2016-03-23 14:26:18 +0000 | [diff] [blame] | 147 | // Mac to QKeyCode conversion |
Akihiko Odaki | cb82340 | 2021-02-25 17:42:02 +0900 | [diff] [blame] | 148 | static const int mac_to_qkeycode_map[] = { |
John Arbuckle | aaac714 | 2016-03-23 14:26:18 +0000 | [diff] [blame] | 149 | [kVK_ANSI_A] = Q_KEY_CODE_A, |
| 150 | [kVK_ANSI_B] = Q_KEY_CODE_B, |
| 151 | [kVK_ANSI_C] = Q_KEY_CODE_C, |
| 152 | [kVK_ANSI_D] = Q_KEY_CODE_D, |
| 153 | [kVK_ANSI_E] = Q_KEY_CODE_E, |
| 154 | [kVK_ANSI_F] = Q_KEY_CODE_F, |
| 155 | [kVK_ANSI_G] = Q_KEY_CODE_G, |
| 156 | [kVK_ANSI_H] = Q_KEY_CODE_H, |
| 157 | [kVK_ANSI_I] = Q_KEY_CODE_I, |
| 158 | [kVK_ANSI_J] = Q_KEY_CODE_J, |
| 159 | [kVK_ANSI_K] = Q_KEY_CODE_K, |
| 160 | [kVK_ANSI_L] = Q_KEY_CODE_L, |
| 161 | [kVK_ANSI_M] = Q_KEY_CODE_M, |
| 162 | [kVK_ANSI_N] = Q_KEY_CODE_N, |
| 163 | [kVK_ANSI_O] = Q_KEY_CODE_O, |
| 164 | [kVK_ANSI_P] = Q_KEY_CODE_P, |
| 165 | [kVK_ANSI_Q] = Q_KEY_CODE_Q, |
| 166 | [kVK_ANSI_R] = Q_KEY_CODE_R, |
| 167 | [kVK_ANSI_S] = Q_KEY_CODE_S, |
| 168 | [kVK_ANSI_T] = Q_KEY_CODE_T, |
| 169 | [kVK_ANSI_U] = Q_KEY_CODE_U, |
| 170 | [kVK_ANSI_V] = Q_KEY_CODE_V, |
| 171 | [kVK_ANSI_W] = Q_KEY_CODE_W, |
| 172 | [kVK_ANSI_X] = Q_KEY_CODE_X, |
| 173 | [kVK_ANSI_Y] = Q_KEY_CODE_Y, |
| 174 | [kVK_ANSI_Z] = Q_KEY_CODE_Z, |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 175 | |
John Arbuckle | aaac714 | 2016-03-23 14:26:18 +0000 | [diff] [blame] | 176 | [kVK_ANSI_0] = Q_KEY_CODE_0, |
| 177 | [kVK_ANSI_1] = Q_KEY_CODE_1, |
| 178 | [kVK_ANSI_2] = Q_KEY_CODE_2, |
| 179 | [kVK_ANSI_3] = Q_KEY_CODE_3, |
| 180 | [kVK_ANSI_4] = Q_KEY_CODE_4, |
| 181 | [kVK_ANSI_5] = Q_KEY_CODE_5, |
| 182 | [kVK_ANSI_6] = Q_KEY_CODE_6, |
| 183 | [kVK_ANSI_7] = Q_KEY_CODE_7, |
| 184 | [kVK_ANSI_8] = Q_KEY_CODE_8, |
| 185 | [kVK_ANSI_9] = Q_KEY_CODE_9, |
| 186 | |
| 187 | [kVK_ANSI_Grave] = Q_KEY_CODE_GRAVE_ACCENT, |
| 188 | [kVK_ANSI_Minus] = Q_KEY_CODE_MINUS, |
| 189 | [kVK_ANSI_Equal] = Q_KEY_CODE_EQUAL, |
| 190 | [kVK_Delete] = Q_KEY_CODE_BACKSPACE, |
| 191 | [kVK_CapsLock] = Q_KEY_CODE_CAPS_LOCK, |
| 192 | [kVK_Tab] = Q_KEY_CODE_TAB, |
| 193 | [kVK_Return] = Q_KEY_CODE_RET, |
| 194 | [kVK_ANSI_LeftBracket] = Q_KEY_CODE_BRACKET_LEFT, |
| 195 | [kVK_ANSI_RightBracket] = Q_KEY_CODE_BRACKET_RIGHT, |
| 196 | [kVK_ANSI_Backslash] = Q_KEY_CODE_BACKSLASH, |
| 197 | [kVK_ANSI_Semicolon] = Q_KEY_CODE_SEMICOLON, |
| 198 | [kVK_ANSI_Quote] = Q_KEY_CODE_APOSTROPHE, |
| 199 | [kVK_ANSI_Comma] = Q_KEY_CODE_COMMA, |
| 200 | [kVK_ANSI_Period] = Q_KEY_CODE_DOT, |
| 201 | [kVK_ANSI_Slash] = Q_KEY_CODE_SLASH, |
John Arbuckle | aaac714 | 2016-03-23 14:26:18 +0000 | [diff] [blame] | 202 | [kVK_Space] = Q_KEY_CODE_SPC, |
| 203 | |
| 204 | [kVK_ANSI_Keypad0] = Q_KEY_CODE_KP_0, |
| 205 | [kVK_ANSI_Keypad1] = Q_KEY_CODE_KP_1, |
| 206 | [kVK_ANSI_Keypad2] = Q_KEY_CODE_KP_2, |
| 207 | [kVK_ANSI_Keypad3] = Q_KEY_CODE_KP_3, |
| 208 | [kVK_ANSI_Keypad4] = Q_KEY_CODE_KP_4, |
| 209 | [kVK_ANSI_Keypad5] = Q_KEY_CODE_KP_5, |
| 210 | [kVK_ANSI_Keypad6] = Q_KEY_CODE_KP_6, |
| 211 | [kVK_ANSI_Keypad7] = Q_KEY_CODE_KP_7, |
| 212 | [kVK_ANSI_Keypad8] = Q_KEY_CODE_KP_8, |
| 213 | [kVK_ANSI_Keypad9] = Q_KEY_CODE_KP_9, |
| 214 | [kVK_ANSI_KeypadDecimal] = Q_KEY_CODE_KP_DECIMAL, |
| 215 | [kVK_ANSI_KeypadEnter] = Q_KEY_CODE_KP_ENTER, |
| 216 | [kVK_ANSI_KeypadPlus] = Q_KEY_CODE_KP_ADD, |
| 217 | [kVK_ANSI_KeypadMinus] = Q_KEY_CODE_KP_SUBTRACT, |
| 218 | [kVK_ANSI_KeypadMultiply] = Q_KEY_CODE_KP_MULTIPLY, |
| 219 | [kVK_ANSI_KeypadDivide] = Q_KEY_CODE_KP_DIVIDE, |
| 220 | [kVK_ANSI_KeypadEquals] = Q_KEY_CODE_KP_EQUALS, |
| 221 | [kVK_ANSI_KeypadClear] = Q_KEY_CODE_NUM_LOCK, |
| 222 | |
| 223 | [kVK_UpArrow] = Q_KEY_CODE_UP, |
| 224 | [kVK_DownArrow] = Q_KEY_CODE_DOWN, |
| 225 | [kVK_LeftArrow] = Q_KEY_CODE_LEFT, |
| 226 | [kVK_RightArrow] = Q_KEY_CODE_RIGHT, |
| 227 | |
| 228 | [kVK_Help] = Q_KEY_CODE_INSERT, |
| 229 | [kVK_Home] = Q_KEY_CODE_HOME, |
| 230 | [kVK_PageUp] = Q_KEY_CODE_PGUP, |
| 231 | [kVK_PageDown] = Q_KEY_CODE_PGDN, |
| 232 | [kVK_End] = Q_KEY_CODE_END, |
| 233 | [kVK_ForwardDelete] = Q_KEY_CODE_DELETE, |
| 234 | |
| 235 | [kVK_Escape] = Q_KEY_CODE_ESC, |
| 236 | |
| 237 | /* The Power key can't be used directly because the operating system uses |
| 238 | * it. This key can be emulated by using it in place of another key such as |
| 239 | * F1. Don't forget to disable the real key binding. |
| 240 | */ |
| 241 | /* [kVK_F1] = Q_KEY_CODE_POWER, */ |
| 242 | |
| 243 | [kVK_F1] = Q_KEY_CODE_F1, |
| 244 | [kVK_F2] = Q_KEY_CODE_F2, |
| 245 | [kVK_F3] = Q_KEY_CODE_F3, |
| 246 | [kVK_F4] = Q_KEY_CODE_F4, |
| 247 | [kVK_F5] = Q_KEY_CODE_F5, |
| 248 | [kVK_F6] = Q_KEY_CODE_F6, |
| 249 | [kVK_F7] = Q_KEY_CODE_F7, |
| 250 | [kVK_F8] = Q_KEY_CODE_F8, |
| 251 | [kVK_F9] = Q_KEY_CODE_F9, |
| 252 | [kVK_F10] = Q_KEY_CODE_F10, |
| 253 | [kVK_F11] = Q_KEY_CODE_F11, |
| 254 | [kVK_F12] = Q_KEY_CODE_F12, |
| 255 | [kVK_F13] = Q_KEY_CODE_PRINT, |
| 256 | [kVK_F14] = Q_KEY_CODE_SCROLL_LOCK, |
| 257 | [kVK_F15] = Q_KEY_CODE_PAUSE, |
| 258 | |
Akihiko Odaki | 708b725 | 2021-02-12 09:04:04 +0900 | [diff] [blame] | 259 | // JIS keyboards only |
| 260 | [kVK_JIS_Yen] = Q_KEY_CODE_YEN, |
| 261 | [kVK_JIS_Underscore] = Q_KEY_CODE_RO, |
| 262 | [kVK_JIS_KeypadComma] = Q_KEY_CODE_KP_COMMA, |
| 263 | [kVK_JIS_Eisu] = Q_KEY_CODE_MUHENKAN, |
| 264 | [kVK_JIS_Kana] = Q_KEY_CODE_HENKAN, |
| 265 | |
John Arbuckle | aaac714 | 2016-03-23 14:26:18 +0000 | [diff] [blame] | 266 | /* |
| 267 | * The eject and volume keys can't be used here because they are handled at |
| 268 | * a lower level than what an Application can see. |
| 269 | */ |
bellard | 5b0753e | 2005-03-01 21:37:28 +0000 | [diff] [blame] | 270 | }; |
| 271 | |
Andreas Färber | 77047bb | 2009-12-13 00:55:53 +0100 | [diff] [blame] | 272 | static int cocoa_keycode_to_qemu(int keycode) |
bellard | 5b0753e | 2005-03-01 21:37:28 +0000 | [diff] [blame] | 273 | { |
John Arbuckle | aaac714 | 2016-03-23 14:26:18 +0000 | [diff] [blame] | 274 | if (ARRAY_SIZE(mac_to_qkeycode_map) <= keycode) { |
Akihiko Odaki | 4313739 | 2021-02-23 22:11:06 +0900 | [diff] [blame] | 275 | error_report("(cocoa) warning unknown keycode 0x%x", keycode); |
bellard | 5b0753e | 2005-03-01 21:37:28 +0000 | [diff] [blame] | 276 | return 0; |
| 277 | } |
John Arbuckle | aaac714 | 2016-03-23 14:26:18 +0000 | [diff] [blame] | 278 | return mac_to_qkeycode_map[keycode]; |
bellard | 5b0753e | 2005-03-01 21:37:28 +0000 | [diff] [blame] | 279 | } |
| 280 | |
John Arbuckle | 693a3e0 | 2015-06-19 10:53:27 +0100 | [diff] [blame] | 281 | /* Displays an alert dialog box with the specified message */ |
| 282 | static void QEMU_Alert(NSString *message) |
| 283 | { |
| 284 | NSAlert *alert; |
| 285 | alert = [NSAlert new]; |
| 286 | [alert setMessageText: message]; |
| 287 | [alert runModal]; |
| 288 | } |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 289 | |
John Arbuckle | 693a3e0 | 2015-06-19 10:53:27 +0100 | [diff] [blame] | 290 | /* Handles any errors that happen with a device transaction */ |
| 291 | static void handleAnyDeviceErrors(Error * err) |
| 292 | { |
| 293 | if (err) { |
| 294 | QEMU_Alert([NSString stringWithCString: error_get_pretty(err) |
| 295 | encoding: NSASCIIStringEncoding]); |
| 296 | error_free(err); |
| 297 | } |
| 298 | } |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 299 | |
bellard | 5b0753e | 2005-03-01 21:37:28 +0000 | [diff] [blame] | 300 | /* |
| 301 | ------------------------------------------------------ |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 302 | QemuCocoaView |
bellard | 5b0753e | 2005-03-01 21:37:28 +0000 | [diff] [blame] | 303 | ------------------------------------------------------ |
| 304 | */ |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 305 | @interface QemuCocoaView : NSView |
bellard | 5b0753e | 2005-03-01 21:37:28 +0000 | [diff] [blame] | 306 | { |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 307 | QEMUScreen screen; |
| 308 | NSWindow *fullScreenWindow; |
| 309 | float cx,cy,cw,ch,cdx,cdy; |
Peter Maydell | 5588840 | 2019-02-25 10:24:33 +0000 | [diff] [blame] | 310 | pixman_image_t *pixman_image; |
Akihiko Odaki | 6d73bb6 | 2021-03-10 23:46:02 +0900 | [diff] [blame] | 311 | QKbdState *kbd; |
Peter Maydell | 49b9bd4 | 2013-12-08 22:59:03 +0000 | [diff] [blame] | 312 | BOOL isMouseGrabbed; |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 313 | BOOL isFullscreen; |
| 314 | BOOL isAbsoluteEnabled; |
Gustavo Noronha Silva | f844cdb | 2022-03-06 21:11:18 +0900 | [diff] [blame] | 315 | CFMachPortRef eventsTap; |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 316 | } |
Peter Maydell | 72a3e31 | 2019-02-25 10:24:28 +0000 | [diff] [blame] | 317 | - (void) switchSurface:(pixman_image_t *)image; |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 318 | - (void) grabMouse; |
| 319 | - (void) ungrabMouse; |
| 320 | - (void) toggleFullScreen:(id)sender; |
Gustavo Noronha Silva | f844cdb | 2022-03-06 21:11:18 +0900 | [diff] [blame] | 321 | - (void) setFullGrab:(id)sender; |
John Arbuckle | 9c3a418 | 2017-11-07 10:14:14 +0000 | [diff] [blame] | 322 | - (void) handleMonitorInput:(NSEvent *)event; |
Peter Maydell | 60105d7 | 2019-02-25 10:24:31 +0000 | [diff] [blame] | 323 | - (bool) handleEvent:(NSEvent *)event; |
| 324 | - (bool) handleEventLocked:(NSEvent *)event; |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 325 | - (void) setAbsoluteEnabled:(BOOL)tIsAbsoluteEnabled; |
Peter Maydell | f61c387 | 2014-06-23 10:35:24 +0100 | [diff] [blame] | 326 | /* The state surrounding mouse grabbing is potentially confusing. |
| 327 | * isAbsoluteEnabled tracks qemu_input_is_absolute() [ie "is the emulated |
| 328 | * pointing device an absolute-position one?"], but is only updated on |
| 329 | * next refresh. |
| 330 | * isMouseGrabbed tracks whether GUI events are directed to the guest; |
| 331 | * it controls whether special keys like Cmd get sent to the guest, |
| 332 | * and whether we capture the mouse when in non-absolute mode. |
Peter Maydell | f61c387 | 2014-06-23 10:35:24 +0100 | [diff] [blame] | 333 | */ |
Peter Maydell | 49b9bd4 | 2013-12-08 22:59:03 +0000 | [diff] [blame] | 334 | - (BOOL) isMouseGrabbed; |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 335 | - (BOOL) isAbsoluteEnabled; |
| 336 | - (float) cdx; |
| 337 | - (float) cdy; |
| 338 | - (QEMUScreen) gscreen; |
John Arbuckle | 3b178b7 | 2015-09-25 23:14:00 +0100 | [diff] [blame] | 339 | - (void) raiseAllKeys; |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 340 | @end |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 341 | |
Andreas Färber | 7fee199 | 2011-06-09 20:53:32 +0200 | [diff] [blame] | 342 | QemuCocoaView *cocoaView; |
| 343 | |
Gustavo Noronha Silva | f844cdb | 2022-03-06 21:11:18 +0900 | [diff] [blame] | 344 | static CGEventRef handleTapEvent(CGEventTapProxy proxy, CGEventType type, CGEventRef cgEvent, void *userInfo) |
| 345 | { |
| 346 | QemuCocoaView *cocoaView = userInfo; |
| 347 | NSEvent *event = [NSEvent eventWithCGEvent:cgEvent]; |
| 348 | if ([cocoaView isMouseGrabbed] && [cocoaView handleEvent:event]) { |
| 349 | COCOA_DEBUG("Global events tap: qemu handled the event, capturing!\n"); |
| 350 | return NULL; |
| 351 | } |
| 352 | COCOA_DEBUG("Global events tap: qemu did not handle the event, letting it through...\n"); |
| 353 | |
| 354 | return cgEvent; |
| 355 | } |
| 356 | |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 357 | @implementation QemuCocoaView |
| 358 | - (id)initWithFrame:(NSRect)frameRect |
| 359 | { |
| 360 | COCOA_DEBUG("QemuCocoaView: initWithFrame\n"); |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 361 | |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 362 | self = [super initWithFrame:frameRect]; |
| 363 | if (self) { |
pbrook | 9521989 | 2006-04-09 01:06:34 +0000 | [diff] [blame] | 364 | |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 365 | screen.width = frameRect.size.width; |
| 366 | screen.height = frameRect.size.height; |
Akihiko Odaki | 6d73bb6 | 2021-03-10 23:46:02 +0900 | [diff] [blame] | 367 | kbd = qkbd_state_init(dcl.con); |
bellard | 7c206a7 | 2005-12-18 19:18:45 +0000 | [diff] [blame] | 368 | |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 369 | } |
| 370 | return self; |
| 371 | } |
bellard | 7c206a7 | 2005-12-18 19:18:45 +0000 | [diff] [blame] | 372 | |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 373 | - (void) dealloc |
| 374 | { |
| 375 | COCOA_DEBUG("QemuCocoaView: dealloc\n"); |
bellard | 7c206a7 | 2005-12-18 19:18:45 +0000 | [diff] [blame] | 376 | |
Akihiko Odaki | c0ff29d | 2021-02-12 09:06:29 +0900 | [diff] [blame] | 377 | if (pixman_image) { |
Peter Maydell | 5588840 | 2019-02-25 10:24:33 +0000 | [diff] [blame] | 378 | pixman_image_unref(pixman_image); |
| 379 | } |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 380 | |
Akihiko Odaki | 6d73bb6 | 2021-03-10 23:46:02 +0900 | [diff] [blame] | 381 | qkbd_state_free(kbd); |
Gustavo Noronha Silva | f844cdb | 2022-03-06 21:11:18 +0900 | [diff] [blame] | 382 | |
| 383 | if (eventsTap) { |
| 384 | CFRelease(eventsTap); |
| 385 | } |
| 386 | |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 387 | [super dealloc]; |
| 388 | } |
bellard | 5cbfcd0 | 2006-06-14 15:53:24 +0000 | [diff] [blame] | 389 | |
Andreas Färber | d50f71d | 2009-12-13 02:03:33 +0100 | [diff] [blame] | 390 | - (BOOL) isOpaque |
| 391 | { |
| 392 | return YES; |
| 393 | } |
| 394 | |
Peter Maydell | 5dd45be | 2014-06-23 10:35:23 +0100 | [diff] [blame] | 395 | - (BOOL) screenContainsPoint:(NSPoint) p |
| 396 | { |
| 397 | return (p.x > -1 && p.x < screen.width && p.y > -1 && p.y < screen.height); |
| 398 | } |
| 399 | |
Chen Zhang | 2044dff | 2019-06-04 17:36:00 +0800 | [diff] [blame] | 400 | /* Get location of event and convert to virtual screen coordinate */ |
| 401 | - (CGPoint) screenLocationOfEvent:(NSEvent *)ev |
| 402 | { |
| 403 | NSWindow *eventWindow = [ev window]; |
| 404 | // XXX: Use CGRect and -convertRectFromScreen: to support macOS 10.10 |
| 405 | CGRect r = CGRectZero; |
| 406 | r.origin = [ev locationInWindow]; |
| 407 | if (!eventWindow) { |
| 408 | if (!isFullscreen) { |
| 409 | return [[self window] convertRectFromScreen:r].origin; |
| 410 | } else { |
| 411 | CGPoint locationInSelfWindow = [[self window] convertRectFromScreen:r].origin; |
| 412 | CGPoint loc = [self convertPoint:locationInSelfWindow fromView:nil]; |
| 413 | if (stretch_video) { |
| 414 | loc.x /= cdx; |
| 415 | loc.y /= cdy; |
| 416 | } |
| 417 | return loc; |
| 418 | } |
| 419 | } else if ([[self window] isEqual:eventWindow]) { |
| 420 | if (!isFullscreen) { |
| 421 | return r.origin; |
| 422 | } else { |
| 423 | CGPoint loc = [self convertPoint:r.origin fromView:nil]; |
| 424 | if (stretch_video) { |
| 425 | loc.x /= cdx; |
| 426 | loc.y /= cdy; |
| 427 | } |
| 428 | return loc; |
| 429 | } |
| 430 | } else { |
| 431 | return [[self window] convertRectFromScreen:[eventWindow convertRectToScreen:r]].origin; |
| 432 | } |
| 433 | } |
| 434 | |
Peter Maydell | 13aefd3 | 2014-06-23 10:35:25 +0100 | [diff] [blame] | 435 | - (void) hideCursor |
| 436 | { |
| 437 | if (!cursor_hide) { |
| 438 | return; |
| 439 | } |
| 440 | [NSCursor hide]; |
| 441 | } |
| 442 | |
| 443 | - (void) unhideCursor |
| 444 | { |
| 445 | if (!cursor_hide) { |
| 446 | return; |
| 447 | } |
| 448 | [NSCursor unhide]; |
| 449 | } |
| 450 | |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 451 | - (void) drawRect:(NSRect) rect |
| 452 | { |
| 453 | COCOA_DEBUG("QemuCocoaView: drawRect\n"); |
bellard | 5cbfcd0 | 2006-06-14 15:53:24 +0000 | [diff] [blame] | 454 | |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 455 | // get CoreGraphic context |
Brendan Shanks | 5e24600 | 2019-01-31 23:12:25 -0800 | [diff] [blame] | 456 | CGContextRef viewContextRef = [[NSGraphicsContext currentContext] CGContext]; |
Brendan Shanks | 5e24600 | 2019-01-31 23:12:25 -0800 | [diff] [blame] | 457 | |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 458 | CGContextSetInterpolationQuality (viewContextRef, kCGInterpolationNone); |
| 459 | CGContextSetShouldAntialias (viewContextRef, NO); |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 460 | |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 461 | // draw screen bitmap directly to Core Graphics context |
Akihiko Odaki | c0ff29d | 2021-02-12 09:06:29 +0900 | [diff] [blame] | 462 | if (!pixman_image) { |
Peter Maydell | 7d270b1 | 2013-12-24 02:51:47 +0000 | [diff] [blame] | 463 | // Draw request before any guest device has set up a framebuffer: |
| 464 | // just draw an opaque black rectangle |
| 465 | CGContextSetRGBFillColor(viewContextRef, 0, 0, 0, 1.0); |
| 466 | CGContextFillRect(viewContextRef, NSRectToCGRect(rect)); |
| 467 | } else { |
Akihiko Odaki | c0ff29d | 2021-02-12 09:06:29 +0900 | [diff] [blame] | 468 | int w = pixman_image_get_width(pixman_image); |
| 469 | int h = pixman_image_get_height(pixman_image); |
| 470 | int bitsPerPixel = PIXMAN_FORMAT_BPP(pixman_image_get_format(pixman_image)); |
Akihiko Odaki | d9c32b8 | 2021-02-22 23:40:12 +0900 | [diff] [blame] | 471 | int stride = pixman_image_get_stride(pixman_image); |
Akihiko Odaki | c0ff29d | 2021-02-12 09:06:29 +0900 | [diff] [blame] | 472 | CGDataProviderRef dataProviderRef = CGDataProviderCreateWithData( |
| 473 | NULL, |
| 474 | pixman_image_get_data(pixman_image), |
Akihiko Odaki | d9c32b8 | 2021-02-22 23:40:12 +0900 | [diff] [blame] | 475 | stride * h, |
Akihiko Odaki | c0ff29d | 2021-02-12 09:06:29 +0900 | [diff] [blame] | 476 | NULL |
| 477 | ); |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 478 | CGImageRef imageRef = CGImageCreate( |
Akihiko Odaki | c0ff29d | 2021-02-12 09:06:29 +0900 | [diff] [blame] | 479 | w, //width |
| 480 | h, //height |
Akihiko Odaki | d9c32b8 | 2021-02-22 23:40:12 +0900 | [diff] [blame] | 481 | DIV_ROUND_UP(bitsPerPixel, 8) * 2, //bitsPerComponent |
Akihiko Odaki | c0ff29d | 2021-02-12 09:06:29 +0900 | [diff] [blame] | 482 | bitsPerPixel, //bitsPerPixel |
Akihiko Odaki | d9c32b8 | 2021-02-22 23:40:12 +0900 | [diff] [blame] | 483 | stride, //bytesPerRow |
Akihiko Odaki | ae57d35 | 2021-03-05 21:13:04 +0900 | [diff] [blame] | 484 | CGColorSpaceCreateWithName(kCGColorSpaceSRGB), //colorspace |
| 485 | kCGBitmapByteOrder32Little | kCGImageAlphaNoneSkipFirst, //bitmapInfo |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 486 | dataProviderRef, //provider |
| 487 | NULL, //decode |
| 488 | 0, //interpolate |
| 489 | kCGRenderingIntentDefault //intent |
| 490 | ); |
Peter Maydell | b63901d | 2015-05-19 09:11:17 +0100 | [diff] [blame] | 491 | // selective drawing code (draws only dirty rectangles) (OS X >= 10.4) |
| 492 | const NSRect *rectList; |
Peter Maydell | b63901d | 2015-05-19 09:11:17 +0100 | [diff] [blame] | 493 | NSInteger rectCount; |
Peter Maydell | b63901d | 2015-05-19 09:11:17 +0100 | [diff] [blame] | 494 | int i; |
| 495 | CGImageRef clipImageRef; |
| 496 | CGRect clipRect; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 497 | |
Peter Maydell | b63901d | 2015-05-19 09:11:17 +0100 | [diff] [blame] | 498 | [self getRectsBeingDrawn:&rectList count:&rectCount]; |
| 499 | for (i = 0; i < rectCount; i++) { |
| 500 | clipRect.origin.x = rectList[i].origin.x / cdx; |
Akihiko Odaki | c0ff29d | 2021-02-12 09:06:29 +0900 | [diff] [blame] | 501 | clipRect.origin.y = (float)h - (rectList[i].origin.y + rectList[i].size.height) / cdy; |
Peter Maydell | b63901d | 2015-05-19 09:11:17 +0100 | [diff] [blame] | 502 | clipRect.size.width = rectList[i].size.width / cdx; |
| 503 | clipRect.size.height = rectList[i].size.height / cdy; |
| 504 | clipImageRef = CGImageCreateWithImageInRect( |
| 505 | imageRef, |
| 506 | clipRect |
| 507 | ); |
| 508 | CGContextDrawImage (viewContextRef, cgrect(rectList[i]), clipImageRef); |
| 509 | CGImageRelease (clipImageRef); |
bellard | 5b0753e | 2005-03-01 21:37:28 +0000 | [diff] [blame] | 510 | } |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 511 | CGImageRelease (imageRef); |
Akihiko Odaki | c0ff29d | 2021-02-12 09:06:29 +0900 | [diff] [blame] | 512 | CGDataProviderRelease(dataProviderRef); |
bellard | 5b0753e | 2005-03-01 21:37:28 +0000 | [diff] [blame] | 513 | } |
| 514 | } |
| 515 | |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 516 | - (void) setContentDimensions |
bellard | 5b0753e | 2005-03-01 21:37:28 +0000 | [diff] [blame] | 517 | { |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 518 | COCOA_DEBUG("QemuCocoaView: setContentDimensions\n"); |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 519 | |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 520 | if (isFullscreen) { |
| 521 | cdx = [[NSScreen mainScreen] frame].size.width / (float)screen.width; |
| 522 | cdy = [[NSScreen mainScreen] frame].size.height / (float)screen.height; |
Programmingkid | 5d1b2ee | 2015-05-19 09:11:17 +0100 | [diff] [blame] | 523 | |
| 524 | /* stretches video, but keeps same aspect ratio */ |
| 525 | if (stretch_video == true) { |
| 526 | /* use smallest stretch value - prevents clipping on sides */ |
| 527 | if (MIN(cdx, cdy) == cdx) { |
| 528 | cdy = cdx; |
| 529 | } else { |
| 530 | cdx = cdy; |
| 531 | } |
| 532 | } else { /* No stretching */ |
| 533 | cdx = cdy = 1; |
| 534 | } |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 535 | cw = screen.width * cdx; |
| 536 | ch = screen.height * cdy; |
| 537 | cx = ([[NSScreen mainScreen] frame].size.width - cw) / 2.0; |
| 538 | cy = ([[NSScreen mainScreen] frame].size.height - ch) / 2.0; |
| 539 | } else { |
| 540 | cx = 0; |
| 541 | cy = 0; |
| 542 | cw = screen.width; |
| 543 | ch = screen.height; |
| 544 | cdx = 1.0; |
| 545 | cdy = 1.0; |
| 546 | } |
bellard | 5b0753e | 2005-03-01 21:37:28 +0000 | [diff] [blame] | 547 | } |
| 548 | |
Peter Maydell | 8d65dee | 2022-02-24 10:13:29 +0000 | [diff] [blame] | 549 | - (void) updateUIInfoLocked |
Akihiko Odaki | 15280e8 | 2021-06-16 23:19:10 +0900 | [diff] [blame] | 550 | { |
Peter Maydell | 8d65dee | 2022-02-24 10:13:29 +0000 | [diff] [blame] | 551 | /* Must be called with the iothread lock, i.e. via updateUIInfo */ |
Akihiko Odaki | 15280e8 | 2021-06-16 23:19:10 +0900 | [diff] [blame] | 552 | NSSize frameSize; |
| 553 | QemuUIInfo info; |
| 554 | |
| 555 | if (!qemu_console_is_graphic(dcl.con)) { |
| 556 | return; |
| 557 | } |
| 558 | |
| 559 | if ([self window]) { |
| 560 | NSDictionary *description = [[[self window] screen] deviceDescription]; |
| 561 | CGDirectDisplayID display = [[description objectForKey:@"NSScreenNumber"] unsignedIntValue]; |
| 562 | NSSize screenSize = [[[self window] screen] frame].size; |
| 563 | CGSize screenPhysicalSize = CGDisplayScreenSize(display); |
Akihiko Odaki | 52eaefd | 2022-07-02 23:25:19 +0900 | [diff] [blame^] | 564 | CVDisplayLinkRef displayLink; |
Akihiko Odaki | 15280e8 | 2021-06-16 23:19:10 +0900 | [diff] [blame] | 565 | |
| 566 | frameSize = isFullscreen ? screenSize : [self frame].size; |
Akihiko Odaki | 52eaefd | 2022-07-02 23:25:19 +0900 | [diff] [blame^] | 567 | |
| 568 | if (!CVDisplayLinkCreateWithCGDisplay(display, &displayLink)) { |
| 569 | CVTime period = CVDisplayLinkGetNominalOutputVideoRefreshPeriod(displayLink); |
| 570 | CVDisplayLinkRelease(displayLink); |
| 571 | if (!(period.flags & kCVTimeIsIndefinite)) { |
| 572 | update_displaychangelistener(&dcl, |
| 573 | 1000 * period.timeValue / period.timeScale); |
| 574 | info.refresh_rate = (int64_t)1000 * period.timeScale / period.timeValue; |
| 575 | } |
| 576 | } |
| 577 | |
Akihiko Odaki | 15280e8 | 2021-06-16 23:19:10 +0900 | [diff] [blame] | 578 | info.width_mm = frameSize.width / screenSize.width * screenPhysicalSize.width; |
| 579 | info.height_mm = frameSize.height / screenSize.height * screenPhysicalSize.height; |
| 580 | } else { |
| 581 | frameSize = [self frame].size; |
| 582 | info.width_mm = 0; |
| 583 | info.height_mm = 0; |
| 584 | } |
| 585 | |
| 586 | info.xoff = 0; |
| 587 | info.yoff = 0; |
| 588 | info.width = frameSize.width; |
| 589 | info.height = frameSize.height; |
| 590 | |
Marc-André Lureau | ca19ef5 | 2021-04-13 20:39:11 +0400 | [diff] [blame] | 591 | dpy_set_ui_info(dcl.con, &info, TRUE); |
Akihiko Odaki | 15280e8 | 2021-06-16 23:19:10 +0900 | [diff] [blame] | 592 | } |
| 593 | |
Peter Maydell | 8d65dee | 2022-02-24 10:13:29 +0000 | [diff] [blame] | 594 | - (void) updateUIInfo |
| 595 | { |
| 596 | if (!allow_events) { |
| 597 | /* |
| 598 | * Don't try to tell QEMU about UI information in the application |
| 599 | * startup phase -- we haven't yet registered dcl with the QEMU UI |
| 600 | * layer, and also trying to take the iothread lock would deadlock. |
| 601 | * When cocoa_display_init() does register the dcl, the UI layer |
| 602 | * will call cocoa_switch(), which will call updateUIInfo, so |
| 603 | * we don't lose any information here. |
| 604 | */ |
| 605 | return; |
| 606 | } |
| 607 | |
| 608 | with_iothread_lock(^{ |
| 609 | [self updateUIInfoLocked]; |
| 610 | }); |
| 611 | } |
| 612 | |
Akihiko Odaki | 15280e8 | 2021-06-16 23:19:10 +0900 | [diff] [blame] | 613 | - (void)viewDidMoveToWindow |
| 614 | { |
| 615 | [self updateUIInfo]; |
| 616 | } |
| 617 | |
Peter Maydell | 72a3e31 | 2019-02-25 10:24:28 +0000 | [diff] [blame] | 618 | - (void) switchSurface:(pixman_image_t *)image |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 619 | { |
Gerd Hoffmann | 5e00d3a | 2013-03-01 12:52:06 +0100 | [diff] [blame] | 620 | COCOA_DEBUG("QemuCocoaView: switchSurface\n"); |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 621 | |
Peter Maydell | 72a3e31 | 2019-02-25 10:24:28 +0000 | [diff] [blame] | 622 | int w = pixman_image_get_width(image); |
| 623 | int h = pixman_image_get_height(image); |
Peter Maydell | 381600d | 2014-06-23 10:35:22 +0100 | [diff] [blame] | 624 | /* cdx == 0 means this is our very first surface, in which case we need |
| 625 | * to recalculate the content dimensions even if it happens to be the size |
| 626 | * of the initial empty window. |
| 627 | */ |
| 628 | bool isResize = (w != screen.width || h != screen.height || cdx == 0.0); |
Peter Maydell | d3345a0 | 2013-12-24 02:51:46 +0000 | [diff] [blame] | 629 | |
| 630 | int oldh = screen.height; |
| 631 | if (isResize) { |
| 632 | // Resize before we trigger the redraw, or we'll redraw at the wrong size |
| 633 | COCOA_DEBUG("switchSurface: new size %d x %d\n", w, h); |
| 634 | screen.width = w; |
| 635 | screen.height = h; |
| 636 | [self setContentDimensions]; |
| 637 | [self setFrame:NSMakeRect(cx, cy, cw, ch)]; |
| 638 | } |
Peter Maydell | 8510d91 | 2013-03-18 20:28:21 +0000 | [diff] [blame] | 639 | |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 640 | // update screenBuffer |
Akihiko Odaki | c0ff29d | 2021-02-12 09:06:29 +0900 | [diff] [blame] | 641 | if (pixman_image) { |
Peter Maydell | 5588840 | 2019-02-25 10:24:33 +0000 | [diff] [blame] | 642 | pixman_image_unref(pixman_image); |
| 643 | } |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 644 | |
Peter Maydell | 5588840 | 2019-02-25 10:24:33 +0000 | [diff] [blame] | 645 | pixman_image = image; |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 646 | |
| 647 | // update windows |
| 648 | if (isFullscreen) { |
| 649 | [[fullScreenWindow contentView] setFrame:[[NSScreen mainScreen] frame]]; |
Peter Maydell | d3345a0 | 2013-12-24 02:51:46 +0000 | [diff] [blame] | 650 | [normalWindow setFrame:NSMakeRect([normalWindow frame].origin.x, [normalWindow frame].origin.y - h + oldh, w, h + [normalWindow frame].size.height - oldh) display:NO animate:NO]; |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 651 | } else { |
| 652 | if (qemu_name) |
| 653 | [normalWindow setTitle:[NSString stringWithFormat:@"QEMU %s", qemu_name]]; |
Peter Maydell | d3345a0 | 2013-12-24 02:51:46 +0000 | [diff] [blame] | 654 | [normalWindow setFrame:NSMakeRect([normalWindow frame].origin.x, [normalWindow frame].origin.y - h + oldh, w, h + [normalWindow frame].size.height - oldh) display:YES animate:NO]; |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 655 | } |
Peter Maydell | d3345a0 | 2013-12-24 02:51:46 +0000 | [diff] [blame] | 656 | |
| 657 | if (isResize) { |
| 658 | [normalWindow center]; |
| 659 | } |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 660 | } |
| 661 | |
| 662 | - (void) toggleFullScreen:(id)sender |
| 663 | { |
| 664 | COCOA_DEBUG("QemuCocoaView: toggleFullScreen\n"); |
| 665 | |
| 666 | if (isFullscreen) { // switch from fullscreen to desktop |
| 667 | isFullscreen = FALSE; |
| 668 | [self ungrabMouse]; |
| 669 | [self setContentDimensions]; |
Akihiko Odaki | 1e8b6f2 | 2021-02-20 10:31:38 +0900 | [diff] [blame] | 670 | [fullScreenWindow close]; |
| 671 | [normalWindow setContentView: self]; |
| 672 | [normalWindow makeKeyAndOrderFront: self]; |
| 673 | [NSMenu setMenuBarVisible:YES]; |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 674 | } else { // switch from desktop to fullscreen |
| 675 | isFullscreen = TRUE; |
Programmingkid | 5d1b2ee | 2015-05-19 09:11:17 +0100 | [diff] [blame] | 676 | [normalWindow orderOut: nil]; /* Hide the window */ |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 677 | [self grabMouse]; |
| 678 | [self setContentDimensions]; |
Akihiko Odaki | 1e8b6f2 | 2021-02-20 10:31:38 +0900 | [diff] [blame] | 679 | [NSMenu setMenuBarVisible:NO]; |
| 680 | fullScreenWindow = [[NSWindow alloc] initWithContentRect:[[NSScreen mainScreen] frame] |
| 681 | styleMask:NSWindowStyleMaskBorderless |
| 682 | backing:NSBackingStoreBuffered |
| 683 | defer:NO]; |
| 684 | [fullScreenWindow setAcceptsMouseMovedEvents: YES]; |
| 685 | [fullScreenWindow setHasShadow:NO]; |
| 686 | [fullScreenWindow setBackgroundColor: [NSColor blackColor]]; |
| 687 | [self setFrame:NSMakeRect(cx, cy, cw, ch)]; |
| 688 | [[fullScreenWindow contentView] addSubview: self]; |
| 689 | [fullScreenWindow makeKeyAndOrderFront:self]; |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 690 | } |
| 691 | } |
| 692 | |
Gustavo Noronha Silva | f844cdb | 2022-03-06 21:11:18 +0900 | [diff] [blame] | 693 | - (void) setFullGrab:(id)sender |
| 694 | { |
| 695 | COCOA_DEBUG("QemuCocoaView: setFullGrab\n"); |
| 696 | |
| 697 | CGEventMask mask = CGEventMaskBit(kCGEventKeyDown) | CGEventMaskBit(kCGEventKeyUp) | CGEventMaskBit(kCGEventFlagsChanged); |
| 698 | eventsTap = CGEventTapCreate(kCGHIDEventTap, kCGHeadInsertEventTap, kCGEventTapOptionDefault, |
| 699 | mask, handleTapEvent, self); |
| 700 | if (!eventsTap) { |
| 701 | warn_report("Could not create event tap, system key combos will not be captured.\n"); |
| 702 | return; |
| 703 | } else { |
| 704 | COCOA_DEBUG("Global events tap created! Will capture system key combos.\n"); |
| 705 | } |
| 706 | |
| 707 | CFRunLoopRef runLoop = CFRunLoopGetCurrent(); |
| 708 | if (!runLoop) { |
| 709 | warn_report("Could not obtain current CF RunLoop, system key combos will not be captured.\n"); |
| 710 | return; |
| 711 | } |
| 712 | |
| 713 | CFRunLoopSourceRef tapEventsSrc = CFMachPortCreateRunLoopSource(kCFAllocatorDefault, eventsTap, 0); |
| 714 | if (!tapEventsSrc ) { |
| 715 | warn_report("Could not obtain current CF RunLoop, system key combos will not be captured.\n"); |
| 716 | return; |
| 717 | } |
| 718 | |
| 719 | CFRunLoopAddSource(runLoop, tapEventsSrc, kCFRunLoopDefaultMode); |
| 720 | CFRelease(tapEventsSrc); |
| 721 | } |
| 722 | |
Akihiko Odaki | 6d73bb6 | 2021-03-10 23:46:02 +0900 | [diff] [blame] | 723 | - (void) toggleKey: (int)keycode { |
| 724 | qkbd_state_key_event(kbd, keycode, !qkbd_state_key_get(kbd, keycode)); |
Ian McKellar via Qemu-devel | af8862b | 2017-05-26 16:38:16 -0700 | [diff] [blame] | 725 | } |
| 726 | |
John Arbuckle | 9c3a418 | 2017-11-07 10:14:14 +0000 | [diff] [blame] | 727 | // Does the work of sending input to the monitor |
| 728 | - (void) handleMonitorInput:(NSEvent *)event |
| 729 | { |
| 730 | int keysym = 0; |
| 731 | int control_key = 0; |
| 732 | |
| 733 | // if the control key is down |
| 734 | if ([event modifierFlags] & NSEventModifierFlagControl) { |
| 735 | control_key = 1; |
| 736 | } |
| 737 | |
| 738 | /* translates Macintosh keycodes to QEMU's keysym */ |
| 739 | |
Philippe Mathieu-Daudé | 9459262 | 2022-02-15 16:21:14 +0100 | [diff] [blame] | 740 | static const int without_control_translation[] = { |
John Arbuckle | 9c3a418 | 2017-11-07 10:14:14 +0000 | [diff] [blame] | 741 | [0 ... 0xff] = 0, // invalid key |
| 742 | |
| 743 | [kVK_UpArrow] = QEMU_KEY_UP, |
| 744 | [kVK_DownArrow] = QEMU_KEY_DOWN, |
| 745 | [kVK_RightArrow] = QEMU_KEY_RIGHT, |
| 746 | [kVK_LeftArrow] = QEMU_KEY_LEFT, |
| 747 | [kVK_Home] = QEMU_KEY_HOME, |
| 748 | [kVK_End] = QEMU_KEY_END, |
| 749 | [kVK_PageUp] = QEMU_KEY_PAGEUP, |
| 750 | [kVK_PageDown] = QEMU_KEY_PAGEDOWN, |
| 751 | [kVK_ForwardDelete] = QEMU_KEY_DELETE, |
| 752 | [kVK_Delete] = QEMU_KEY_BACKSPACE, |
| 753 | }; |
| 754 | |
Philippe Mathieu-Daudé | 9459262 | 2022-02-15 16:21:14 +0100 | [diff] [blame] | 755 | static const int with_control_translation[] = { |
John Arbuckle | 9c3a418 | 2017-11-07 10:14:14 +0000 | [diff] [blame] | 756 | [0 ... 0xff] = 0, // invalid key |
| 757 | |
| 758 | [kVK_UpArrow] = QEMU_KEY_CTRL_UP, |
| 759 | [kVK_DownArrow] = QEMU_KEY_CTRL_DOWN, |
| 760 | [kVK_RightArrow] = QEMU_KEY_CTRL_RIGHT, |
| 761 | [kVK_LeftArrow] = QEMU_KEY_CTRL_LEFT, |
| 762 | [kVK_Home] = QEMU_KEY_CTRL_HOME, |
| 763 | [kVK_End] = QEMU_KEY_CTRL_END, |
| 764 | [kVK_PageUp] = QEMU_KEY_CTRL_PAGEUP, |
| 765 | [kVK_PageDown] = QEMU_KEY_CTRL_PAGEDOWN, |
| 766 | }; |
| 767 | |
| 768 | if (control_key != 0) { /* If the control key is being used */ |
| 769 | if ([event keyCode] < ARRAY_SIZE(with_control_translation)) { |
| 770 | keysym = with_control_translation[[event keyCode]]; |
| 771 | } |
| 772 | } else { |
| 773 | if ([event keyCode] < ARRAY_SIZE(without_control_translation)) { |
| 774 | keysym = without_control_translation[[event keyCode]]; |
| 775 | } |
| 776 | } |
| 777 | |
| 778 | // if not a key that needs translating |
| 779 | if (keysym == 0) { |
| 780 | NSString *ks = [event characters]; |
| 781 | if ([ks length] > 0) { |
| 782 | keysym = [ks characterAtIndex:0]; |
| 783 | } |
| 784 | } |
| 785 | |
| 786 | if (keysym) { |
| 787 | kbd_put_keysym(keysym); |
| 788 | } |
| 789 | } |
| 790 | |
Peter Maydell | 60105d7 | 2019-02-25 10:24:31 +0000 | [diff] [blame] | 791 | - (bool) handleEvent:(NSEvent *)event |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 792 | { |
Hikaru Nishida | dff742a | 2019-10-15 10:07:34 +0900 | [diff] [blame] | 793 | if(!allow_events) { |
| 794 | /* |
| 795 | * Just let OSX have all events that arrive before |
| 796 | * applicationDidFinishLaunching. |
| 797 | * This avoids a deadlock on the iothread lock, which cocoa_display_init() |
| 798 | * will not drop until after the app_started_sem is posted. (In theory |
| 799 | * there should not be any such events, but OSX Catalina now emits some.) |
| 800 | */ |
| 801 | return false; |
| 802 | } |
Peter Maydell | 60105d7 | 2019-02-25 10:24:31 +0000 | [diff] [blame] | 803 | return bool_with_iothread_lock(^{ |
| 804 | return [self handleEventLocked:event]; |
Peter Maydell | 31819e9 | 2019-02-25 10:24:27 +0000 | [diff] [blame] | 805 | }); |
| 806 | } |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 807 | |
Peter Maydell | 60105d7 | 2019-02-25 10:24:31 +0000 | [diff] [blame] | 808 | - (bool) handleEventLocked:(NSEvent *)event |
Peter Maydell | 31819e9 | 2019-02-25 10:24:27 +0000 | [diff] [blame] | 809 | { |
Peter Maydell | 60105d7 | 2019-02-25 10:24:31 +0000 | [diff] [blame] | 810 | /* Return true if we handled the event, false if it should be given to OSX */ |
Peter Maydell | 31819e9 | 2019-02-25 10:24:27 +0000 | [diff] [blame] | 811 | COCOA_DEBUG("QemuCocoaView: handleEvent\n"); |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 812 | int buttons = 0; |
Ian McKellar via Qemu-devel | af8862b | 2017-05-26 16:38:16 -0700 | [diff] [blame] | 813 | int keycode = 0; |
Gerd Hoffmann | 21bae11 | 2013-12-04 14:08:04 +0100 | [diff] [blame] | 814 | bool mouse_event = false; |
Chen Zhang | 2044dff | 2019-06-04 17:36:00 +0800 | [diff] [blame] | 815 | // Location of event in virtual screen coordinates |
| 816 | NSPoint p = [self screenLocationOfEvent:event]; |
Akihiko Odaki | 6d73bb6 | 2021-03-10 23:46:02 +0900 | [diff] [blame] | 817 | NSUInteger modifiers = [event modifierFlags]; |
| 818 | |
Akihiko Odaki | ad7f2f8 | 2021-03-12 22:32:12 +0900 | [diff] [blame] | 819 | /* |
| 820 | * Check -[NSEvent modifierFlags] here. |
| 821 | * |
| 822 | * There is a NSEventType for an event notifying the change of |
| 823 | * -[NSEvent modifierFlags], NSEventTypeFlagsChanged but these operations |
| 824 | * are performed for any events because a modifier state may change while |
| 825 | * the application is inactive (i.e. no events fire) and we don't want to |
| 826 | * wait for another modifier state change to detect such a change. |
| 827 | * |
| 828 | * NSEventModifierFlagCapsLock requires a special treatment. The other flags |
| 829 | * are handled in similar manners. |
| 830 | * |
| 831 | * NSEventModifierFlagCapsLock |
| 832 | * --------------------------- |
| 833 | * |
| 834 | * If CapsLock state is changed, "up" and "down" events will be fired in |
| 835 | * sequence, effectively updates CapsLock state on the guest. |
| 836 | * |
| 837 | * The other flags |
| 838 | * --------------- |
| 839 | * |
| 840 | * If a flag is not set, fire "up" events for all keys which correspond to |
| 841 | * the flag. Note that "down" events are not fired here because the flags |
| 842 | * checked here do not tell what exact keys are down. |
| 843 | * |
| 844 | * If one of the keys corresponding to a flag is down, we rely on |
| 845 | * -[NSEvent keyCode] of an event whose -[NSEvent type] is |
| 846 | * NSEventTypeFlagsChanged to know the exact key which is down, which has |
| 847 | * the following two downsides: |
| 848 | * - It does not work when the application is inactive as described above. |
| 849 | * - It malfactions *after* the modifier state is changed while the |
| 850 | * application is inactive. It is because -[NSEvent keyCode] does not tell |
| 851 | * if the key is up or down, and requires to infer the current state from |
| 852 | * the previous state. It is still possible to fix such a malfanction by |
| 853 | * completely leaving your hands from the keyboard, which hopefully makes |
| 854 | * this implementation usable enough. |
| 855 | */ |
Akihiko Odaki | 6d73bb6 | 2021-03-10 23:46:02 +0900 | [diff] [blame] | 856 | if (!!(modifiers & NSEventModifierFlagCapsLock) != |
| 857 | qkbd_state_modifier_get(kbd, QKBD_MOD_CAPSLOCK)) { |
| 858 | qkbd_state_key_event(kbd, Q_KEY_CODE_CAPS_LOCK, true); |
| 859 | qkbd_state_key_event(kbd, Q_KEY_CODE_CAPS_LOCK, false); |
| 860 | } |
| 861 | |
| 862 | if (!(modifiers & NSEventModifierFlagShift)) { |
| 863 | qkbd_state_key_event(kbd, Q_KEY_CODE_SHIFT, false); |
| 864 | qkbd_state_key_event(kbd, Q_KEY_CODE_SHIFT_R, false); |
| 865 | } |
| 866 | if (!(modifiers & NSEventModifierFlagControl)) { |
| 867 | qkbd_state_key_event(kbd, Q_KEY_CODE_CTRL, false); |
| 868 | qkbd_state_key_event(kbd, Q_KEY_CODE_CTRL_R, false); |
| 869 | } |
| 870 | if (!(modifiers & NSEventModifierFlagOption)) { |
Gustavo Noronha Silva | 4797adc | 2022-03-06 21:11:19 +0900 | [diff] [blame] | 871 | if (swap_opt_cmd) { |
| 872 | qkbd_state_key_event(kbd, Q_KEY_CODE_META_L, false); |
| 873 | qkbd_state_key_event(kbd, Q_KEY_CODE_META_R, false); |
| 874 | } else { |
| 875 | qkbd_state_key_event(kbd, Q_KEY_CODE_ALT, false); |
| 876 | qkbd_state_key_event(kbd, Q_KEY_CODE_ALT_R, false); |
| 877 | } |
Akihiko Odaki | 6d73bb6 | 2021-03-10 23:46:02 +0900 | [diff] [blame] | 878 | } |
| 879 | if (!(modifiers & NSEventModifierFlagCommand)) { |
Gustavo Noronha Silva | 4797adc | 2022-03-06 21:11:19 +0900 | [diff] [blame] | 880 | if (swap_opt_cmd) { |
| 881 | qkbd_state_key_event(kbd, Q_KEY_CODE_ALT, false); |
| 882 | qkbd_state_key_event(kbd, Q_KEY_CODE_ALT_R, false); |
| 883 | } else { |
| 884 | qkbd_state_key_event(kbd, Q_KEY_CODE_META_L, false); |
| 885 | qkbd_state_key_event(kbd, Q_KEY_CODE_META_R, false); |
| 886 | } |
Akihiko Odaki | 6d73bb6 | 2021-03-10 23:46:02 +0900 | [diff] [blame] | 887 | } |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 888 | |
| 889 | switch ([event type]) { |
Brendan Shanks | 4ba967a | 2017-04-24 23:29:52 -0700 | [diff] [blame] | 890 | case NSEventTypeFlagsChanged: |
Akihiko Odaki | 6d73bb6 | 2021-03-10 23:46:02 +0900 | [diff] [blame] | 891 | switch ([event keyCode]) { |
| 892 | case kVK_Shift: |
| 893 | if (!!(modifiers & NSEventModifierFlagShift)) { |
| 894 | [self toggleKey:Q_KEY_CODE_SHIFT]; |
| 895 | } |
| 896 | break; |
Ian McKellar via Qemu-devel | af8862b | 2017-05-26 16:38:16 -0700 | [diff] [blame] | 897 | |
Akihiko Odaki | 6d73bb6 | 2021-03-10 23:46:02 +0900 | [diff] [blame] | 898 | case kVK_RightShift: |
| 899 | if (!!(modifiers & NSEventModifierFlagShift)) { |
| 900 | [self toggleKey:Q_KEY_CODE_SHIFT_R]; |
| 901 | } |
| 902 | break; |
Ian McKellar via Qemu-devel | af8862b | 2017-05-26 16:38:16 -0700 | [diff] [blame] | 903 | |
Akihiko Odaki | 6d73bb6 | 2021-03-10 23:46:02 +0900 | [diff] [blame] | 904 | case kVK_Control: |
| 905 | if (!!(modifiers & NSEventModifierFlagControl)) { |
| 906 | [self toggleKey:Q_KEY_CODE_CTRL]; |
Ian McKellar via Qemu-devel | af8862b | 2017-05-26 16:38:16 -0700 | [diff] [blame] | 907 | } |
Akihiko Odaki | 6d73bb6 | 2021-03-10 23:46:02 +0900 | [diff] [blame] | 908 | break; |
| 909 | |
| 910 | case kVK_RightControl: |
| 911 | if (!!(modifiers & NSEventModifierFlagControl)) { |
| 912 | [self toggleKey:Q_KEY_CODE_CTRL_R]; |
Ian McKellar via Qemu-devel | af8862b | 2017-05-26 16:38:16 -0700 | [diff] [blame] | 913 | } |
Akihiko Odaki | 6d73bb6 | 2021-03-10 23:46:02 +0900 | [diff] [blame] | 914 | break; |
| 915 | |
| 916 | case kVK_Option: |
| 917 | if (!!(modifiers & NSEventModifierFlagOption)) { |
Gustavo Noronha Silva | 4797adc | 2022-03-06 21:11:19 +0900 | [diff] [blame] | 918 | if (swap_opt_cmd) { |
| 919 | [self toggleKey:Q_KEY_CODE_META_L]; |
| 920 | } else { |
| 921 | [self toggleKey:Q_KEY_CODE_ALT]; |
| 922 | } |
Ian McKellar via Qemu-devel | af8862b | 2017-05-26 16:38:16 -0700 | [diff] [blame] | 923 | } |
Akihiko Odaki | 6d73bb6 | 2021-03-10 23:46:02 +0900 | [diff] [blame] | 924 | break; |
| 925 | |
| 926 | case kVK_RightOption: |
| 927 | if (!!(modifiers & NSEventModifierFlagOption)) { |
Gustavo Noronha Silva | 4797adc | 2022-03-06 21:11:19 +0900 | [diff] [blame] | 928 | if (swap_opt_cmd) { |
| 929 | [self toggleKey:Q_KEY_CODE_META_R]; |
| 930 | } else { |
| 931 | [self toggleKey:Q_KEY_CODE_ALT_R]; |
| 932 | } |
Ian McKellar via Qemu-devel | af8862b | 2017-05-26 16:38:16 -0700 | [diff] [blame] | 933 | } |
Akihiko Odaki | 6d73bb6 | 2021-03-10 23:46:02 +0900 | [diff] [blame] | 934 | break; |
| 935 | |
| 936 | /* Don't pass command key changes to guest unless mouse is grabbed */ |
| 937 | case kVK_Command: |
| 938 | if (isMouseGrabbed && |
Akihiko Odaki | d6b6dea | 2022-03-18 00:29:49 +0900 | [diff] [blame] | 939 | !!(modifiers & NSEventModifierFlagCommand) && |
| 940 | left_command_key_enabled) { |
Gustavo Noronha Silva | 4797adc | 2022-03-06 21:11:19 +0900 | [diff] [blame] | 941 | if (swap_opt_cmd) { |
| 942 | [self toggleKey:Q_KEY_CODE_ALT]; |
| 943 | } else { |
| 944 | [self toggleKey:Q_KEY_CODE_META_L]; |
| 945 | } |
Ian McKellar via Qemu-devel | af8862b | 2017-05-26 16:38:16 -0700 | [diff] [blame] | 946 | } |
Akihiko Odaki | 6d73bb6 | 2021-03-10 23:46:02 +0900 | [diff] [blame] | 947 | break; |
| 948 | |
| 949 | case kVK_RightCommand: |
| 950 | if (isMouseGrabbed && |
| 951 | !!(modifiers & NSEventModifierFlagCommand)) { |
Gustavo Noronha Silva | 4797adc | 2022-03-06 21:11:19 +0900 | [diff] [blame] | 952 | if (swap_opt_cmd) { |
| 953 | [self toggleKey:Q_KEY_CODE_ALT_R]; |
| 954 | } else { |
| 955 | [self toggleKey:Q_KEY_CODE_META_R]; |
| 956 | } |
Akihiko Odaki | 6d73bb6 | 2021-03-10 23:46:02 +0900 | [diff] [blame] | 957 | } |
| 958 | break; |
Ian McKellar via Qemu-devel | af8862b | 2017-05-26 16:38:16 -0700 | [diff] [blame] | 959 | } |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 960 | break; |
Brendan Shanks | 4ba967a | 2017-04-24 23:29:52 -0700 | [diff] [blame] | 961 | case NSEventTypeKeyDown: |
Peter Maydell | 8895919 | 2013-12-08 22:59:02 +0000 | [diff] [blame] | 962 | keycode = cocoa_keycode_to_qemu([event keyCode]); |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 963 | |
Peter Maydell | 8895919 | 2013-12-08 22:59:02 +0000 | [diff] [blame] | 964 | // forward command key combos to the host UI unless the mouse is grabbed |
Brendan Shanks | 4ba967a | 2017-04-24 23:29:52 -0700 | [diff] [blame] | 965 | if (!isMouseGrabbed && ([event modifierFlags] & NSEventModifierFlagCommand)) { |
Peter Maydell | 60105d7 | 2019-02-25 10:24:31 +0000 | [diff] [blame] | 966 | return false; |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 967 | } |
| 968 | |
| 969 | // default |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 970 | |
John Arbuckle | 5929e36 | 2017-11-07 10:14:14 +0000 | [diff] [blame] | 971 | // handle control + alt Key Combos (ctrl+alt+[1..9,g] is reserved for QEMU) |
Brendan Shanks | 4ba967a | 2017-04-24 23:29:52 -0700 | [diff] [blame] | 972 | if (([event modifierFlags] & NSEventModifierFlagControl) && ([event modifierFlags] & NSEventModifierFlagOption)) { |
John Arbuckle | 5929e36 | 2017-11-07 10:14:14 +0000 | [diff] [blame] | 973 | NSString *keychar = [event charactersIgnoringModifiers]; |
| 974 | if ([keychar length] == 1) { |
| 975 | char key = [keychar characterAtIndex:0]; |
| 976 | switch (key) { |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 977 | |
John Arbuckle | 5929e36 | 2017-11-07 10:14:14 +0000 | [diff] [blame] | 978 | // enable graphic console |
| 979 | case '1' ... '9': |
| 980 | console_select(key - '0' - 1); /* ascii math */ |
Peter Maydell | 60105d7 | 2019-02-25 10:24:31 +0000 | [diff] [blame] | 981 | return true; |
John Arbuckle | 5929e36 | 2017-11-07 10:14:14 +0000 | [diff] [blame] | 982 | |
| 983 | // release the mouse grab |
| 984 | case 'g': |
| 985 | [self ungrabMouse]; |
Peter Maydell | 60105d7 | 2019-02-25 10:24:31 +0000 | [diff] [blame] | 986 | return true; |
John Arbuckle | 5929e36 | 2017-11-07 10:14:14 +0000 | [diff] [blame] | 987 | } |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 988 | } |
Peter Maydell | ef2088f | 2017-11-07 10:14:14 +0000 | [diff] [blame] | 989 | } |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 990 | |
Peter Maydell | ef2088f | 2017-11-07 10:14:14 +0000 | [diff] [blame] | 991 | if (qemu_console_is_graphic(NULL)) { |
Akihiko Odaki | 6d73bb6 | 2021-03-10 23:46:02 +0900 | [diff] [blame] | 992 | qkbd_state_key_event(kbd, keycode, true); |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 993 | } else { |
John Arbuckle | 9c3a418 | 2017-11-07 10:14:14 +0000 | [diff] [blame] | 994 | [self handleMonitorInput: event]; |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 995 | } |
| 996 | break; |
Brendan Shanks | 4ba967a | 2017-04-24 23:29:52 -0700 | [diff] [blame] | 997 | case NSEventTypeKeyUp: |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 998 | keycode = cocoa_keycode_to_qemu([event keyCode]); |
Peter Maydell | 8895919 | 2013-12-08 22:59:02 +0000 | [diff] [blame] | 999 | |
| 1000 | // don't pass the guest a spurious key-up if we treated this |
| 1001 | // command-key combo as a host UI action |
Brendan Shanks | 4ba967a | 2017-04-24 23:29:52 -0700 | [diff] [blame] | 1002 | if (!isMouseGrabbed && ([event modifierFlags] & NSEventModifierFlagCommand)) { |
Peter Maydell | 60105d7 | 2019-02-25 10:24:31 +0000 | [diff] [blame] | 1003 | return true; |
Peter Maydell | 8895919 | 2013-12-08 22:59:02 +0000 | [diff] [blame] | 1004 | } |
| 1005 | |
Peter Maydell | 68c0aa6 | 2013-04-17 09:16:35 +0000 | [diff] [blame] | 1006 | if (qemu_console_is_graphic(NULL)) { |
Akihiko Odaki | 6d73bb6 | 2021-03-10 23:46:02 +0900 | [diff] [blame] | 1007 | qkbd_state_key_event(kbd, keycode, false); |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 1008 | } |
| 1009 | break; |
Brendan Shanks | 4ba967a | 2017-04-24 23:29:52 -0700 | [diff] [blame] | 1010 | case NSEventTypeMouseMoved: |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 1011 | if (isAbsoluteEnabled) { |
Chen Zhang | 2044dff | 2019-06-04 17:36:00 +0800 | [diff] [blame] | 1012 | // Cursor re-entered into a window might generate events bound to screen coordinates |
| 1013 | // and `nil` window property, and in full screen mode, current window might not be |
| 1014 | // key window, where event location alone should suffice. |
| 1015 | if (![self screenContainsPoint:p] || !([[self window] isKeyWindow] || isFullscreen)) { |
Peter Maydell | f61c387 | 2014-06-23 10:35:24 +0100 | [diff] [blame] | 1016 | if (isMouseGrabbed) { |
| 1017 | [self ungrabMouse]; |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 1018 | } |
| 1019 | } else { |
Peter Maydell | f61c387 | 2014-06-23 10:35:24 +0100 | [diff] [blame] | 1020 | if (!isMouseGrabbed) { |
| 1021 | [self grabMouse]; |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 1022 | } |
| 1023 | } |
| 1024 | } |
Gerd Hoffmann | 21bae11 | 2013-12-04 14:08:04 +0100 | [diff] [blame] | 1025 | mouse_event = true; |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 1026 | break; |
Brendan Shanks | 4ba967a | 2017-04-24 23:29:52 -0700 | [diff] [blame] | 1027 | case NSEventTypeLeftMouseDown: |
Akihiko Odaki | 4295f83 | 2021-02-12 09:07:06 +0900 | [diff] [blame] | 1028 | buttons |= MOUSE_EVENT_LBUTTON; |
Gerd Hoffmann | 21bae11 | 2013-12-04 14:08:04 +0100 | [diff] [blame] | 1029 | mouse_event = true; |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 1030 | break; |
Brendan Shanks | 4ba967a | 2017-04-24 23:29:52 -0700 | [diff] [blame] | 1031 | case NSEventTypeRightMouseDown: |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 1032 | buttons |= MOUSE_EVENT_RBUTTON; |
Gerd Hoffmann | 21bae11 | 2013-12-04 14:08:04 +0100 | [diff] [blame] | 1033 | mouse_event = true; |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 1034 | break; |
Brendan Shanks | 4ba967a | 2017-04-24 23:29:52 -0700 | [diff] [blame] | 1035 | case NSEventTypeOtherMouseDown: |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 1036 | buttons |= MOUSE_EVENT_MBUTTON; |
Gerd Hoffmann | 21bae11 | 2013-12-04 14:08:04 +0100 | [diff] [blame] | 1037 | mouse_event = true; |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 1038 | break; |
Brendan Shanks | 4ba967a | 2017-04-24 23:29:52 -0700 | [diff] [blame] | 1039 | case NSEventTypeLeftMouseDragged: |
Akihiko Odaki | 4295f83 | 2021-02-12 09:07:06 +0900 | [diff] [blame] | 1040 | buttons |= MOUSE_EVENT_LBUTTON; |
Gerd Hoffmann | 21bae11 | 2013-12-04 14:08:04 +0100 | [diff] [blame] | 1041 | mouse_event = true; |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 1042 | break; |
Brendan Shanks | 4ba967a | 2017-04-24 23:29:52 -0700 | [diff] [blame] | 1043 | case NSEventTypeRightMouseDragged: |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 1044 | buttons |= MOUSE_EVENT_RBUTTON; |
Gerd Hoffmann | 21bae11 | 2013-12-04 14:08:04 +0100 | [diff] [blame] | 1045 | mouse_event = true; |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 1046 | break; |
Brendan Shanks | 4ba967a | 2017-04-24 23:29:52 -0700 | [diff] [blame] | 1047 | case NSEventTypeOtherMouseDragged: |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 1048 | buttons |= MOUSE_EVENT_MBUTTON; |
Gerd Hoffmann | 21bae11 | 2013-12-04 14:08:04 +0100 | [diff] [blame] | 1049 | mouse_event = true; |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 1050 | break; |
Brendan Shanks | 4ba967a | 2017-04-24 23:29:52 -0700 | [diff] [blame] | 1051 | case NSEventTypeLeftMouseUp: |
Peter Maydell | f61c387 | 2014-06-23 10:35:24 +0100 | [diff] [blame] | 1052 | mouse_event = true; |
| 1053 | if (!isMouseGrabbed && [self screenContainsPoint:p]) { |
Chen Zhang | 8e23e34 | 2019-06-04 17:36:48 +0800 | [diff] [blame] | 1054 | /* |
| 1055 | * In fullscreen mode, the window of cocoaView may not be the |
| 1056 | * key window, therefore the position relative to the virtual |
| 1057 | * screen alone will be sufficient. |
| 1058 | */ |
| 1059 | if(isFullscreen || [[self window] isKeyWindow]) { |
Programmingkid | 9e8204b | 2016-08-15 22:11:06 -0400 | [diff] [blame] | 1060 | [self grabMouse]; |
| 1061 | } |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 1062 | } |
| 1063 | break; |
Brendan Shanks | 4ba967a | 2017-04-24 23:29:52 -0700 | [diff] [blame] | 1064 | case NSEventTypeRightMouseUp: |
Gerd Hoffmann | 21bae11 | 2013-12-04 14:08:04 +0100 | [diff] [blame] | 1065 | mouse_event = true; |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 1066 | break; |
Brendan Shanks | 4ba967a | 2017-04-24 23:29:52 -0700 | [diff] [blame] | 1067 | case NSEventTypeOtherMouseUp: |
Gerd Hoffmann | 21bae11 | 2013-12-04 14:08:04 +0100 | [diff] [blame] | 1068 | mouse_event = true; |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 1069 | break; |
Brendan Shanks | 4ba967a | 2017-04-24 23:29:52 -0700 | [diff] [blame] | 1070 | case NSEventTypeScrollWheel: |
John Arbuckle | ae7313e | 2018-01-08 13:07:07 -0500 | [diff] [blame] | 1071 | /* |
| 1072 | * Send wheel events to the guest regardless of window focus. |
| 1073 | * This is in-line with standard Mac OS X UI behaviour. |
| 1074 | */ |
| 1075 | |
John Arbuckle | dc3c89d | 2018-07-09 11:02:35 -0400 | [diff] [blame] | 1076 | /* |
Dmitry Petrov | d70a5de | 2022-01-08 16:39:44 +0100 | [diff] [blame] | 1077 | * We shouldn't have got a scroll event when deltaY and delta Y |
| 1078 | * are zero, hence no harm in dropping the event |
John Arbuckle | dc3c89d | 2018-07-09 11:02:35 -0400 | [diff] [blame] | 1079 | */ |
Dmitry Petrov | d70a5de | 2022-01-08 16:39:44 +0100 | [diff] [blame] | 1080 | if ([event deltaY] != 0 || [event deltaX] != 0) { |
John Arbuckle | ae7313e | 2018-01-08 13:07:07 -0500 | [diff] [blame] | 1081 | /* Determine if this is a scroll up or scroll down event */ |
Dmitry Petrov | d70a5de | 2022-01-08 16:39:44 +0100 | [diff] [blame] | 1082 | if ([event deltaY] != 0) { |
| 1083 | buttons = ([event deltaY] > 0) ? |
John Arbuckle | dc3c89d | 2018-07-09 11:02:35 -0400 | [diff] [blame] | 1084 | INPUT_BUTTON_WHEEL_UP : INPUT_BUTTON_WHEEL_DOWN; |
Dmitry Petrov | d70a5de | 2022-01-08 16:39:44 +0100 | [diff] [blame] | 1085 | } else if ([event deltaX] != 0) { |
| 1086 | buttons = ([event deltaX] > 0) ? |
| 1087 | INPUT_BUTTON_WHEEL_LEFT : INPUT_BUTTON_WHEEL_RIGHT; |
| 1088 | } |
| 1089 | |
Akihiko Odaki | cc7859c | 2021-02-19 17:44:19 +0900 | [diff] [blame] | 1090 | qemu_input_queue_btn(dcl.con, buttons, true); |
John Arbuckle | dc3c89d | 2018-07-09 11:02:35 -0400 | [diff] [blame] | 1091 | qemu_input_event_sync(); |
Akihiko Odaki | cc7859c | 2021-02-19 17:44:19 +0900 | [diff] [blame] | 1092 | qemu_input_queue_btn(dcl.con, buttons, false); |
John Arbuckle | dc3c89d | 2018-07-09 11:02:35 -0400 | [diff] [blame] | 1093 | qemu_input_event_sync(); |
| 1094 | } |
Dmitry Petrov | d70a5de | 2022-01-08 16:39:44 +0100 | [diff] [blame] | 1095 | |
John Arbuckle | ae7313e | 2018-01-08 13:07:07 -0500 | [diff] [blame] | 1096 | /* |
Dmitry Petrov | d70a5de | 2022-01-08 16:39:44 +0100 | [diff] [blame] | 1097 | * Since deltaX/deltaY also report scroll wheel events we prevent mouse |
John Arbuckle | ae7313e | 2018-01-08 13:07:07 -0500 | [diff] [blame] | 1098 | * movement code from executing. |
| 1099 | */ |
| 1100 | mouse_event = false; |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 1101 | break; |
| 1102 | default: |
Peter Maydell | 60105d7 | 2019-02-25 10:24:31 +0000 | [diff] [blame] | 1103 | return false; |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 1104 | } |
Gerd Hoffmann | 21bae11 | 2013-12-04 14:08:04 +0100 | [diff] [blame] | 1105 | |
| 1106 | if (mouse_event) { |
Peter Maydell | 8d3a5d9 | 2015-11-26 15:19:28 +0000 | [diff] [blame] | 1107 | /* Don't send button events to the guest unless we've got a |
| 1108 | * mouse grab or window focus. If we have neither then this event |
| 1109 | * is the user clicking on the background window to activate and |
| 1110 | * bring us to the front, which will be done by the sendEvent |
| 1111 | * call below. We definitely don't want to pass that click through |
| 1112 | * to the guest. |
| 1113 | */ |
| 1114 | if ((isMouseGrabbed || [[self window] isKeyWindow]) && |
| 1115 | (last_buttons != buttons)) { |
Eric Blake | 7fb1cf1 | 2015-11-18 01:52:57 -0700 | [diff] [blame] | 1116 | static uint32_t bmap[INPUT_BUTTON__MAX] = { |
Gerd Hoffmann | 21bae11 | 2013-12-04 14:08:04 +0100 | [diff] [blame] | 1117 | [INPUT_BUTTON_LEFT] = MOUSE_EVENT_LBUTTON, |
| 1118 | [INPUT_BUTTON_MIDDLE] = MOUSE_EVENT_MBUTTON, |
John Arbuckle | ae7313e | 2018-01-08 13:07:07 -0500 | [diff] [blame] | 1119 | [INPUT_BUTTON_RIGHT] = MOUSE_EVENT_RBUTTON |
Gerd Hoffmann | 21bae11 | 2013-12-04 14:08:04 +0100 | [diff] [blame] | 1120 | }; |
Akihiko Odaki | cc7859c | 2021-02-19 17:44:19 +0900 | [diff] [blame] | 1121 | qemu_input_update_buttons(dcl.con, bmap, last_buttons, buttons); |
Gerd Hoffmann | 21bae11 | 2013-12-04 14:08:04 +0100 | [diff] [blame] | 1122 | last_buttons = buttons; |
| 1123 | } |
Peter Maydell | f61c387 | 2014-06-23 10:35:24 +0100 | [diff] [blame] | 1124 | if (isMouseGrabbed) { |
| 1125 | if (isAbsoluteEnabled) { |
| 1126 | /* Note that the origin for Cocoa mouse coords is bottom left, not top left. |
| 1127 | * The check on screenContainsPoint is to avoid sending out of range values for |
| 1128 | * clicks in the titlebar. |
| 1129 | */ |
| 1130 | if ([self screenContainsPoint:p]) { |
Akihiko Odaki | cc7859c | 2021-02-19 17:44:19 +0900 | [diff] [blame] | 1131 | qemu_input_queue_abs(dcl.con, INPUT_AXIS_X, p.x, 0, screen.width); |
| 1132 | qemu_input_queue_abs(dcl.con, INPUT_AXIS_Y, screen.height - p.y, 0, screen.height); |
Peter Maydell | f61c387 | 2014-06-23 10:35:24 +0100 | [diff] [blame] | 1133 | } |
| 1134 | } else { |
Akihiko Odaki | cc7859c | 2021-02-19 17:44:19 +0900 | [diff] [blame] | 1135 | qemu_input_queue_rel(dcl.con, INPUT_AXIS_X, (int)[event deltaX]); |
| 1136 | qemu_input_queue_rel(dcl.con, INPUT_AXIS_Y, (int)[event deltaY]); |
Peter Maydell | f61c387 | 2014-06-23 10:35:24 +0100 | [diff] [blame] | 1137 | } |
Gerd Hoffmann | 21bae11 | 2013-12-04 14:08:04 +0100 | [diff] [blame] | 1138 | } else { |
Peter Maydell | 60105d7 | 2019-02-25 10:24:31 +0000 | [diff] [blame] | 1139 | return false; |
Gerd Hoffmann | 21bae11 | 2013-12-04 14:08:04 +0100 | [diff] [blame] | 1140 | } |
| 1141 | qemu_input_event_sync(); |
| 1142 | } |
Peter Maydell | 60105d7 | 2019-02-25 10:24:31 +0000 | [diff] [blame] | 1143 | return true; |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 1144 | } |
| 1145 | |
| 1146 | - (void) grabMouse |
| 1147 | { |
| 1148 | COCOA_DEBUG("QemuCocoaView: grabMouse\n"); |
| 1149 | |
| 1150 | if (!isFullscreen) { |
| 1151 | if (qemu_name) |
John Arbuckle | 5929e36 | 2017-11-07 10:14:14 +0000 | [diff] [blame] | 1152 | [normalWindow setTitle:[NSString stringWithFormat:@"QEMU %s - (Press ctrl + alt + g to release Mouse)", qemu_name]]; |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 1153 | else |
John Arbuckle | 5929e36 | 2017-11-07 10:14:14 +0000 | [diff] [blame] | 1154 | [normalWindow setTitle:@"QEMU - (Press ctrl + alt + g to release Mouse)"]; |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 1155 | } |
Peter Maydell | 13aefd3 | 2014-06-23 10:35:25 +0100 | [diff] [blame] | 1156 | [self hideCursor]; |
Akihiko Odaki | d192906 | 2021-02-23 00:07:14 +0900 | [diff] [blame] | 1157 | CGAssociateMouseAndMouseCursorPosition(isAbsoluteEnabled); |
Peter Maydell | 49b9bd4 | 2013-12-08 22:59:03 +0000 | [diff] [blame] | 1158 | isMouseGrabbed = TRUE; // while isMouseGrabbed = TRUE, QemuCocoaApp sends all events to [cocoaView handleEvent:] |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 1159 | } |
| 1160 | |
| 1161 | - (void) ungrabMouse |
| 1162 | { |
| 1163 | COCOA_DEBUG("QemuCocoaView: ungrabMouse\n"); |
| 1164 | |
| 1165 | if (!isFullscreen) { |
| 1166 | if (qemu_name) |
| 1167 | [normalWindow setTitle:[NSString stringWithFormat:@"QEMU %s", qemu_name]]; |
| 1168 | else |
| 1169 | [normalWindow setTitle:@"QEMU"]; |
| 1170 | } |
Peter Maydell | 13aefd3 | 2014-06-23 10:35:25 +0100 | [diff] [blame] | 1171 | [self unhideCursor]; |
Akihiko Odaki | d192906 | 2021-02-23 00:07:14 +0900 | [diff] [blame] | 1172 | CGAssociateMouseAndMouseCursorPosition(TRUE); |
Peter Maydell | 49b9bd4 | 2013-12-08 22:59:03 +0000 | [diff] [blame] | 1173 | isMouseGrabbed = FALSE; |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 1174 | } |
| 1175 | |
Akihiko Odaki | d192906 | 2021-02-23 00:07:14 +0900 | [diff] [blame] | 1176 | - (void) setAbsoluteEnabled:(BOOL)tIsAbsoluteEnabled { |
| 1177 | isAbsoluteEnabled = tIsAbsoluteEnabled; |
| 1178 | if (isMouseGrabbed) { |
| 1179 | CGAssociateMouseAndMouseCursorPosition(isAbsoluteEnabled); |
| 1180 | } |
| 1181 | } |
Peter Maydell | 49b9bd4 | 2013-12-08 22:59:03 +0000 | [diff] [blame] | 1182 | - (BOOL) isMouseGrabbed {return isMouseGrabbed;} |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 1183 | - (BOOL) isAbsoluteEnabled {return isAbsoluteEnabled;} |
| 1184 | - (float) cdx {return cdx;} |
| 1185 | - (float) cdy {return cdy;} |
| 1186 | - (QEMUScreen) gscreen {return screen;} |
John Arbuckle | 3b178b7 | 2015-09-25 23:14:00 +0100 | [diff] [blame] | 1187 | |
| 1188 | /* |
| 1189 | * Makes the target think all down keys are being released. |
| 1190 | * This prevents a stuck key problem, since we will not see |
| 1191 | * key up events for those keys after we have lost focus. |
| 1192 | */ |
| 1193 | - (void) raiseAllKeys |
| 1194 | { |
Peter Maydell | 31819e9 | 2019-02-25 10:24:27 +0000 | [diff] [blame] | 1195 | with_iothread_lock(^{ |
Akihiko Odaki | 6d73bb6 | 2021-03-10 23:46:02 +0900 | [diff] [blame] | 1196 | qkbd_state_lift_all_keys(kbd); |
Peter Maydell | 31819e9 | 2019-02-25 10:24:27 +0000 | [diff] [blame] | 1197 | }); |
John Arbuckle | 3b178b7 | 2015-09-25 23:14:00 +0100 | [diff] [blame] | 1198 | } |
bellard | 5b0753e | 2005-03-01 21:37:28 +0000 | [diff] [blame] | 1199 | @end |
| 1200 | |
| 1201 | |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 1202 | |
bellard | 5b0753e | 2005-03-01 21:37:28 +0000 | [diff] [blame] | 1203 | /* |
| 1204 | ------------------------------------------------------ |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 1205 | QemuCocoaAppController |
bellard | 5b0753e | 2005-03-01 21:37:28 +0000 | [diff] [blame] | 1206 | ------------------------------------------------------ |
| 1207 | */ |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 1208 | @interface QemuCocoaAppController : NSObject |
John Arbuckle | d9bc14f | 2015-09-25 23:13:59 +0100 | [diff] [blame] | 1209 | <NSWindowDelegate, NSApplicationDelegate> |
bellard | 5b0753e | 2005-03-01 21:37:28 +0000 | [diff] [blame] | 1210 | { |
| 1211 | } |
Programmingkid | 5d1b2ee | 2015-05-19 09:11:17 +0100 | [diff] [blame] | 1212 | - (void)doToggleFullScreen:(id)sender; |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 1213 | - (void)toggleFullScreen:(id)sender; |
| 1214 | - (void)showQEMUDoc:(id)sender; |
Programmingkid | 5d1b2ee | 2015-05-19 09:11:17 +0100 | [diff] [blame] | 1215 | - (void)zoomToFit:(id) sender; |
Programmingkid | b4c6a11 | 2015-05-19 09:11:18 +0100 | [diff] [blame] | 1216 | - (void)displayConsole:(id)sender; |
John Arbuckle | 8524f1c | 2015-06-19 10:53:27 +0100 | [diff] [blame] | 1217 | - (void)pauseQEMU:(id)sender; |
| 1218 | - (void)resumeQEMU:(id)sender; |
| 1219 | - (void)displayPause; |
| 1220 | - (void)removePause; |
John Arbuckle | 2707461 | 2015-06-19 10:53:27 +0100 | [diff] [blame] | 1221 | - (void)restartQEMU:(id)sender; |
| 1222 | - (void)powerDownQEMU:(id)sender; |
John Arbuckle | 693a3e0 | 2015-06-19 10:53:27 +0100 | [diff] [blame] | 1223 | - (void)ejectDeviceMedia:(id)sender; |
| 1224 | - (void)changeDeviceMedia:(id)sender; |
John Arbuckle | d9bc14f | 2015-09-25 23:13:59 +0100 | [diff] [blame] | 1225 | - (BOOL)verifyQuit; |
John Arbuckle | f474790 | 2016-03-23 14:26:17 +0000 | [diff] [blame] | 1226 | - (void)openDocumentation:(NSString *)filename; |
Programmingkid | 9e8204b | 2016-08-15 22:11:06 -0400 | [diff] [blame] | 1227 | - (IBAction) do_about_menu_item: (id) sender; |
John Arbuckle | e47ec1a | 2017-06-13 23:17:38 -0400 | [diff] [blame] | 1228 | - (void)adjustSpeed:(id)sender; |
bellard | 5b0753e | 2005-03-01 21:37:28 +0000 | [diff] [blame] | 1229 | @end |
| 1230 | |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 1231 | @implementation QemuCocoaAppController |
| 1232 | - (id) init |
| 1233 | { |
| 1234 | COCOA_DEBUG("QemuCocoaAppController: init\n"); |
| 1235 | |
| 1236 | self = [super init]; |
| 1237 | if (self) { |
| 1238 | |
| 1239 | // create a view and add it to the window |
| 1240 | cocoaView = [[QemuCocoaView alloc] initWithFrame:NSMakeRect(0.0, 0.0, 640.0, 480.0)]; |
| 1241 | if(!cocoaView) { |
Akihiko Odaki | 4313739 | 2021-02-23 22:11:06 +0900 | [diff] [blame] | 1242 | error_report("(cocoa) can't create a view"); |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 1243 | exit(1); |
| 1244 | } |
| 1245 | |
| 1246 | // create a window |
| 1247 | normalWindow = [[NSWindow alloc] initWithContentRect:[cocoaView frame] |
Brendan Shanks | 4ba967a | 2017-04-24 23:29:52 -0700 | [diff] [blame] | 1248 | styleMask:NSWindowStyleMaskTitled|NSWindowStyleMaskMiniaturizable|NSWindowStyleMaskClosable |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 1249 | backing:NSBackingStoreBuffered defer:NO]; |
| 1250 | if(!normalWindow) { |
Akihiko Odaki | 4313739 | 2021-02-23 22:11:06 +0900 | [diff] [blame] | 1251 | error_report("(cocoa) can't create window"); |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 1252 | exit(1); |
| 1253 | } |
| 1254 | [normalWindow setAcceptsMouseMovedEvents:YES]; |
John Arbuckle | a1dbc05 | 2015-10-13 21:51:18 +0100 | [diff] [blame] | 1255 | [normalWindow setTitle:@"QEMU"]; |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 1256 | [normalWindow setContentView:cocoaView]; |
| 1257 | [normalWindow makeKeyAndOrderFront:self]; |
Peter Maydell | 49060c2 | 2013-12-24 11:54:12 +0000 | [diff] [blame] | 1258 | [normalWindow center]; |
John Arbuckle | d9bc14f | 2015-09-25 23:13:59 +0100 | [diff] [blame] | 1259 | [normalWindow setDelegate: self]; |
Programmingkid | 5d1b2ee | 2015-05-19 09:11:17 +0100 | [diff] [blame] | 1260 | stretch_video = false; |
John Arbuckle | 8524f1c | 2015-06-19 10:53:27 +0100 | [diff] [blame] | 1261 | |
| 1262 | /* Used for displaying pause on the screen */ |
| 1263 | pauseLabel = [NSTextField new]; |
| 1264 | [pauseLabel setBezeled:YES]; |
| 1265 | [pauseLabel setDrawsBackground:YES]; |
| 1266 | [pauseLabel setBackgroundColor: [NSColor whiteColor]]; |
| 1267 | [pauseLabel setEditable:NO]; |
| 1268 | [pauseLabel setSelectable:NO]; |
| 1269 | [pauseLabel setStringValue: @"Paused"]; |
| 1270 | [pauseLabel setFont: [NSFont fontWithName: @"Helvetica" size: 90]]; |
| 1271 | [pauseLabel setTextColor: [NSColor blackColor]]; |
| 1272 | [pauseLabel sizeToFit]; |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 1273 | } |
| 1274 | return self; |
| 1275 | } |
| 1276 | |
| 1277 | - (void) dealloc |
| 1278 | { |
| 1279 | COCOA_DEBUG("QemuCocoaAppController: dealloc\n"); |
| 1280 | |
| 1281 | if (cocoaView) |
| 1282 | [cocoaView release]; |
| 1283 | [super dealloc]; |
| 1284 | } |
| 1285 | |
bellard | 5b0753e | 2005-03-01 21:37:28 +0000 | [diff] [blame] | 1286 | - (void)applicationDidFinishLaunching: (NSNotification *) note |
| 1287 | { |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 1288 | COCOA_DEBUG("QemuCocoaAppController: applicationDidFinishLaunching\n"); |
Hikaru Nishida | dff742a | 2019-10-15 10:07:34 +0900 | [diff] [blame] | 1289 | allow_events = true; |
Peter Maydell | 5588840 | 2019-02-25 10:24:33 +0000 | [diff] [blame] | 1290 | /* Tell cocoa_display_init to proceed */ |
| 1291 | qemu_sem_post(&app_started_sem); |
bellard | 5b0753e | 2005-03-01 21:37:28 +0000 | [diff] [blame] | 1292 | } |
| 1293 | |
| 1294 | - (void)applicationWillTerminate:(NSNotification *)aNotification |
| 1295 | { |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 1296 | COCOA_DEBUG("QemuCocoaAppController: applicationWillTerminate\n"); |
| 1297 | |
Akihiko Odaki | 2910abd | 2022-05-29 17:25:08 +0900 | [diff] [blame] | 1298 | with_iothread_lock(^{ |
| 1299 | shutdown_action = SHUTDOWN_ACTION_POWEROFF; |
| 1300 | qemu_system_shutdown_request(SHUTDOWN_CAUSE_HOST_UI); |
| 1301 | }); |
Akihiko Odaki | 40c0193 | 2021-02-19 20:16:52 +0900 | [diff] [blame] | 1302 | |
| 1303 | /* |
| 1304 | * Sleep here, because returning will cause OSX to kill us |
| 1305 | * immediately; the QEMU main loop will handle the shutdown |
| 1306 | * request and terminate the process. |
| 1307 | */ |
| 1308 | [NSThread sleepForTimeInterval:INFINITY]; |
bellard | 5b0753e | 2005-03-01 21:37:28 +0000 | [diff] [blame] | 1309 | } |
| 1310 | |
Andreas Färber | 41ea49b | 2009-12-14 22:13:27 +0100 | [diff] [blame] | 1311 | - (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)theApplication |
| 1312 | { |
| 1313 | return YES; |
| 1314 | } |
| 1315 | |
John Arbuckle | d9bc14f | 2015-09-25 23:13:59 +0100 | [diff] [blame] | 1316 | - (NSApplicationTerminateReply)applicationShouldTerminate: |
| 1317 | (NSApplication *)sender |
| 1318 | { |
| 1319 | COCOA_DEBUG("QemuCocoaAppController: applicationShouldTerminate\n"); |
| 1320 | return [self verifyQuit]; |
| 1321 | } |
| 1322 | |
Akihiko Odaki | 15280e8 | 2021-06-16 23:19:10 +0900 | [diff] [blame] | 1323 | - (void)windowDidChangeScreen:(NSNotification *)notification |
| 1324 | { |
| 1325 | [cocoaView updateUIInfo]; |
| 1326 | } |
| 1327 | |
| 1328 | - (void)windowDidResize:(NSNotification *)notification |
| 1329 | { |
| 1330 | [cocoaView updateUIInfo]; |
| 1331 | } |
| 1332 | |
John Arbuckle | d9bc14f | 2015-09-25 23:13:59 +0100 | [diff] [blame] | 1333 | /* Called when the user clicks on a window's close button */ |
| 1334 | - (BOOL)windowShouldClose:(id)sender |
| 1335 | { |
| 1336 | COCOA_DEBUG("QemuCocoaAppController: windowShouldClose\n"); |
| 1337 | [NSApp terminate: sender]; |
| 1338 | /* If the user allows the application to quit then the call to |
| 1339 | * NSApp terminate will never return. If we get here then the user |
| 1340 | * cancelled the quit, so we should return NO to not permit the |
| 1341 | * closing of this window. |
| 1342 | */ |
| 1343 | return NO; |
| 1344 | } |
| 1345 | |
John Arbuckle | 3b178b7 | 2015-09-25 23:14:00 +0100 | [diff] [blame] | 1346 | /* Called when QEMU goes into the background */ |
| 1347 | - (void) applicationWillResignActive: (NSNotification *)aNotification |
| 1348 | { |
| 1349 | COCOA_DEBUG("QemuCocoaAppController: applicationWillResignActive\n"); |
Carwyn Ellis | 69221df | 2022-01-02 17:41:53 +0000 | [diff] [blame] | 1350 | [cocoaView ungrabMouse]; |
John Arbuckle | 3b178b7 | 2015-09-25 23:14:00 +0100 | [diff] [blame] | 1351 | [cocoaView raiseAllKeys]; |
| 1352 | } |
| 1353 | |
Programmingkid | 5d1b2ee | 2015-05-19 09:11:17 +0100 | [diff] [blame] | 1354 | /* We abstract the method called by the Enter Fullscreen menu item |
| 1355 | * because Mac OS 10.7 and higher disables it. This is because of the |
| 1356 | * menu item's old selector's name toggleFullScreen: |
| 1357 | */ |
| 1358 | - (void) doToggleFullScreen:(id)sender |
| 1359 | { |
| 1360 | [self toggleFullScreen:(id)sender]; |
| 1361 | } |
| 1362 | |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 1363 | - (void)toggleFullScreen:(id)sender |
bellard | 5b0753e | 2005-03-01 21:37:28 +0000 | [diff] [blame] | 1364 | { |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 1365 | COCOA_DEBUG("QemuCocoaAppController: toggleFullScreen\n"); |
| 1366 | |
| 1367 | [cocoaView toggleFullScreen:sender]; |
| 1368 | } |
| 1369 | |
Gustavo Noronha Silva | f844cdb | 2022-03-06 21:11:18 +0900 | [diff] [blame] | 1370 | - (void) setFullGrab:(id)sender |
| 1371 | { |
| 1372 | COCOA_DEBUG("QemuCocoaAppController: setFullGrab\n"); |
| 1373 | |
| 1374 | [cocoaView setFullGrab:sender]; |
| 1375 | } |
| 1376 | |
John Arbuckle | f474790 | 2016-03-23 14:26:17 +0000 | [diff] [blame] | 1377 | /* Tries to find then open the specified filename */ |
| 1378 | - (void) openDocumentation: (NSString *) filename |
| 1379 | { |
| 1380 | /* Where to look for local files */ |
Roman Bolshakov | 8d6fda8 | 2021-01-09 00:38:15 +0300 | [diff] [blame] | 1381 | NSString *path_array[] = {@"../share/doc/qemu/", @"../doc/qemu/", @"docs/"}; |
John Arbuckle | f474790 | 2016-03-23 14:26:17 +0000 | [diff] [blame] | 1382 | NSString *full_file_path; |
Roman Bolshakov | 1ff5a06 | 2021-01-02 18:07:21 +0300 | [diff] [blame] | 1383 | NSURL *full_file_url; |
John Arbuckle | f474790 | 2016-03-23 14:26:17 +0000 | [diff] [blame] | 1384 | |
| 1385 | /* iterate thru the possible paths until the file is found */ |
| 1386 | int index; |
| 1387 | for (index = 0; index < ARRAY_SIZE(path_array); index++) { |
| 1388 | full_file_path = [[NSBundle mainBundle] executablePath]; |
| 1389 | full_file_path = [full_file_path stringByDeletingLastPathComponent]; |
| 1390 | full_file_path = [NSString stringWithFormat: @"%@/%@%@", full_file_path, |
| 1391 | path_array[index], filename]; |
Roman Bolshakov | 1ff5a06 | 2021-01-02 18:07:21 +0300 | [diff] [blame] | 1392 | full_file_url = [NSURL fileURLWithPath: full_file_path |
| 1393 | isDirectory: false]; |
| 1394 | if ([[NSWorkspace sharedWorkspace] openURL: full_file_url] == YES) { |
John Arbuckle | f474790 | 2016-03-23 14:26:17 +0000 | [diff] [blame] | 1395 | return; |
| 1396 | } |
| 1397 | } |
| 1398 | |
| 1399 | /* If none of the paths opened a file */ |
| 1400 | NSBeep(); |
| 1401 | QEMU_Alert(@"Failed to open file"); |
| 1402 | } |
| 1403 | |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 1404 | - (void)showQEMUDoc:(id)sender |
| 1405 | { |
| 1406 | COCOA_DEBUG("QemuCocoaAppController: showQEMUDoc\n"); |
| 1407 | |
Peter Maydell | 1879f24 | 2020-02-28 15:36:16 +0000 | [diff] [blame] | 1408 | [self openDocumentation: @"index.html"]; |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 1409 | } |
| 1410 | |
Programmingkid | 5d1b2ee | 2015-05-19 09:11:17 +0100 | [diff] [blame] | 1411 | /* Stretches video to fit host monitor size */ |
| 1412 | - (void)zoomToFit:(id) sender |
| 1413 | { |
| 1414 | stretch_video = !stretch_video; |
| 1415 | if (stretch_video == true) { |
Brendan Shanks | 5e24600 | 2019-01-31 23:12:25 -0800 | [diff] [blame] | 1416 | [sender setState: NSControlStateValueOn]; |
Programmingkid | 5d1b2ee | 2015-05-19 09:11:17 +0100 | [diff] [blame] | 1417 | } else { |
Brendan Shanks | 5e24600 | 2019-01-31 23:12:25 -0800 | [diff] [blame] | 1418 | [sender setState: NSControlStateValueOff]; |
Programmingkid | 5d1b2ee | 2015-05-19 09:11:17 +0100 | [diff] [blame] | 1419 | } |
| 1420 | } |
bellard | 5b0753e | 2005-03-01 21:37:28 +0000 | [diff] [blame] | 1421 | |
Programmingkid | b4c6a11 | 2015-05-19 09:11:18 +0100 | [diff] [blame] | 1422 | /* Displays the console on the screen */ |
| 1423 | - (void)displayConsole:(id)sender |
| 1424 | { |
| 1425 | console_select([sender tag]); |
| 1426 | } |
John Arbuckle | 8524f1c | 2015-06-19 10:53:27 +0100 | [diff] [blame] | 1427 | |
| 1428 | /* Pause the guest */ |
| 1429 | - (void)pauseQEMU:(id)sender |
| 1430 | { |
Peter Maydell | 31819e9 | 2019-02-25 10:24:27 +0000 | [diff] [blame] | 1431 | with_iothread_lock(^{ |
| 1432 | qmp_stop(NULL); |
| 1433 | }); |
John Arbuckle | 8524f1c | 2015-06-19 10:53:27 +0100 | [diff] [blame] | 1434 | [sender setEnabled: NO]; |
| 1435 | [[[sender menu] itemWithTitle: @"Resume"] setEnabled: YES]; |
| 1436 | [self displayPause]; |
| 1437 | } |
| 1438 | |
| 1439 | /* Resume running the guest operating system */ |
| 1440 | - (void)resumeQEMU:(id) sender |
| 1441 | { |
Peter Maydell | 31819e9 | 2019-02-25 10:24:27 +0000 | [diff] [blame] | 1442 | with_iothread_lock(^{ |
| 1443 | qmp_cont(NULL); |
| 1444 | }); |
John Arbuckle | 8524f1c | 2015-06-19 10:53:27 +0100 | [diff] [blame] | 1445 | [sender setEnabled: NO]; |
| 1446 | [[[sender menu] itemWithTitle: @"Pause"] setEnabled: YES]; |
| 1447 | [self removePause]; |
| 1448 | } |
| 1449 | |
| 1450 | /* Displays the word pause on the screen */ |
| 1451 | - (void)displayPause |
| 1452 | { |
| 1453 | /* Coordinates have to be calculated each time because the window can change its size */ |
| 1454 | int xCoord, yCoord, width, height; |
| 1455 | xCoord = ([normalWindow frame].size.width - [pauseLabel frame].size.width)/2; |
| 1456 | yCoord = [normalWindow frame].size.height - [pauseLabel frame].size.height - ([pauseLabel frame].size.height * .5); |
| 1457 | width = [pauseLabel frame].size.width; |
| 1458 | height = [pauseLabel frame].size.height; |
| 1459 | [pauseLabel setFrame: NSMakeRect(xCoord, yCoord, width, height)]; |
| 1460 | [cocoaView addSubview: pauseLabel]; |
| 1461 | } |
| 1462 | |
| 1463 | /* Removes the word pause from the screen */ |
| 1464 | - (void)removePause |
| 1465 | { |
| 1466 | [pauseLabel removeFromSuperview]; |
| 1467 | } |
| 1468 | |
John Arbuckle | 2707461 | 2015-06-19 10:53:27 +0100 | [diff] [blame] | 1469 | /* Restarts QEMU */ |
| 1470 | - (void)restartQEMU:(id)sender |
| 1471 | { |
Peter Maydell | 31819e9 | 2019-02-25 10:24:27 +0000 | [diff] [blame] | 1472 | with_iothread_lock(^{ |
| 1473 | qmp_system_reset(NULL); |
| 1474 | }); |
John Arbuckle | 2707461 | 2015-06-19 10:53:27 +0100 | [diff] [blame] | 1475 | } |
| 1476 | |
| 1477 | /* Powers down QEMU */ |
| 1478 | - (void)powerDownQEMU:(id)sender |
| 1479 | { |
Peter Maydell | 31819e9 | 2019-02-25 10:24:27 +0000 | [diff] [blame] | 1480 | with_iothread_lock(^{ |
| 1481 | qmp_system_powerdown(NULL); |
| 1482 | }); |
John Arbuckle | 2707461 | 2015-06-19 10:53:27 +0100 | [diff] [blame] | 1483 | } |
| 1484 | |
John Arbuckle | 693a3e0 | 2015-06-19 10:53:27 +0100 | [diff] [blame] | 1485 | /* Ejects the media. |
| 1486 | * Uses sender's tag to figure out the device to eject. |
| 1487 | */ |
| 1488 | - (void)ejectDeviceMedia:(id)sender |
| 1489 | { |
| 1490 | NSString * drive; |
| 1491 | drive = [sender representedObject]; |
| 1492 | if(drive == nil) { |
| 1493 | NSBeep(); |
| 1494 | QEMU_Alert(@"Failed to find drive to eject!"); |
| 1495 | return; |
| 1496 | } |
| 1497 | |
Peter Maydell | 31819e9 | 2019-02-25 10:24:27 +0000 | [diff] [blame] | 1498 | __block Error *err = NULL; |
| 1499 | with_iothread_lock(^{ |
| 1500 | qmp_eject(true, [drive cStringUsingEncoding: NSASCIIStringEncoding], |
| 1501 | false, NULL, false, false, &err); |
| 1502 | }); |
John Arbuckle | 693a3e0 | 2015-06-19 10:53:27 +0100 | [diff] [blame] | 1503 | handleAnyDeviceErrors(err); |
| 1504 | } |
| 1505 | |
| 1506 | /* Displays a dialog box asking the user to select an image file to load. |
| 1507 | * Uses sender's represented object value to figure out which drive to use. |
| 1508 | */ |
| 1509 | - (void)changeDeviceMedia:(id)sender |
| 1510 | { |
| 1511 | /* Find the drive name */ |
| 1512 | NSString * drive; |
| 1513 | drive = [sender representedObject]; |
| 1514 | if(drive == nil) { |
| 1515 | NSBeep(); |
| 1516 | QEMU_Alert(@"Could not find drive!"); |
| 1517 | return; |
| 1518 | } |
| 1519 | |
| 1520 | /* Display the file open dialog */ |
| 1521 | NSOpenPanel * openPanel; |
| 1522 | openPanel = [NSOpenPanel openPanel]; |
| 1523 | [openPanel setCanChooseFiles: YES]; |
| 1524 | [openPanel setAllowsMultipleSelection: NO]; |
Peter Maydell | b572538 | 2018-05-29 19:15:23 +0100 | [diff] [blame] | 1525 | if([openPanel runModal] == NSModalResponseOK) { |
John Arbuckle | 693a3e0 | 2015-06-19 10:53:27 +0100 | [diff] [blame] | 1526 | NSString * file = [[[openPanel URLs] objectAtIndex: 0] path]; |
| 1527 | if(file == nil) { |
| 1528 | NSBeep(); |
| 1529 | QEMU_Alert(@"Failed to convert URL to file path!"); |
| 1530 | return; |
| 1531 | } |
| 1532 | |
Peter Maydell | 31819e9 | 2019-02-25 10:24:27 +0000 | [diff] [blame] | 1533 | __block Error *err = NULL; |
| 1534 | with_iothread_lock(^{ |
| 1535 | qmp_blockdev_change_medium(true, |
| 1536 | [drive cStringUsingEncoding: |
| 1537 | NSASCIIStringEncoding], |
| 1538 | false, NULL, |
| 1539 | [file cStringUsingEncoding: |
| 1540 | NSASCIIStringEncoding], |
| 1541 | true, "raw", |
Denis V. Lunev | 80dd5af | 2022-04-13 01:18:46 +0300 | [diff] [blame] | 1542 | true, false, |
Peter Maydell | 31819e9 | 2019-02-25 10:24:27 +0000 | [diff] [blame] | 1543 | false, 0, |
| 1544 | &err); |
| 1545 | }); |
John Arbuckle | 693a3e0 | 2015-06-19 10:53:27 +0100 | [diff] [blame] | 1546 | handleAnyDeviceErrors(err); |
| 1547 | } |
| 1548 | } |
| 1549 | |
John Arbuckle | d9bc14f | 2015-09-25 23:13:59 +0100 | [diff] [blame] | 1550 | /* Verifies if the user really wants to quit */ |
| 1551 | - (BOOL)verifyQuit |
| 1552 | { |
| 1553 | NSAlert *alert = [NSAlert new]; |
| 1554 | [alert autorelease]; |
| 1555 | [alert setMessageText: @"Are you sure you want to quit QEMU?"]; |
| 1556 | [alert addButtonWithTitle: @"Cancel"]; |
| 1557 | [alert addButtonWithTitle: @"Quit"]; |
| 1558 | if([alert runModal] == NSAlertSecondButtonReturn) { |
| 1559 | return YES; |
| 1560 | } else { |
| 1561 | return NO; |
| 1562 | } |
| 1563 | } |
| 1564 | |
Programmingkid | 9e8204b | 2016-08-15 22:11:06 -0400 | [diff] [blame] | 1565 | /* The action method for the About menu item */ |
| 1566 | - (IBAction) do_about_menu_item: (id) sender |
| 1567 | { |
Akihiko Odaki | 99eb313 | 2022-02-27 13:22:41 +0900 | [diff] [blame] | 1568 | NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
| 1569 | char *icon_path_c = get_relocated_path(CONFIG_QEMU_ICONDIR "/hicolor/512x512/apps/qemu.png"); |
| 1570 | NSString *icon_path = [NSString stringWithUTF8String:icon_path_c]; |
| 1571 | g_free(icon_path_c); |
| 1572 | NSImage *icon = [[NSImage alloc] initWithContentsOfFile:icon_path]; |
| 1573 | NSString *version = @"QEMU emulator version " QEMU_FULL_VERSION; |
| 1574 | NSString *copyright = @QEMU_COPYRIGHT; |
| 1575 | NSDictionary *options; |
| 1576 | if (icon) { |
| 1577 | options = @{ |
| 1578 | NSAboutPanelOptionApplicationIcon : icon, |
| 1579 | NSAboutPanelOptionApplicationVersion : version, |
| 1580 | @"Copyright" : copyright, |
| 1581 | }; |
| 1582 | [icon release]; |
| 1583 | } else { |
| 1584 | options = @{ |
| 1585 | NSAboutPanelOptionApplicationVersion : version, |
| 1586 | @"Copyright" : copyright, |
| 1587 | }; |
Akihiko Odaki | a0f973f | 2021-03-09 21:22:26 +0900 | [diff] [blame] | 1588 | } |
Akihiko Odaki | 99eb313 | 2022-02-27 13:22:41 +0900 | [diff] [blame] | 1589 | [NSApp orderFrontStandardAboutPanelWithOptions:options]; |
| 1590 | [pool release]; |
Programmingkid | 9e8204b | 2016-08-15 22:11:06 -0400 | [diff] [blame] | 1591 | } |
| 1592 | |
John Arbuckle | e47ec1a | 2017-06-13 23:17:38 -0400 | [diff] [blame] | 1593 | /* Used by the Speed menu items */ |
| 1594 | - (void)adjustSpeed:(id)sender |
| 1595 | { |
| 1596 | int throttle_pct; /* throttle percentage */ |
| 1597 | NSMenu *menu; |
| 1598 | |
| 1599 | menu = [sender menu]; |
| 1600 | if (menu != nil) |
| 1601 | { |
| 1602 | /* Unselect the currently selected item */ |
| 1603 | for (NSMenuItem *item in [menu itemArray]) { |
Brendan Shanks | 5e24600 | 2019-01-31 23:12:25 -0800 | [diff] [blame] | 1604 | if (item.state == NSControlStateValueOn) { |
| 1605 | [item setState: NSControlStateValueOff]; |
John Arbuckle | e47ec1a | 2017-06-13 23:17:38 -0400 | [diff] [blame] | 1606 | break; |
| 1607 | } |
| 1608 | } |
| 1609 | } |
| 1610 | |
| 1611 | // check the menu item |
Brendan Shanks | 5e24600 | 2019-01-31 23:12:25 -0800 | [diff] [blame] | 1612 | [sender setState: NSControlStateValueOn]; |
John Arbuckle | e47ec1a | 2017-06-13 23:17:38 -0400 | [diff] [blame] | 1613 | |
| 1614 | // get the throttle percentage |
| 1615 | throttle_pct = [sender tag]; |
| 1616 | |
Peter Maydell | 31819e9 | 2019-02-25 10:24:27 +0000 | [diff] [blame] | 1617 | with_iothread_lock(^{ |
| 1618 | cpu_throttle_set(throttle_pct); |
| 1619 | }); |
John Arbuckle | e47ec1a | 2017-06-13 23:17:38 -0400 | [diff] [blame] | 1620 | COCOA_DEBUG("cpu throttling at %d%c\n", cpu_throttle_get_percentage(), '%'); |
| 1621 | } |
| 1622 | |
Programmingkid | b4c6a11 | 2015-05-19 09:11:18 +0100 | [diff] [blame] | 1623 | @end |
bellard | 5b0753e | 2005-03-01 21:37:28 +0000 | [diff] [blame] | 1624 | |
Peter Maydell | 61a2ed4 | 2019-02-25 10:24:32 +0000 | [diff] [blame] | 1625 | @interface QemuApplication : NSApplication |
| 1626 | @end |
| 1627 | |
| 1628 | @implementation QemuApplication |
| 1629 | - (void)sendEvent:(NSEvent *)event |
| 1630 | { |
| 1631 | COCOA_DEBUG("QemuApplication: sendEvent\n"); |
Peter Maydell | 5588840 | 2019-02-25 10:24:33 +0000 | [diff] [blame] | 1632 | if (![cocoaView handleEvent:event]) { |
| 1633 | [super sendEvent: event]; |
| 1634 | } |
Peter Maydell | 61a2ed4 | 2019-02-25 10:24:32 +0000 | [diff] [blame] | 1635 | } |
| 1636 | @end |
| 1637 | |
Peter Maydell | c6fd6c7 | 2019-02-25 10:24:29 +0000 | [diff] [blame] | 1638 | static void create_initial_menus(void) |
| 1639 | { |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 1640 | // Add menus |
| 1641 | NSMenu *menu; |
| 1642 | NSMenuItem *menuItem; |
| 1643 | |
bellard | 5b0753e | 2005-03-01 21:37:28 +0000 | [diff] [blame] | 1644 | [NSApp setMainMenu:[[NSMenu alloc] init]]; |
Akihiko Odaki | 5b6988c | 2022-02-14 18:13:20 +0900 | [diff] [blame] | 1645 | [NSApp setServicesMenu:[[NSMenu alloc] initWithTitle:@"Services"]]; |
bellard | 5b0753e | 2005-03-01 21:37:28 +0000 | [diff] [blame] | 1646 | |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 1647 | // Application menu |
| 1648 | menu = [[NSMenu alloc] initWithTitle:@""]; |
Programmingkid | 9e8204b | 2016-08-15 22:11:06 -0400 | [diff] [blame] | 1649 | [menu addItemWithTitle:@"About QEMU" action:@selector(do_about_menu_item:) keyEquivalent:@""]; // About QEMU |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 1650 | [menu addItem:[NSMenuItem separatorItem]]; //Separator |
Akihiko Odaki | 5b6988c | 2022-02-14 18:13:20 +0900 | [diff] [blame] | 1651 | menuItem = [menu addItemWithTitle:@"Services" action:nil keyEquivalent:@""]; |
| 1652 | [menuItem setSubmenu:[NSApp servicesMenu]]; |
| 1653 | [menu addItem:[NSMenuItem separatorItem]]; |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 1654 | [menu addItemWithTitle:@"Hide QEMU" action:@selector(hide:) keyEquivalent:@"h"]; //Hide QEMU |
| 1655 | menuItem = (NSMenuItem *)[menu addItemWithTitle:@"Hide Others" action:@selector(hideOtherApplications:) keyEquivalent:@"h"]; // Hide Others |
Brendan Shanks | 4ba967a | 2017-04-24 23:29:52 -0700 | [diff] [blame] | 1656 | [menuItem setKeyEquivalentModifierMask:(NSEventModifierFlagOption|NSEventModifierFlagCommand)]; |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 1657 | [menu addItemWithTitle:@"Show All" action:@selector(unhideAllApplications:) keyEquivalent:@""]; // Show All |
| 1658 | [menu addItem:[NSMenuItem separatorItem]]; //Separator |
| 1659 | [menu addItemWithTitle:@"Quit QEMU" action:@selector(terminate:) keyEquivalent:@"q"]; |
| 1660 | menuItem = [[NSMenuItem alloc] initWithTitle:@"Apple" action:nil keyEquivalent:@""]; |
| 1661 | [menuItem setSubmenu:menu]; |
| 1662 | [[NSApp mainMenu] addItem:menuItem]; |
| 1663 | [NSApp performSelector:@selector(setAppleMenu:) withObject:menu]; // Workaround (this method is private since 10.4+) |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 1664 | |
John Arbuckle | 8524f1c | 2015-06-19 10:53:27 +0100 | [diff] [blame] | 1665 | // Machine menu |
| 1666 | menu = [[NSMenu alloc] initWithTitle: @"Machine"]; |
| 1667 | [menu setAutoenablesItems: NO]; |
| 1668 | [menu addItem: [[[NSMenuItem alloc] initWithTitle: @"Pause" action: @selector(pauseQEMU:) keyEquivalent: @""] autorelease]]; |
| 1669 | menuItem = [[[NSMenuItem alloc] initWithTitle: @"Resume" action: @selector(resumeQEMU:) keyEquivalent: @""] autorelease]; |
| 1670 | [menu addItem: menuItem]; |
| 1671 | [menuItem setEnabled: NO]; |
John Arbuckle | 2707461 | 2015-06-19 10:53:27 +0100 | [diff] [blame] | 1672 | [menu addItem: [NSMenuItem separatorItem]]; |
| 1673 | [menu addItem: [[[NSMenuItem alloc] initWithTitle: @"Reset" action: @selector(restartQEMU:) keyEquivalent: @""] autorelease]]; |
| 1674 | [menu addItem: [[[NSMenuItem alloc] initWithTitle: @"Power Down" action: @selector(powerDownQEMU:) keyEquivalent: @""] autorelease]]; |
John Arbuckle | 8524f1c | 2015-06-19 10:53:27 +0100 | [diff] [blame] | 1675 | menuItem = [[[NSMenuItem alloc] initWithTitle: @"Machine" action:nil keyEquivalent:@""] autorelease]; |
| 1676 | [menuItem setSubmenu:menu]; |
| 1677 | [[NSApp mainMenu] addItem:menuItem]; |
| 1678 | |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 1679 | // View menu |
| 1680 | menu = [[NSMenu alloc] initWithTitle:@"View"]; |
Programmingkid | 5d1b2ee | 2015-05-19 09:11:17 +0100 | [diff] [blame] | 1681 | [menu addItem: [[[NSMenuItem alloc] initWithTitle:@"Enter Fullscreen" action:@selector(doToggleFullScreen:) keyEquivalent:@"f"] autorelease]]; // Fullscreen |
| 1682 | [menu addItem: [[[NSMenuItem alloc] initWithTitle:@"Zoom To Fit" action:@selector(zoomToFit:) keyEquivalent:@""] autorelease]]; |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 1683 | menuItem = [[[NSMenuItem alloc] initWithTitle:@"View" action:nil keyEquivalent:@""] autorelease]; |
| 1684 | [menuItem setSubmenu:menu]; |
| 1685 | [[NSApp mainMenu] addItem:menuItem]; |
| 1686 | |
John Arbuckle | e47ec1a | 2017-06-13 23:17:38 -0400 | [diff] [blame] | 1687 | // Speed menu |
| 1688 | menu = [[NSMenu alloc] initWithTitle:@"Speed"]; |
| 1689 | |
| 1690 | // Add the rest of the Speed menu items |
| 1691 | int p, percentage, throttle_pct; |
| 1692 | for (p = 10; p >= 0; p--) |
| 1693 | { |
| 1694 | percentage = p * 10 > 1 ? p * 10 : 1; // prevent a 0% menu item |
| 1695 | |
| 1696 | menuItem = [[[NSMenuItem alloc] |
| 1697 | initWithTitle: [NSString stringWithFormat: @"%d%%", percentage] action:@selector(adjustSpeed:) keyEquivalent:@""] autorelease]; |
| 1698 | |
| 1699 | if (percentage == 100) { |
Brendan Shanks | 5e24600 | 2019-01-31 23:12:25 -0800 | [diff] [blame] | 1700 | [menuItem setState: NSControlStateValueOn]; |
John Arbuckle | e47ec1a | 2017-06-13 23:17:38 -0400 | [diff] [blame] | 1701 | } |
| 1702 | |
| 1703 | /* Calculate the throttle percentage */ |
| 1704 | throttle_pct = -1 * percentage + 100; |
| 1705 | |
| 1706 | [menuItem setTag: throttle_pct]; |
| 1707 | [menu addItem: menuItem]; |
| 1708 | } |
| 1709 | menuItem = [[[NSMenuItem alloc] initWithTitle:@"Speed" action:nil keyEquivalent:@""] autorelease]; |
| 1710 | [menuItem setSubmenu:menu]; |
| 1711 | [[NSApp mainMenu] addItem:menuItem]; |
| 1712 | |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 1713 | // Window menu |
| 1714 | menu = [[NSMenu alloc] initWithTitle:@"Window"]; |
| 1715 | [menu addItem: [[[NSMenuItem alloc] initWithTitle:@"Minimize" action:@selector(performMiniaturize:) keyEquivalent:@"m"] autorelease]]; // Miniaturize |
| 1716 | menuItem = [[[NSMenuItem alloc] initWithTitle:@"Window" action:nil keyEquivalent:@""] autorelease]; |
| 1717 | [menuItem setSubmenu:menu]; |
| 1718 | [[NSApp mainMenu] addItem:menuItem]; |
| 1719 | [NSApp setWindowsMenu:menu]; |
| 1720 | |
| 1721 | // Help menu |
| 1722 | menu = [[NSMenu alloc] initWithTitle:@"Help"]; |
| 1723 | [menu addItem: [[[NSMenuItem alloc] initWithTitle:@"QEMU Documentation" action:@selector(showQEMUDoc:) keyEquivalent:@"?"] autorelease]]; // QEMU Help |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 1724 | menuItem = [[[NSMenuItem alloc] initWithTitle:@"Window" action:nil keyEquivalent:@""] autorelease]; |
| 1725 | [menuItem setSubmenu:menu]; |
| 1726 | [[NSApp mainMenu] addItem:menuItem]; |
Peter Maydell | c6fd6c7 | 2019-02-25 10:24:29 +0000 | [diff] [blame] | 1727 | } |
| 1728 | |
Peter Maydell | 8b00e4e | 2019-02-25 10:24:30 +0000 | [diff] [blame] | 1729 | /* Returns a name for a given console */ |
| 1730 | static NSString * getConsoleName(QemuConsole * console) |
| 1731 | { |
Akihiko Odaki | ca51160 | 2022-02-15 09:03:05 +0100 | [diff] [blame] | 1732 | g_autofree char *label = qemu_console_get_label(console); |
| 1733 | |
| 1734 | return [NSString stringWithUTF8String:label]; |
Peter Maydell | 8b00e4e | 2019-02-25 10:24:30 +0000 | [diff] [blame] | 1735 | } |
| 1736 | |
| 1737 | /* Add an entry to the View menu for each console */ |
| 1738 | static void add_console_menu_entries(void) |
| 1739 | { |
| 1740 | NSMenu *menu; |
| 1741 | NSMenuItem *menuItem; |
| 1742 | int index = 0; |
| 1743 | |
| 1744 | menu = [[[NSApp mainMenu] itemWithTitle:@"View"] submenu]; |
| 1745 | |
| 1746 | [menu addItem:[NSMenuItem separatorItem]]; |
| 1747 | |
| 1748 | while (qemu_console_lookup_by_index(index) != NULL) { |
| 1749 | menuItem = [[[NSMenuItem alloc] initWithTitle: getConsoleName(qemu_console_lookup_by_index(index)) |
| 1750 | action: @selector(displayConsole:) keyEquivalent: @""] autorelease]; |
| 1751 | [menuItem setTag: index]; |
| 1752 | [menu addItem: menuItem]; |
| 1753 | index++; |
| 1754 | } |
| 1755 | } |
| 1756 | |
| 1757 | /* Make menu items for all removable devices. |
| 1758 | * Each device is given an 'Eject' and 'Change' menu item. |
| 1759 | */ |
| 1760 | static void addRemovableDevicesMenuItems(void) |
| 1761 | { |
| 1762 | NSMenu *menu; |
| 1763 | NSMenuItem *menuItem; |
| 1764 | BlockInfoList *currentDevice, *pointerToFree; |
| 1765 | NSString *deviceName; |
| 1766 | |
| 1767 | currentDevice = qmp_query_block(NULL); |
| 1768 | pointerToFree = currentDevice; |
Peter Maydell | 8b00e4e | 2019-02-25 10:24:30 +0000 | [diff] [blame] | 1769 | |
| 1770 | menu = [[[NSApp mainMenu] itemWithTitle:@"Machine"] submenu]; |
| 1771 | |
| 1772 | // Add a separator between related groups of menu items |
| 1773 | [menu addItem:[NSMenuItem separatorItem]]; |
| 1774 | |
| 1775 | // Set the attributes to the "Removable Media" menu item |
| 1776 | NSString *titleString = @"Removable Media"; |
| 1777 | NSMutableAttributedString *attString=[[NSMutableAttributedString alloc] initWithString:titleString]; |
| 1778 | NSColor *newColor = [NSColor blackColor]; |
| 1779 | NSFontManager *fontManager = [NSFontManager sharedFontManager]; |
| 1780 | NSFont *font = [fontManager fontWithFamily:@"Helvetica" |
| 1781 | traits:NSBoldFontMask|NSItalicFontMask |
| 1782 | weight:0 |
| 1783 | size:14]; |
| 1784 | [attString addAttribute:NSFontAttributeName value:font range:NSMakeRange(0, [titleString length])]; |
| 1785 | [attString addAttribute:NSForegroundColorAttributeName value:newColor range:NSMakeRange(0, [titleString length])]; |
| 1786 | [attString addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInt: 1] range:NSMakeRange(0, [titleString length])]; |
| 1787 | |
| 1788 | // Add the "Removable Media" menu item |
| 1789 | menuItem = [NSMenuItem new]; |
| 1790 | [menuItem setAttributedTitle: attString]; |
| 1791 | [menuItem setEnabled: NO]; |
| 1792 | [menu addItem: menuItem]; |
| 1793 | |
| 1794 | /* Loop through all the block devices in the emulator */ |
| 1795 | while (currentDevice) { |
| 1796 | deviceName = [[NSString stringWithFormat: @"%s", currentDevice->value->device] retain]; |
| 1797 | |
| 1798 | if(currentDevice->value->removable) { |
| 1799 | menuItem = [[NSMenuItem alloc] initWithTitle: [NSString stringWithFormat: @"Change %s...", currentDevice->value->device] |
| 1800 | action: @selector(changeDeviceMedia:) |
| 1801 | keyEquivalent: @""]; |
| 1802 | [menu addItem: menuItem]; |
| 1803 | [menuItem setRepresentedObject: deviceName]; |
| 1804 | [menuItem autorelease]; |
| 1805 | |
| 1806 | menuItem = [[NSMenuItem alloc] initWithTitle: [NSString stringWithFormat: @"Eject %s", currentDevice->value->device] |
| 1807 | action: @selector(ejectDeviceMedia:) |
| 1808 | keyEquivalent: @""]; |
| 1809 | [menu addItem: menuItem]; |
| 1810 | [menuItem setRepresentedObject: deviceName]; |
| 1811 | [menuItem autorelease]; |
| 1812 | } |
| 1813 | currentDevice = currentDevice->next; |
| 1814 | } |
| 1815 | qapi_free_BlockInfoList(pointerToFree); |
| 1816 | } |
| 1817 | |
Akihiko Odaki | 7e3e20d | 2021-06-16 23:19:54 +0900 | [diff] [blame] | 1818 | @interface QemuCocoaPasteboardTypeOwner : NSObject<NSPasteboardTypeOwner> |
| 1819 | @end |
| 1820 | |
| 1821 | @implementation QemuCocoaPasteboardTypeOwner |
| 1822 | |
| 1823 | - (void)pasteboard:(NSPasteboard *)sender provideDataForType:(NSPasteboardType)type |
| 1824 | { |
| 1825 | if (type != NSPasteboardTypeString) { |
| 1826 | return; |
| 1827 | } |
| 1828 | |
| 1829 | with_iothread_lock(^{ |
| 1830 | QemuClipboardInfo *info = qemu_clipboard_info_ref(cbinfo); |
| 1831 | qemu_event_reset(&cbevent); |
| 1832 | qemu_clipboard_request(info, QEMU_CLIPBOARD_TYPE_TEXT); |
| 1833 | |
| 1834 | while (info == cbinfo && |
| 1835 | info->types[QEMU_CLIPBOARD_TYPE_TEXT].available && |
| 1836 | info->types[QEMU_CLIPBOARD_TYPE_TEXT].data == NULL) { |
| 1837 | qemu_mutex_unlock_iothread(); |
| 1838 | qemu_event_wait(&cbevent); |
| 1839 | qemu_mutex_lock_iothread(); |
| 1840 | } |
| 1841 | |
| 1842 | if (info == cbinfo) { |
| 1843 | NSData *data = [[NSData alloc] initWithBytes:info->types[QEMU_CLIPBOARD_TYPE_TEXT].data |
| 1844 | length:info->types[QEMU_CLIPBOARD_TYPE_TEXT].size]; |
| 1845 | [sender setData:data forType:NSPasteboardTypeString]; |
| 1846 | [data release]; |
| 1847 | } |
| 1848 | |
| 1849 | qemu_clipboard_info_unref(info); |
| 1850 | }); |
| 1851 | } |
| 1852 | |
| 1853 | @end |
| 1854 | |
| 1855 | static QemuCocoaPasteboardTypeOwner *cbowner; |
| 1856 | |
| 1857 | static void cocoa_clipboard_notify(Notifier *notifier, void *data); |
| 1858 | static void cocoa_clipboard_request(QemuClipboardInfo *info, |
| 1859 | QemuClipboardType type); |
| 1860 | |
| 1861 | static QemuClipboardPeer cbpeer = { |
| 1862 | .name = "cocoa", |
Marc-André Lureau | 1b17f1e | 2021-07-19 19:42:15 +0400 | [diff] [blame] | 1863 | .notifier = { .notify = cocoa_clipboard_notify }, |
Akihiko Odaki | 7e3e20d | 2021-06-16 23:19:54 +0900 | [diff] [blame] | 1864 | .request = cocoa_clipboard_request |
| 1865 | }; |
| 1866 | |
Marc-André Lureau | 1b17f1e | 2021-07-19 19:42:15 +0400 | [diff] [blame] | 1867 | static void cocoa_clipboard_update_info(QemuClipboardInfo *info) |
Akihiko Odaki | 7e3e20d | 2021-06-16 23:19:54 +0900 | [diff] [blame] | 1868 | { |
Akihiko Odaki | 7e3e20d | 2021-06-16 23:19:54 +0900 | [diff] [blame] | 1869 | if (info->owner == &cbpeer || info->selection != QEMU_CLIPBOARD_SELECTION_CLIPBOARD) { |
| 1870 | return; |
| 1871 | } |
| 1872 | |
| 1873 | if (info != cbinfo) { |
| 1874 | NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; |
| 1875 | qemu_clipboard_info_unref(cbinfo); |
| 1876 | cbinfo = qemu_clipboard_info_ref(info); |
| 1877 | cbchangecount = [[NSPasteboard generalPasteboard] declareTypes:@[NSPasteboardTypeString] owner:cbowner]; |
| 1878 | [pool release]; |
| 1879 | } |
| 1880 | |
| 1881 | qemu_event_set(&cbevent); |
| 1882 | } |
| 1883 | |
Marc-André Lureau | 1b17f1e | 2021-07-19 19:42:15 +0400 | [diff] [blame] | 1884 | static void cocoa_clipboard_notify(Notifier *notifier, void *data) |
| 1885 | { |
| 1886 | QemuClipboardNotify *notify = data; |
| 1887 | |
| 1888 | switch (notify->type) { |
| 1889 | case QEMU_CLIPBOARD_UPDATE_INFO: |
| 1890 | cocoa_clipboard_update_info(notify->info); |
| 1891 | return; |
Marc-André Lureau | 505dbf9 | 2021-07-19 19:49:56 +0400 | [diff] [blame] | 1892 | case QEMU_CLIPBOARD_RESET_SERIAL: |
| 1893 | /* ignore */ |
| 1894 | return; |
Marc-André Lureau | 1b17f1e | 2021-07-19 19:42:15 +0400 | [diff] [blame] | 1895 | } |
| 1896 | } |
| 1897 | |
Akihiko Odaki | 7e3e20d | 2021-06-16 23:19:54 +0900 | [diff] [blame] | 1898 | static void cocoa_clipboard_request(QemuClipboardInfo *info, |
| 1899 | QemuClipboardType type) |
| 1900 | { |
Akihiko Odaki | 8c0d802 | 2022-06-15 06:21:31 +0900 | [diff] [blame] | 1901 | NSAutoreleasePool *pool; |
Akihiko Odaki | 7e3e20d | 2021-06-16 23:19:54 +0900 | [diff] [blame] | 1902 | NSData *text; |
| 1903 | |
| 1904 | switch (type) { |
| 1905 | case QEMU_CLIPBOARD_TYPE_TEXT: |
Akihiko Odaki | 8c0d802 | 2022-06-15 06:21:31 +0900 | [diff] [blame] | 1906 | pool = [[NSAutoreleasePool alloc] init]; |
Akihiko Odaki | 7e3e20d | 2021-06-16 23:19:54 +0900 | [diff] [blame] | 1907 | text = [[NSPasteboard generalPasteboard] dataForType:NSPasteboardTypeString]; |
| 1908 | if (text) { |
| 1909 | qemu_clipboard_set_data(&cbpeer, info, type, |
| 1910 | [text length], [text bytes], true); |
Akihiko Odaki | 7e3e20d | 2021-06-16 23:19:54 +0900 | [diff] [blame] | 1911 | } |
Akihiko Odaki | 8c0d802 | 2022-06-15 06:21:31 +0900 | [diff] [blame] | 1912 | [pool release]; |
Akihiko Odaki | 7e3e20d | 2021-06-16 23:19:54 +0900 | [diff] [blame] | 1913 | break; |
| 1914 | default: |
| 1915 | break; |
| 1916 | } |
| 1917 | } |
| 1918 | |
Peter Maydell | 5588840 | 2019-02-25 10:24:33 +0000 | [diff] [blame] | 1919 | /* |
| 1920 | * The startup process for the OSX/Cocoa UI is complicated, because |
| 1921 | * OSX insists that the UI runs on the initial main thread, and so we |
| 1922 | * need to start a second thread which runs the vl.c qemu_main(): |
| 1923 | * |
| 1924 | * Initial thread: 2nd thread: |
| 1925 | * in main(): |
| 1926 | * create qemu-main thread |
| 1927 | * wait on display_init semaphore |
| 1928 | * call qemu_main() |
| 1929 | * ... |
| 1930 | * in cocoa_display_init(): |
| 1931 | * post the display_init semaphore |
| 1932 | * wait on app_started semaphore |
| 1933 | * create application, menus, etc |
| 1934 | * enter OSX run loop |
| 1935 | * in applicationDidFinishLaunching: |
| 1936 | * post app_started semaphore |
| 1937 | * tell main thread to fullscreen if needed |
| 1938 | * [...] |
| 1939 | * run qemu main-loop |
| 1940 | * |
| 1941 | * We do this in two stages so that we don't do the creation of the |
| 1942 | * GUI application menus and so on for command line options like --help |
| 1943 | * where we want to just print text to stdout and exit immediately. |
| 1944 | */ |
Peter Maydell | c6fd6c7 | 2019-02-25 10:24:29 +0000 | [diff] [blame] | 1945 | |
Peter Maydell | 5588840 | 2019-02-25 10:24:33 +0000 | [diff] [blame] | 1946 | static void *call_qemu_main(void *opaque) |
| 1947 | { |
| 1948 | int status; |
| 1949 | |
| 1950 | COCOA_DEBUG("Second thread: calling qemu_main()\n"); |
| 1951 | status = qemu_main(gArgc, gArgv, *_NSGetEnviron()); |
| 1952 | COCOA_DEBUG("Second thread: qemu_main() returned, exiting\n"); |
Akihiko Odaki | 7e3e20d | 2021-06-16 23:19:54 +0900 | [diff] [blame] | 1953 | [cbowner release]; |
Peter Maydell | 5588840 | 2019-02-25 10:24:33 +0000 | [diff] [blame] | 1954 | exit(status); |
| 1955 | } |
| 1956 | |
Akihiko Odaki | 40a9aad | 2021-07-09 01:56:19 +0900 | [diff] [blame] | 1957 | int main (int argc, char **argv) { |
Peter Maydell | 5588840 | 2019-02-25 10:24:33 +0000 | [diff] [blame] | 1958 | QemuThread thread; |
| 1959 | |
| 1960 | COCOA_DEBUG("Entered main()\n"); |
Peter Maydell | c6fd6c7 | 2019-02-25 10:24:29 +0000 | [diff] [blame] | 1961 | gArgc = argc; |
Akihiko Odaki | 40a9aad | 2021-07-09 01:56:19 +0900 | [diff] [blame] | 1962 | gArgv = argv; |
Peter Maydell | c6fd6c7 | 2019-02-25 10:24:29 +0000 | [diff] [blame] | 1963 | |
Peter Maydell | 5588840 | 2019-02-25 10:24:33 +0000 | [diff] [blame] | 1964 | qemu_sem_init(&display_init_sem, 0); |
| 1965 | qemu_sem_init(&app_started_sem, 0); |
Peter Maydell | c6fd6c7 | 2019-02-25 10:24:29 +0000 | [diff] [blame] | 1966 | |
Peter Maydell | 5588840 | 2019-02-25 10:24:33 +0000 | [diff] [blame] | 1967 | qemu_thread_create(&thread, "qemu_main", call_qemu_main, |
| 1968 | NULL, QEMU_THREAD_DETACHED); |
| 1969 | |
| 1970 | COCOA_DEBUG("Main thread: waiting for display_init_sem\n"); |
| 1971 | qemu_sem_wait(&display_init_sem); |
| 1972 | COCOA_DEBUG("Main thread: initializing app\n"); |
Peter Maydell | c6fd6c7 | 2019-02-25 10:24:29 +0000 | [diff] [blame] | 1973 | |
| 1974 | NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; |
| 1975 | |
| 1976 | // Pull this console process up to being a fully-fledged graphical |
| 1977 | // app with a menubar and Dock icon |
| 1978 | ProcessSerialNumber psn = { 0, kCurrentProcess }; |
| 1979 | TransformProcessType(&psn, kProcessTransformToForegroundApplication); |
| 1980 | |
Peter Maydell | 61a2ed4 | 2019-02-25 10:24:32 +0000 | [diff] [blame] | 1981 | [QemuApplication sharedApplication]; |
Peter Maydell | c6fd6c7 | 2019-02-25 10:24:29 +0000 | [diff] [blame] | 1982 | |
| 1983 | create_initial_menus(); |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 1984 | |
Peter Maydell | 5588840 | 2019-02-25 10:24:33 +0000 | [diff] [blame] | 1985 | /* |
| 1986 | * Create the menu entries which depend on QEMU state (for consoles |
| 1987 | * and removeable devices). These make calls back into QEMU functions, |
| 1988 | * which is OK because at this point we know that the second thread |
| 1989 | * holds the iothread lock and is synchronously waiting for us to |
| 1990 | * finish. |
| 1991 | */ |
| 1992 | add_console_menu_entries(); |
| 1993 | addRemovableDevicesMenuItems(); |
| 1994 | |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 1995 | // Create an Application controller |
| 1996 | QemuCocoaAppController *appController = [[QemuCocoaAppController alloc] init]; |
| 1997 | [NSApp setDelegate:appController]; |
| 1998 | |
| 1999 | // Start the main event loop |
Peter Maydell | 5588840 | 2019-02-25 10:24:33 +0000 | [diff] [blame] | 2000 | COCOA_DEBUG("Main thread: entering OSX run loop\n"); |
bellard | 5b0753e | 2005-03-01 21:37:28 +0000 | [diff] [blame] | 2001 | [NSApp run]; |
Peter Maydell | 5588840 | 2019-02-25 10:24:33 +0000 | [diff] [blame] | 2002 | COCOA_DEBUG("Main thread: left OSX run loop, exiting\n"); |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 2003 | |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 2004 | [appController release]; |
bellard | 5b0753e | 2005-03-01 21:37:28 +0000 | [diff] [blame] | 2005 | [pool release]; |
bellard | cae41b1 | 2006-05-22 21:25:04 +0000 | [diff] [blame] | 2006 | |
bellard | 5b0753e | 2005-03-01 21:37:28 +0000 | [diff] [blame] | 2007 | return 0; |
| 2008 | } |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 2009 | |
| 2010 | |
| 2011 | |
| 2012 | #pragma mark qemu |
Gerd Hoffmann | 7c20b4a | 2012-11-13 14:51:41 +0100 | [diff] [blame] | 2013 | static void cocoa_update(DisplayChangeListener *dcl, |
Gerd Hoffmann | 7c20b4a | 2012-11-13 14:51:41 +0100 | [diff] [blame] | 2014 | int x, int y, int w, int h) |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 2015 | { |
| 2016 | COCOA_DEBUG("qemu_cocoa: cocoa_update\n"); |
| 2017 | |
Peter Maydell | 5588840 | 2019-02-25 10:24:33 +0000 | [diff] [blame] | 2018 | dispatch_async(dispatch_get_main_queue(), ^{ |
| 2019 | NSRect rect; |
| 2020 | if ([cocoaView cdx] == 1.0) { |
| 2021 | rect = NSMakeRect(x, [cocoaView gscreen].height - y - h, w, h); |
| 2022 | } else { |
| 2023 | rect = NSMakeRect( |
| 2024 | x * [cocoaView cdx], |
| 2025 | ([cocoaView gscreen].height - y - h) * [cocoaView cdy], |
| 2026 | w * [cocoaView cdx], |
| 2027 | h * [cocoaView cdy]); |
| 2028 | } |
| 2029 | [cocoaView setNeedsDisplayInRect:rect]; |
| 2030 | }); |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 2031 | } |
| 2032 | |
Gerd Hoffmann | c12aeb8 | 2013-02-28 15:03:04 +0100 | [diff] [blame] | 2033 | static void cocoa_switch(DisplayChangeListener *dcl, |
Gerd Hoffmann | c12aeb8 | 2013-02-28 15:03:04 +0100 | [diff] [blame] | 2034 | DisplaySurface *surface) |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 2035 | { |
Peter Maydell | 5588840 | 2019-02-25 10:24:33 +0000 | [diff] [blame] | 2036 | pixman_image_t *image = surface->image; |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 2037 | |
Peter Maydell | 6e657e6 | 2013-04-22 10:29:46 +0000 | [diff] [blame] | 2038 | COCOA_DEBUG("qemu_cocoa: cocoa_switch\n"); |
Peter Maydell | 5588840 | 2019-02-25 10:24:33 +0000 | [diff] [blame] | 2039 | |
| 2040 | // The DisplaySurface will be freed as soon as this callback returns. |
| 2041 | // We take a reference to the underlying pixman image here so it does |
| 2042 | // not disappear from under our feet; the switchSurface method will |
| 2043 | // deref the old image when it is done with it. |
| 2044 | pixman_image_ref(image); |
| 2045 | |
| 2046 | dispatch_async(dispatch_get_main_queue(), ^{ |
Peter Maydell | 8d65dee | 2022-02-24 10:13:29 +0000 | [diff] [blame] | 2047 | [cocoaView updateUIInfo]; |
Peter Maydell | 5588840 | 2019-02-25 10:24:33 +0000 | [diff] [blame] | 2048 | [cocoaView switchSurface:image]; |
| 2049 | }); |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 2050 | } |
| 2051 | |
Gerd Hoffmann | bc2ed97 | 2013-03-01 13:03:04 +0100 | [diff] [blame] | 2052 | static void cocoa_refresh(DisplayChangeListener *dcl) |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 2053 | { |
Peter Maydell | 6e657e6 | 2013-04-22 10:29:46 +0000 | [diff] [blame] | 2054 | NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; |
| 2055 | |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 2056 | COCOA_DEBUG("qemu_cocoa: cocoa_refresh\n"); |
John Arbuckle | 468a895 | 2015-10-13 21:51:18 +0100 | [diff] [blame] | 2057 | graphic_hw_update(NULL); |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 2058 | |
Gerd Hoffmann | 21bae11 | 2013-12-04 14:08:04 +0100 | [diff] [blame] | 2059 | if (qemu_input_is_absolute()) { |
Peter Maydell | 5588840 | 2019-02-25 10:24:33 +0000 | [diff] [blame] | 2060 | dispatch_async(dispatch_get_main_queue(), ^{ |
| 2061 | if (![cocoaView isAbsoluteEnabled]) { |
| 2062 | if ([cocoaView isMouseGrabbed]) { |
| 2063 | [cocoaView ungrabMouse]; |
| 2064 | } |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 2065 | } |
Peter Maydell | 5588840 | 2019-02-25 10:24:33 +0000 | [diff] [blame] | 2066 | [cocoaView setAbsoluteEnabled:YES]; |
| 2067 | }); |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 2068 | } |
Akihiko Odaki | 7e3e20d | 2021-06-16 23:19:54 +0900 | [diff] [blame] | 2069 | |
| 2070 | if (cbchangecount != [[NSPasteboard generalPasteboard] changeCount]) { |
| 2071 | qemu_clipboard_info_unref(cbinfo); |
| 2072 | cbinfo = qemu_clipboard_info_new(&cbpeer, QEMU_CLIPBOARD_SELECTION_CLIPBOARD); |
| 2073 | if ([[NSPasteboard generalPasteboard] availableTypeFromArray:@[NSPasteboardTypeString]]) { |
| 2074 | cbinfo->types[QEMU_CLIPBOARD_TYPE_TEXT].available = true; |
| 2075 | } |
| 2076 | qemu_clipboard_update(cbinfo); |
| 2077 | cbchangecount = [[NSPasteboard generalPasteboard] changeCount]; |
| 2078 | qemu_event_set(&cbevent); |
| 2079 | } |
| 2080 | |
Peter Maydell | 6e657e6 | 2013-04-22 10:29:46 +0000 | [diff] [blame] | 2081 | [pool release]; |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 2082 | } |
| 2083 | |
Gerd Hoffmann | 5013b9e | 2018-03-01 11:05:37 +0100 | [diff] [blame] | 2084 | static void cocoa_display_init(DisplayState *ds, DisplayOptions *opts) |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 2085 | { |
| 2086 | COCOA_DEBUG("qemu_cocoa: cocoa_display_init\n"); |
| 2087 | |
Peter Maydell | 5588840 | 2019-02-25 10:24:33 +0000 | [diff] [blame] | 2088 | /* Tell main thread to go ahead and create the app and enter the run loop */ |
| 2089 | qemu_sem_post(&display_init_sem); |
| 2090 | qemu_sem_wait(&app_started_sem); |
| 2091 | COCOA_DEBUG("cocoa_display_init: app start completed\n"); |
| 2092 | |
Gustavo Noronha Silva | f844cdb | 2022-03-06 21:11:18 +0900 | [diff] [blame] | 2093 | QemuCocoaAppController *controller = (QemuCocoaAppController *)[[NSApplication sharedApplication] delegate]; |
Programmingkid | 43227af | 2015-05-19 09:11:17 +0100 | [diff] [blame] | 2094 | /* if fullscreen mode is to be used */ |
Gerd Hoffmann | 767f9bf | 2018-02-02 12:10:19 +0100 | [diff] [blame] | 2095 | if (opts->has_full_screen && opts->full_screen) { |
Peter Maydell | 5588840 | 2019-02-25 10:24:33 +0000 | [diff] [blame] | 2096 | dispatch_async(dispatch_get_main_queue(), ^{ |
| 2097 | [NSApp activateIgnoringOtherApps: YES]; |
Gustavo Noronha Silva | f844cdb | 2022-03-06 21:11:18 +0900 | [diff] [blame] | 2098 | [controller toggleFullScreen: nil]; |
| 2099 | }); |
| 2100 | } |
| 2101 | if (opts->u.cocoa.has_full_grab && opts->u.cocoa.full_grab) { |
| 2102 | dispatch_async(dispatch_get_main_queue(), ^{ |
| 2103 | [controller setFullGrab: nil]; |
Peter Maydell | 5588840 | 2019-02-25 10:24:33 +0000 | [diff] [blame] | 2104 | }); |
Programmingkid | 43227af | 2015-05-19 09:11:17 +0100 | [diff] [blame] | 2105 | } |
Carwyn Ellis | 69221df | 2022-01-02 17:41:53 +0000 | [diff] [blame] | 2106 | |
Gerd Hoffmann | 3487da6 | 2020-02-06 12:27:50 +0100 | [diff] [blame] | 2107 | if (opts->has_show_cursor && opts->show_cursor) { |
| 2108 | cursor_hide = 0; |
| 2109 | } |
Gustavo Noronha Silva | 4797adc | 2022-03-06 21:11:19 +0900 | [diff] [blame] | 2110 | if (opts->u.cocoa.has_swap_opt_cmd) { |
| 2111 | swap_opt_cmd = opts->u.cocoa.swap_opt_cmd; |
| 2112 | } |
Programmingkid | 43227af | 2015-05-19 09:11:17 +0100 | [diff] [blame] | 2113 | |
Carwyn Ellis | 48941a5 | 2022-01-02 17:41:52 +0000 | [diff] [blame] | 2114 | if (opts->u.cocoa.has_left_command_key && !opts->u.cocoa.left_command_key) { |
| 2115 | left_command_key_enabled = 0; |
| 2116 | } |
| 2117 | |
aliguori | 9794f74 | 2009-03-04 19:25:22 +0000 | [diff] [blame] | 2118 | // register vga output callbacks |
Akihiko Odaki | cc7859c | 2021-02-19 17:44:19 +0900 | [diff] [blame] | 2119 | register_displaychangelistener(&dcl); |
Akihiko Odaki | 7e3e20d | 2021-06-16 23:19:54 +0900 | [diff] [blame] | 2120 | |
| 2121 | qemu_event_init(&cbevent, false); |
| 2122 | cbowner = [[QemuCocoaPasteboardTypeOwner alloc] init]; |
| 2123 | qemu_clipboard_peer_register(&cbpeer); |
ths | c304f7e | 2008-01-22 23:25:15 +0000 | [diff] [blame] | 2124 | } |
Gerd Hoffmann | 5013b9e | 2018-03-01 11:05:37 +0100 | [diff] [blame] | 2125 | |
| 2126 | static QemuDisplay qemu_display_cocoa = { |
| 2127 | .type = DISPLAY_TYPE_COCOA, |
| 2128 | .init = cocoa_display_init, |
| 2129 | }; |
| 2130 | |
| 2131 | static void register_cocoa(void) |
| 2132 | { |
| 2133 | qemu_display_register(&qemu_display_cocoa); |
| 2134 | } |
| 2135 | |
| 2136 | type_init(register_cocoa); |