Clear window on linux

This commit is contained in:
luboslenco
2025-07-21 19:21:14 +02:00
parent d1e47cf375
commit 31bfb96a41
2 changed files with 60 additions and 50 deletions
+58 -49
View File
@@ -363,10 +363,10 @@ void iron_window_set_title(const char *_title) {
const char *title = _title == NULL ? "" : _title; const char *title = _title == NULL ? "" : _title;
struct iron_x11_window *window = &x11_ctx.windows[0]; struct iron_x11_window *window = &x11_ctx.windows[0];
xlib.XChangeProperty(x11_ctx.display, window->window, x11_ctx.atoms.NET_WM_NAME, x11_ctx.atoms.UTF8_STRING, 8, PropModeReplace, (unsigned char *)title, xlib.XChangeProperty(x11_ctx.display, window->window, x11_ctx.atoms.NET_WM_NAME, x11_ctx.atoms.UTF8_STRING, 8, PropModeReplace, (unsigned char *)title,
strlen(title)); strlen(title));
xlib.XChangeProperty(x11_ctx.display, window->window, x11_ctx.atoms.NET_WM_ICON_NAME, x11_ctx.atoms.UTF8_STRING, 8, PropModeReplace, (unsigned char *)title, xlib.XChangeProperty(x11_ctx.display, window->window, x11_ctx.atoms.NET_WM_ICON_NAME, x11_ctx.atoms.UTF8_STRING, 8, PropModeReplace, (unsigned char *)title,
strlen(title)); strlen(title));
xlib.XFlush(x11_ctx.display); xlib.XFlush(x11_ctx.display);
} }
@@ -379,15 +379,23 @@ void iron_window_create(iron_window_options_t *win) {
Visual *visual = NULL; Visual *visual = NULL;
XSetWindowAttributes set_window_attribs = {0}; XSetWindowAttributes set_window_attribs = {0};
XColor color;
Colormap colormap = DefaultColormap(x11_ctx.display, DefaultScreen(x11_ctx.display));
color.red = (32 * 65535) / 255;
color.green = (32 * 65535) / 255;
color.blue = (32 * 65535) / 255;
xlib.XAllocColor(x11_ctx.display, colormap, &color);
set_window_attribs.background_pixel = color.pixel;
set_window_attribs.border_pixel = 0; set_window_attribs.border_pixel = 0;
set_window_attribs.event_mask = set_window_attribs.event_mask =
KeyPressMask | KeyReleaseMask | ExposureMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask | StructureNotifyMask | FocusChangeMask; KeyPressMask | KeyReleaseMask | ExposureMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask | StructureNotifyMask | FocusChangeMask;
int screen = DefaultScreen(x11_ctx.display); int screen = DefaultScreen(x11_ctx.display);
visual = DefaultVisual(x11_ctx.display, screen); visual = DefaultVisual(x11_ctx.display, screen);
int depth = DefaultDepth(x11_ctx.display, screen); int depth = DefaultDepth(x11_ctx.display, screen);
set_window_attribs.colormap = xlib.XCreateColormap(x11_ctx.display, RootWindow(x11_ctx.display, screen), visual, AllocNone); set_window_attribs.colormap = xlib.XCreateColormap(x11_ctx.display, RootWindow(x11_ctx.display, screen), visual, AllocNone);
window->window = xlib.XCreateWindow(x11_ctx.display, RootWindow(x11_ctx.display, DefaultScreen(x11_ctx.display)), 0, 0, win->width, win->height, 0, depth, window->window = xlib.XCreateWindow(x11_ctx.display, RootWindow(x11_ctx.display, DefaultScreen(x11_ctx.display)), 0, 0, win->width, win->height, 0, depth,
InputOutput, visual, CWBorderPixel | CWColormap | CWEventMask, &set_window_attribs); InputOutput, visual, CWBackPixel | CWBorderPixel | CWColormap | CWEventMask, &set_window_attribs);
static char nameClass[256]; static char nameClass[256];
static const char *nameClassAddendum = "_IronApplication"; static const char *nameClassAddendum = "_IronApplication";
@@ -504,7 +512,7 @@ bool iron_x11_init() {
#define LOAD_LIB(name) \ #define LOAD_LIB(name) \
{ \ { \
load_lib(&x11_ctx.libs.name, #name); \ load_lib(&x11_ctx.libs.name, #name); \
\ \
if (x11_ctx.libs.name == NULL) { \ if (x11_ctx.libs.name == NULL) { \
iron_error("Failed to load lib%s.so", #name); \ iron_error("Failed to load lib%s.so", #name); \
return false; \ return false; \
@@ -570,6 +578,7 @@ bool iron_x11_init() {
LOAD_FUN(X11, XUnmapWindow) LOAD_FUN(X11, XUnmapWindow)
LOAD_FUN(X11, XSetWMProtocols) LOAD_FUN(X11, XSetWMProtocols)
LOAD_FUN(X11, XPeekEvent) LOAD_FUN(X11, XPeekEvent)
LOAD_FUN(X11, XAllocColor)
LOAD_FUN(Xi, XListInputDevices) LOAD_FUN(Xi, XListInputDevices)
LOAD_FUN(Xi, XFreeDeviceList) LOAD_FUN(Xi, XFreeDeviceList)
@@ -600,44 +609,44 @@ bool iron_x11_init() {
// this should be kept in sync with the x11_atoms struct // this should be kept in sync with the x11_atoms struct
static char *atom_names[] = { static char *atom_names[] = {
"XdndAware", "XdndAware",
"XdndDrop", "XdndDrop",
"XdndEnter", "XdndEnter",
"text/uri-list", "text/uri-list",
"XdndStatus", "XdndStatus",
"XdndActionCopy", "XdndActionCopy",
"XdndSelection", "XdndSelection",
"CLIPBOARD", "CLIPBOARD",
"UTF8_STRING", "UTF8_STRING",
"XSEL_DATA", "XSEL_DATA",
"TARGETS", "TARGETS",
"MULTIPLE", "MULTIPLE",
"text/plain;charset=utf-8", "text/plain;charset=utf-8",
"WM_DELETE_WINDOW", "WM_DELETE_WINDOW",
"_MOTIF_WM_HINTS", "_MOTIF_WM_HINTS",
"_NET_WM_NAME", "_NET_WM_NAME",
"_NET_WM_ICON_NAME", "_NET_WM_ICON_NAME",
"_NET_WM_STATE", "_NET_WM_STATE",
"_NET_WM_STATE_FULLSCREEN", "_NET_WM_STATE_FULLSCREEN",
XI_MOUSE, XI_MOUSE,
XI_TABLET, XI_TABLET,
XI_KEYBOARD, XI_KEYBOARD,
XI_TOUCHSCREEN, XI_TOUCHSCREEN,
XI_TOUCHPAD, XI_TOUCHPAD,
XI_BUTTONBOX, XI_BUTTONBOX,
XI_BARCODE, XI_BARCODE,
XI_TRACKBALL, XI_TRACKBALL,
XI_QUADRATURE, XI_QUADRATURE,
XI_ID_MODULE, XI_ID_MODULE,
XI_ONE_KNOB, XI_ONE_KNOB,
XI_NINE_KNOB, XI_NINE_KNOB,
XI_KNOB_BOX, XI_KNOB_BOX,
XI_SPACEBALL, XI_SPACEBALL,
XI_DATAGLOVE, XI_DATAGLOVE,
XI_EYETRACKER, XI_EYETRACKER,
XI_CURSORKEYS, XI_CURSORKEYS,
XI_FOOTMOUSE, XI_FOOTMOUSE,
XI_JOYSTICK, XI_JOYSTICK,
}; };
assert((sizeof atom_names / sizeof atom_names[0]) == (sizeof(struct iron_x11_atoms) / sizeof(Atom))); assert((sizeof atom_names / sizeof atom_names[0]) == (sizeof(struct iron_x11_atoms) / sizeof(Atom)));
@@ -733,7 +742,7 @@ void iron_vulkan_get_instance_extensions(const char **names, int *index) {
VkBool32 iron_vulkan_get_physical_device_presentation_support(VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex) { VkBool32 iron_vulkan_get_physical_device_presentation_support(VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex) {
return vkGetPhysicalDeviceXlibPresentationSupportKHR(physicalDevice, queueFamilyIndex, x11_ctx.display, return vkGetPhysicalDeviceXlibPresentationSupportKHR(physicalDevice, queueFamilyIndex, x11_ctx.display,
DefaultVisual(x11_ctx.display, DefaultScreen(x11_ctx.display))->visualid); DefaultVisual(x11_ctx.display, DefaultScreen(x11_ctx.display))->visualid);
} }
VkResult iron_vulkan_create_surface(VkInstance instance, VkSurfaceKHR *surface) { VkResult iron_vulkan_create_surface(VkInstance instance, VkSurfaceKHR *surface) {
VkXlibSurfaceCreateInfoKHR info = {0}; VkXlibSurfaceCreateInfoKHR info = {0};
@@ -1221,7 +1230,7 @@ static bool _handle_messages() {
} }
else if (event.xclient.message_type == x11_ctx.atoms.XdndDrop) { else if (event.xclient.message_type == x11_ctx.atoms.XdndDrop) {
xlib.XConvertSelection(x11_ctx.display, x11_ctx.atoms.XdndSelection, x11_ctx.atoms.XdndTextUriList, x11_ctx.atoms.XdndSelection, window, xlib.XConvertSelection(x11_ctx.display, x11_ctx.atoms.XdndSelection, x11_ctx.atoms.XdndTextUriList, x11_ctx.atoms.XdndSelection, window,
event.xclient.data.l[2]); event.xclient.data.l[2]);
} }
else if (event.xclient.data.l[0] == x11_ctx.atoms.WM_DELETE_WINDOW) { else if (event.xclient.data.l[0] == x11_ctx.atoms.WM_DELETE_WINDOW) {
if (iron_internal_call_close_callback()) { if (iron_internal_call_close_callback()) {
@@ -1236,7 +1245,7 @@ static bool _handle_messages() {
unsigned long ressize, restail; unsigned long ressize, restail;
int resbits; int resbits;
xlib.XGetWindowProperty(x11_ctx.display, window, x11_ctx.atoms.XSEL_DATA, 0, LONG_MAX / 4, False, AnyPropertyType, &x11_ctx.atoms.UTF8_STRING, xlib.XGetWindowProperty(x11_ctx.display, window, x11_ctx.atoms.XSEL_DATA, 0, LONG_MAX / 4, False, AnyPropertyType, &x11_ctx.atoms.UTF8_STRING,
&resbits, &ressize, &restail, (unsigned char **)&result); &resbits, &ressize, &restail, (unsigned char **)&result);
iron_internal_paste_callback(result); iron_internal_paste_callback(result);
xlib.XFree(result); xlib.XFree(result);
} }
@@ -1247,7 +1256,7 @@ static bool _handle_messages() {
unsigned long bytesAfter = 1; unsigned long bytesAfter = 1;
unsigned char *data = 0; unsigned char *data = 0;
xlib.XGetWindowProperty(x11_ctx.display, event.xselection.requestor, event.xselection.property, 0, LONG_MAX, False, event.xselection.target, xlib.XGetWindowProperty(x11_ctx.display, event.xselection.requestor, event.xselection.property, 0, LONG_MAX, False, event.xselection.target,
&type, &format, &numItems, &bytesAfter, &data); &type, &format, &numItems, &bytesAfter, &data);
size_t pos = 0; size_t pos = 0;
size_t len = 0; size_t len = 0;
while (pos < numItems) { while (pos < numItems) {
@@ -1276,7 +1285,7 @@ static bool _handle_messages() {
send.xselection.time = event.xselectionrequest.time; send.xselection.time = event.xselectionrequest.time;
Atom available[] = {x11_ctx.atoms.TARGETS, x11_ctx.atoms.MULTIPLE, x11_ctx.atoms.TEXT_PLAIN, x11_ctx.atoms.UTF8_STRING}; Atom available[] = {x11_ctx.atoms.TARGETS, x11_ctx.atoms.MULTIPLE, x11_ctx.atoms.TEXT_PLAIN, x11_ctx.atoms.UTF8_STRING};
xlib.XChangeProperty(x11_ctx.display, send.xselection.requestor, send.xselection.property, XA_ATOM, 32, PropModeReplace, xlib.XChangeProperty(x11_ctx.display, send.xselection.requestor, send.xselection.property, XA_ATOM, 32, PropModeReplace,
(unsigned char *)&available[0], 4); (unsigned char *)&available[0], 4);
xlib.XSendEvent(x11_ctx.display, send.xselection.requestor, True, 0, &send); xlib.XSendEvent(x11_ctx.display, send.xselection.requestor, True, 0, &send);
} }
if (event.xselectionrequest.target == x11_ctx.atoms.TEXT_PLAIN || event.xselectionrequest.target == x11_ctx.atoms.UTF8_STRING) { if (event.xselectionrequest.target == x11_ctx.atoms.TEXT_PLAIN || event.xselectionrequest.target == x11_ctx.atoms.UTF8_STRING) {
@@ -1288,7 +1297,7 @@ static bool _handle_messages() {
send.xselection.property = event.xselectionrequest.property; send.xselection.property = event.xselectionrequest.property;
send.xselection.time = event.xselectionrequest.time; send.xselection.time = event.xselectionrequest.time;
xlib.XChangeProperty(x11_ctx.display, send.xselection.requestor, send.xselection.property, send.xselection.target, 8, PropModeReplace, xlib.XChangeProperty(x11_ctx.display, send.xselection.requestor, send.xselection.property, send.xselection.target, 8, PropModeReplace,
(const unsigned char *)clipboardString, strlen(clipboardString)); (const unsigned char *)clipboardString, strlen(clipboardString));
xlib.XSendEvent(x11_ctx.display, send.xselection.requestor, True, 0, &send); xlib.XSendEvent(x11_ctx.display, send.xselection.requestor, True, 0, &send);
} }
break; break;
+2 -1
View File
@@ -121,7 +121,7 @@ struct iron_x11_procs {
int (*XQueryPointer)(Display *, Window, Window *, Window *, int *, int *, int *, int *, unsigned int *); int (*XQueryPointer)(Display *, Window, Window *, Window *, int *, int *, int *, int *, unsigned int *);
Colormap (*XCreateColormap)(Display *, Window, Visual *, int); Colormap (*XCreateColormap)(Display *, Window, Visual *, int);
Window (*XCreateWindow)(Display *display, Window parent, int x, int y, unsigned int width, unsigned int height, unsigned int border_width, int depth, Window (*XCreateWindow)(Display *display, Window parent, int x, int y, unsigned int width, unsigned int height, unsigned int border_width, int depth,
unsigned int class, Visual *visual, unsigned long valuemask, XSetWindowAttributes *attributes); unsigned int class, Visual *visual, unsigned long valuemask, XSetWindowAttributes *attributes);
int (*XMoveWindow)(Display *, Window, int, int); int (*XMoveWindow)(Display *, Window, int, int);
int (*XResizeWindow)(Display *, Window, unsigned int, unsigned int); int (*XResizeWindow)(Display *, Window, unsigned int, unsigned int);
int (*XDestroyWindow)(Display *, Window); int (*XDestroyWindow)(Display *, Window);
@@ -135,6 +135,7 @@ struct iron_x11_procs {
int (*XMapWindow)(Display *, Window); int (*XMapWindow)(Display *, Window);
int (*XUnmapWindow)(Display *, Window); int (*XUnmapWindow)(Display *, Window);
int (*XSetWMProtocols)(Display *, Window, Atom *, int); int (*XSetWMProtocols)(Display *, Window, Atom *, int);
int (*XAllocColor)(Display *, Colormap, XColor *);
XDeviceInfo *(*XListInputDevices)(Display *, int *); XDeviceInfo *(*XListInputDevices)(Display *, int *);
void (*XFreeDeviceList)(XDeviceInfo *); void (*XFreeDeviceList)(XDeviceInfo *);