qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Peter Maydell <peter.maydell@linaro.org>
To: Akihiko Odaki <akihiko.odaki@gmail.com>
Cc: qemu-devel@nongnu.org, Gerd Hoffmann <kraxel@redhat.com>
Subject: Re: [PATCH] ui/cocoa: Add clipboard support
Date: Tue, 8 Feb 2022 17:54:10 +0000	[thread overview]
Message-ID: <CAFEAcA8eJFdkO41ZLBCMxm3wHY=u0av7kW5-anHuTRgQD-b6sQ@mail.gmail.com> (raw)
In-Reply-To: <20210616141954.54291-1-akihiko.odaki@gmail.com>

On Wed, 16 Jun 2021 at 15:20, Akihiko Odaki <akihiko.odaki@gmail.com> wrote:
>
> Signed-off-by: Akihiko Odaki <akihiko.odaki@gmail.com>

Hi Akihiko -- I have a similar question here to the other
patch about doing things not on the Cocoa UI thread...

> +static void cocoa_clipboard_notify(Notifier *notifier, void *data)
> +{
> +    QemuClipboardInfo *info = data;
> +
> +    if (info->owner == &cbpeer || info->selection != QEMU_CLIPBOARD_SELECTION_CLIPBOARD) {
> +        return;
> +    }
> +
> +    if (info != cbinfo) {
> +        NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
> +        qemu_clipboard_info_unref(cbinfo);
> +        cbinfo = qemu_clipboard_info_ref(info);
> +        cbchangecount = [[NSPasteboard generalPasteboard] declareTypes:@[NSPasteboardTypeString] owner:cbowner];
> +        [pool release];

Is this OK to do on a non-Cocoa thread with an autorelease pool,
or should it be done via dispatch_async ?

> +    }
> +
> +    qemu_event_set(&cbevent);
> +}

>  /*
>   * The startup process for the OSX/Cocoa UI is complicated, because
>   * OSX insists that the UI runs on the initial main thread, and so we
> @@ -1845,6 +1937,7 @@ static void addRemovableDevicesMenuItems(void)
>      COCOA_DEBUG("Second thread: calling qemu_main()\n");
>      status = qemu_main(gArgc, gArgv, *_NSGetEnviron());
>      COCOA_DEBUG("Second thread: qemu_main() returned, exiting\n");
> +    [cbowner release];
>      exit(status);
>  }
>
> @@ -1965,6 +2058,18 @@ static void cocoa_refresh(DisplayChangeListener *dcl)
>              [cocoaView setAbsoluteEnabled:YES];
>          });
>      }
> +
> +    if (cbchangecount != [[NSPasteboard generalPasteboard] changeCount]) {
> +        qemu_clipboard_info_unref(cbinfo);
> +        cbinfo = qemu_clipboard_info_new(&cbpeer, QEMU_CLIPBOARD_SELECTION_CLIPBOARD);
> +        if ([[NSPasteboard generalPasteboard] availableTypeFromArray:@[NSPasteboardTypeString]]) {
> +            cbinfo->types[QEMU_CLIPBOARD_TYPE_TEXT].available = true;
> +        }
> +        qemu_clipboard_update(cbinfo);
> +        cbchangecount = [[NSPasteboard generalPasteboard] changeCount];
> +        qemu_event_set(&cbevent);
> +    }
> +

This work in the cocoa_refresh() function is done not on the Cocoa
UI thread. Is it OK for it to do that, or should we put it into a
dispatch_async block ?

>      [pool release];
>  }

thanks
-- PMM


  parent reply	other threads:[~2022-02-08 18:25 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-16 14:19 [PATCH] ui/cocoa: Add clipboard support Akihiko Odaki
2021-06-23 12:44 ` Gerd Hoffmann
2022-02-08 17:54 ` Peter Maydell [this message]
2022-02-09 11:27   ` Akihiko Odaki

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAFEAcA8eJFdkO41ZLBCMxm3wHY=u0av7kW5-anHuTRgQD-b6sQ@mail.gmail.com' \
    --to=peter.maydell@linaro.org \
    --cc=akihiko.odaki@gmail.com \
    --cc=kraxel@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).