MCPcopy Create free account
hub / github.com/danoon2/Boxedwine / initClipboard

Method initClipboard

source/x11/xserver.cpp:292–363  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

290}
291
292void XServer::initClipboard() {
293 KNativeScreenPtr screen = KNativeSystem::getScreen();
294
295 selectionWindow = std::make_shared<XWindow>(0, root, 0, 0, 32, 0, 0, InputOnly, 0, visual);
296 windows.set(selectionWindow->id, selectionWindow);
297
298 selectionWindow->onPropertyChanged.push_back([this](U32 propAtom) {
299 if (propAtom == EXPORT_CLIPBOARD) {
300 XPropertyPtr prop = this->selectionWindow->getProperty(propAtom);
301 if (!prop) {
302 return;
303 }
304 char* value = new char[prop->length + 1];
305 memcpy(value, prop->value, prop->length);
306 value[prop->length] = 0;
307 KNativeSystem::getScreen()->clipboardSetText(value);
308 delete[] value;
309 this->selectionWindow->deleteProperty(propAtom);
310 return;
311 }
312 });
313
314 KNativeSystem::getCurrentInput()->onFocusGained.push_back([] {
315 XServer* server = XServer::getServer();
316 KNativeScreenPtr screen = KNativeSystem::getScreen();
317 if (!screen->clipboardIsTextAvailable()) {
318 return;
319 }
320 BString text = screen->clipboardGetText();
321 if (server->sdlLastSelection != text) {
322 server->sdlLastSelection = text;
323 if (!server->selectionOwner) {
324 server->selectionOwner = server->selectionWindow->id;
325 }
326 XWindowPtr owner = server->getWindow(server->selectionOwner);
327
328 if (owner && server->selectionOwner != server->selectionWindow->id) {
329 XEvent event;
330 DisplayDataPtr data = server->getDisplayDataById(owner->displayId);
331 event.type = SelectionClear;
332 event.xselectionclear.display = data->displayAddress;
333 event.xselectionclear.selection = CLIPBOARD;
334 event.xselectionclear.serial = data->getNextEventSerial();
335 event.xselectionclear.time = server->getEventTime();
336 event.xselectionclear.send_event = False;
337 event.xselectionclear.window = server->selectionOwner;
338 data->putEvent(event);
339
340 server->selectionOwner = server->selectionWindow->id;
341 }
342 }
343 });
344 KNativeSystem::getCurrentInput()->onFocusLost.push_back([] {
345 if (server->selectionOwner && server->selectionOwner != server->selectionWindow->id) {
346 XWindowPtr owner = server->getWindow(server->selectionOwner);
347 XEvent event;
348 DisplayDataPtr data = server->getDisplayDataById(owner->displayId);
349 event.type = SelectionRequest;

Callers

nothing calls this directly

Calls 13

memcpyFunction · 0.85
getWindowMethod · 0.80
getDisplayDataByIdMethod · 0.80
getNextEventSerialMethod · 0.80
getEventTimeMethod · 0.80
putEventMethod · 0.80
clipboardSetTextMethod · 0.65
clipboardGetTextMethod · 0.65
setMethod · 0.45
push_backMethod · 0.45
getPropertyMethod · 0.45

Tested by

no test coverage detected