mirror of
https://github.com/Karaka-Management/cOMS.git
synced 2026-01-11 19:28:40 +00:00
65 lines
1.5 KiB
C
65 lines
1.5 KiB
C
/**
|
|
* Jingga
|
|
*
|
|
* @copyright Jingga
|
|
* @license OMS License 2.0
|
|
* @version 1.0.0
|
|
* @link https://jingga.app
|
|
*/
|
|
#ifndef TOS_UTILS_LINUX_H
|
|
#define TOS_UTILS_LINUX_H
|
|
|
|
#include "../../stdlib/Types.h"
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <stdarg.h>
|
|
#include <X11/Xlib.h>
|
|
#include <X11/Xatom.h>
|
|
|
|
void clipboard_get(char* text, int32 max_length)
|
|
{
|
|
*text = '\0';
|
|
|
|
Display *display = XOpenDisplay(NULL);
|
|
if (display == NULL) {
|
|
return;
|
|
}
|
|
|
|
Atom clipboard = XInternAtom(display, "CLIPBOARD", false);
|
|
Atom utf8_string = XInternAtom(display, "UTF8_STRING", false);
|
|
Atom xa_string = XInternAtom(display, "STRING", false);
|
|
Window window = XDefaultRootWindow(display);
|
|
|
|
XConvertSelection(display, clipboard, utf8_string, xa_string, window, CurrentTime);
|
|
XEvent event;
|
|
XNextEvent(display, &event);
|
|
|
|
if (event.type == SelectionNotify) {
|
|
if (event.xselection.property) {
|
|
Atom type;
|
|
int32 format;
|
|
unsigned long nitems, bytes_after;
|
|
byte* data = NULL;
|
|
|
|
XGetWindowProperty(
|
|
display, event.xselection.requestor,
|
|
event.xselection.property, 0, (~0L), false,
|
|
AnyPropertyType, &type, &format, &nitems,
|
|
&bytes_after, &data
|
|
);
|
|
|
|
if (data) {
|
|
str_copy_short(text, clipboard_text, max_length);
|
|
XFree(data);
|
|
}
|
|
}
|
|
}
|
|
|
|
XCloseDisplay(display);
|
|
}
|
|
|
|
void output_char(char c) {
|
|
write(STDOUT_FILENO, &c, 1);
|
|
}
|
|
|
|
#endif |