/* * Decompiled with CFR 0.152. * * Could not load the following classes: * org.lwjgl.BufferUtils * org.lwjgl.glfw.GLFW * org.lwjgl.glfw.GLFWErrorCallback * org.lwjgl.glfw.GLFWErrorCallbackI * org.lwjgl.system.MemoryUtil */ package com.mojang.blaze3d.platform; import com.mojang.blaze3d.platform.Window; import java.nio.Buffer; import java.nio.ByteBuffer; import java.nio.charset.StandardCharsets; import net.minecraft.util.StringDecomposer; import org.lwjgl.BufferUtils; import org.lwjgl.glfw.GLFW; import org.lwjgl.glfw.GLFWErrorCallback; import org.lwjgl.glfw.GLFWErrorCallbackI; import org.lwjgl.system.MemoryUtil; public class ClipboardManager { public static final int FORMAT_UNAVAILABLE = 65545; private final ByteBuffer clipboardScratchBuffer = BufferUtils.createByteBuffer((int)8192); public String getClipboard(Window window, GLFWErrorCallbackI errorCallback) { GLFWErrorCallback prevCallback = GLFW.glfwSetErrorCallback((GLFWErrorCallbackI)errorCallback); String clipboard = GLFW.glfwGetClipboardString((long)window.handle()); clipboard = clipboard != null ? StringDecomposer.filterBrokenSurrogates(clipboard) : ""; GLFWErrorCallback oldCallback = GLFW.glfwSetErrorCallback((GLFWErrorCallbackI)prevCallback); if (oldCallback != null) { oldCallback.free(); } return clipboard; } private static void pushClipboard(Window window, ByteBuffer buffer, byte[] data) { buffer.clear(); buffer.put(data); buffer.put((byte)0); buffer.flip(); GLFW.glfwSetClipboardString((long)window.handle(), (ByteBuffer)buffer); } /* * WARNING - Removed try catching itself - possible behaviour change. */ public void setClipboard(Window window, String clipboard) { byte[] encoded = clipboard.getBytes(StandardCharsets.UTF_8); int encodedLength = encoded.length + 1; if (encodedLength < this.clipboardScratchBuffer.capacity()) { ClipboardManager.pushClipboard(window, this.clipboardScratchBuffer, encoded); } else { ByteBuffer buffer = MemoryUtil.memAlloc((int)encodedLength); try { ClipboardManager.pushClipboard(window, buffer, encoded); } finally { MemoryUtil.memFree((Buffer)buffer); } } } }