currentlyHeldWidget brought back
All checks were successful
pyrite-dev/milsko/pipeline/head This commit looks good
All checks were successful
pyrite-dev/milsko/pipeline/head This commit looks good
This commit is contained in:
parent
f25b676523
commit
5d5170e6ca
3 changed files with 84 additions and 38 deletions
|
|
@ -412,7 +412,7 @@ struct _MwLLWayland {
|
||||||
MwI32 ox, oy;
|
MwI32 ox, oy;
|
||||||
MwU32 ww, wh; /* Window position */
|
MwU32 ww, wh; /* Window position */
|
||||||
MwPoint cur_mouse_pos; /* Currently known mouse position */
|
MwPoint cur_mouse_pos; /* Currently known mouse position */
|
||||||
MwLL currentlyHeldWidget;
|
MwLL* currentlyHeldWidgets;
|
||||||
MwLL focusedWidget;
|
MwLL focusedWidget;
|
||||||
|
|
||||||
int resizing;
|
int resizing;
|
||||||
|
|
@ -486,9 +486,9 @@ int MwLLWaylandHyprlandGetRoundness(void);
|
||||||
|
|
||||||
void MwLLWaylandHangUntilConfigured(MwLL handle);
|
void MwLLWaylandHangUntilConfigured(MwLL handle);
|
||||||
|
|
||||||
// MwBool MwLLWaylandWidgetIsDestroyed(MwLL self);
|
MwBool MwLLWaylandWidgetIsDestroyed(MwLL self);
|
||||||
// void MwLLWaylandWidgetUndestroy(MwLL self);
|
void MwLLWaylandWidgetUndestroy(MwLL self);
|
||||||
void MwLLWaylandChildrenIterate(MwLL handle, void (*func)(MwLL handle, MwLL child));
|
void MwLLWaylandChildrenIterate(MwLL handle, void (*func)(MwLL handle, MwLL child));
|
||||||
|
|
||||||
/* Function for setting up the callbacks/structs that will be registered upon the relevant interfaces being found. */
|
/* Function for setting up the callbacks/structs that will be registered upon the relevant interfaces being found. */
|
||||||
void MwLLWaylandSetupCallbacks(struct _MwLLWayland* wayland);
|
void MwLLWaylandSetupCallbacks(struct _MwLLWayland* wayland);
|
||||||
|
|
@ -498,8 +498,13 @@ void MwLLWaylandClipboardRead(wl_clipboard_device_context_t* ctx, int clipboard_
|
||||||
/* Flush Wayland events */
|
/* Flush Wayland events */
|
||||||
void MwLLWaylandFlush(MwLL handle);
|
void MwLLWaylandFlush(MwLL handle);
|
||||||
|
|
||||||
|
void MwLLWaylandCascadeChildren(MwLL handle);
|
||||||
|
|
||||||
/* Standard procedure before event callbacks in Wayland */
|
/* Standard procedure before event callbacks in Wayland */
|
||||||
#define WAYLAND_EVENT_OP_START(self)
|
#define WAYLAND_EVENT_OP_START(self) \
|
||||||
|
if(MwLLWaylandWidgetIsDestroyed(self)) { \
|
||||||
|
return; \
|
||||||
|
}
|
||||||
|
|
||||||
/* Footer for WAYLAND_EVENT_OP_START */
|
/* Footer for WAYLAND_EVENT_OP_START */
|
||||||
#define WAYLAND_EVENT_OP_END(self)
|
#define WAYLAND_EVENT_OP_END(self)
|
||||||
|
|
|
||||||
|
|
@ -531,7 +531,9 @@ static void pointer_motion(void* data, struct wl_pointer* wl_pointer, MwU32 time
|
||||||
MwLL self = data;
|
MwLL self = data;
|
||||||
MwLL topmost_parent = self;
|
MwLL topmost_parent = self;
|
||||||
MwMouse p;
|
MwMouse p;
|
||||||
MwBool inArea = MwFALSE;
|
MwBool inArea = MwFALSE;
|
||||||
|
MwLL* currentlyHeldWidgets = NULL;
|
||||||
|
int i;
|
||||||
|
|
||||||
(void)time;
|
(void)time;
|
||||||
(void)wl_pointer;
|
(void)wl_pointer;
|
||||||
|
|
@ -539,6 +541,8 @@ static void pointer_motion(void* data, struct wl_pointer* wl_pointer, MwU32 time
|
||||||
WAYLAND_EVENT_OP_START(self);
|
WAYLAND_EVENT_OP_START(self);
|
||||||
while(topmost_parent->wayland.parent) topmost_parent = topmost_parent->wayland.parent;
|
while(topmost_parent->wayland.parent) topmost_parent = topmost_parent->wayland.parent;
|
||||||
|
|
||||||
|
currentlyHeldWidgets = topmost_parent->wayland.currentlyHeldWidgets;
|
||||||
|
|
||||||
if(self->wayland.framebuffer.surface) {
|
if(self->wayland.framebuffer.surface) {
|
||||||
inArea |= self->wayland.framebuffer.surface == curSurface;
|
inArea |= self->wayland.framebuffer.surface == curSurface;
|
||||||
}
|
}
|
||||||
|
|
@ -555,6 +559,19 @@ static void pointer_motion(void* data, struct wl_pointer* wl_pointer, MwU32 time
|
||||||
MwLLDispatch(self, move, &p);
|
MwLLDispatch(self, move, &p);
|
||||||
wl_pointer_set_cursor(self->wayland.pointer, self->wayland.pointer_serial, self->wayland.cursor.surface, 0, 0);
|
wl_pointer_set_cursor(self->wayland.pointer, self->wayland.pointer_serial, self->wayland.cursor.surface, 0, 0);
|
||||||
}
|
}
|
||||||
|
for(i = 0; i < arrlen(currentlyHeldWidgets); i++) {
|
||||||
|
MwLL new_topmost = currentlyHeldWidgets[i];
|
||||||
|
p.point = topmost_parent->wayland.cur_mouse_pos;
|
||||||
|
while(new_topmost->wayland.parent) {
|
||||||
|
p.point.x -= new_topmost->wayland.x;
|
||||||
|
p.point.y -= new_topmost->wayland.y;
|
||||||
|
new_topmost = new_topmost->wayland.parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
MwLLDispatch(currentlyHeldWidgets[i], move, &p);
|
||||||
|
}
|
||||||
|
|
||||||
|
MwLLWaylandCascadeChildren(self);
|
||||||
|
|
||||||
WAYLAND_EVENT_OP_END(self);
|
WAYLAND_EVENT_OP_END(self);
|
||||||
};
|
};
|
||||||
|
|
@ -598,7 +615,7 @@ static void mouse_dispatch(MwLL self, MwMouse p, MwU32 state) {
|
||||||
|
|
||||||
if(self->common.user) {
|
if(self->common.user) {
|
||||||
MwWidget w = self->common.user;
|
MwWidget w = self->common.user;
|
||||||
int i;
|
int i, n;
|
||||||
for(i = 0; i < arrlen(w->children); i++) {
|
for(i = 0; i < arrlen(w->children); i++) {
|
||||||
if(w->children[i]->lowlevel->wayland.type == MwLL_WAYLAND_SUBLEVEL) {
|
if(w->children[i]->lowlevel->wayland.type == MwLL_WAYLAND_SUBLEVEL) {
|
||||||
MwLL child = w->children[i]->lowlevel;
|
MwLL child = w->children[i]->lowlevel;
|
||||||
|
|
@ -624,9 +641,27 @@ static void mouse_dispatch(MwLL self, MwMouse p, MwU32 state) {
|
||||||
if(
|
if(
|
||||||
point.x >= absolute_pos.x && point.x <= absolute_pos.x + child->wayland.ww &&
|
point.x >= absolute_pos.x && point.x <= absolute_pos.x + child->wayland.ww &&
|
||||||
point.y >= absolute_pos.y && point.y <= absolute_pos.y + child->wayland.wh) {
|
point.y >= absolute_pos.y && point.y <= absolute_pos.y + child->wayland.wh) {
|
||||||
|
int idx = -1;
|
||||||
|
for(n = 0; n < arrlen(topmost_parent->wayland.currentlyHeldWidgets); n++) {
|
||||||
|
if(topmost_parent->wayland.currentlyHeldWidgets[n] == child) {
|
||||||
|
idx = n;
|
||||||
|
}
|
||||||
|
}
|
||||||
p.point = relative_mouse_pos;
|
p.point = relative_mouse_pos;
|
||||||
|
|
||||||
|
switch(state) {
|
||||||
|
case WL_POINTER_BUTTON_STATE_PRESSED:
|
||||||
|
if(idx == -1) {
|
||||||
|
arrpush(topmost_parent->wayland.currentlyHeldWidgets, child);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case WL_POINTER_BUTTON_STATE_RELEASED:
|
||||||
|
if(idx != -1) {
|
||||||
|
arrdel(topmost_parent->wayland.currentlyHeldWidgets, idx);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
mouse_dispatch(child, p, state);
|
mouse_dispatch(child, p, state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -638,12 +673,15 @@ static void mouse_dispatch(MwLL self, MwMouse p, MwU32 state) {
|
||||||
static void pointer_button(void* data, struct wl_pointer* wl_pointer, MwU32 serial, MwU32 time, MwU32 button, MwU32 state) {
|
static void pointer_button(void* data, struct wl_pointer* wl_pointer, MwU32 serial, MwU32 time, MwU32 button, MwU32 state) {
|
||||||
MwLL self = data;
|
MwLL self = data;
|
||||||
MwMouse p;
|
MwMouse p;
|
||||||
|
MwLL topmost_parent = self;
|
||||||
|
int i;
|
||||||
|
|
||||||
(void)wl_pointer;
|
(void)wl_pointer;
|
||||||
(void)serial;
|
(void)serial;
|
||||||
(void)time;
|
(void)time;
|
||||||
|
|
||||||
WAYLAND_EVENT_OP_START(self);
|
WAYLAND_EVENT_OP_START(self);
|
||||||
|
while(topmost_parent->wayland.parent) topmost_parent = topmost_parent->wayland.parent;
|
||||||
|
|
||||||
p.point = self->wayland.cur_mouse_pos;
|
p.point = self->wayland.cur_mouse_pos;
|
||||||
|
|
||||||
|
|
@ -667,6 +705,10 @@ static void pointer_button(void* data, struct wl_pointer* wl_pointer, MwU32 seri
|
||||||
MwLLDispatch(self, up, &p);
|
MwLLDispatch(self, up, &p);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for(i = 0; i < arrlen(self->wayland.currentlyHeldWidgets); i++) {
|
||||||
|
arrdel(self->wayland.currentlyHeldWidgets, i);
|
||||||
|
}
|
||||||
mouse_dispatch(self, p, state);
|
mouse_dispatch(self, p, state);
|
||||||
|
|
||||||
if(!self->wayland.has_decorations && self->wayland.do_csd) {
|
if(!self->wayland.has_decorations && self->wayland.do_csd) {
|
||||||
|
|
|
||||||
|
|
@ -12,39 +12,38 @@ MwBool MwWaylandVulkan = MwFALSE;
|
||||||
|
|
||||||
MwBool MwWaylandCairoOnly = MwFALSE;
|
MwBool MwWaylandCairoOnly = MwFALSE;
|
||||||
|
|
||||||
// static pthread_mutex_t destroyedWidgetsTableMutex;
|
static pthread_mutex_t destroyedWidgetsTableMutex;
|
||||||
// /*
|
// /*
|
||||||
// * So Wayland, bless its soul; it keeps using callbacks LONG after they should not only be destroyed but the widget doesn't even exist anymore. Naturally, this causes use after free. so we fight fire with fire in the worst code i've ever written: by storing the freed pointers here, we disallow wayland from ever using them again. if something else is created that takes this slot, we remove it from the table.
|
// * So Wayland, bless its soul; it keeps using callbacks LONG after they should not only be destroyed but the widget doesn't even exist anymore. Naturally, this causes use after free. so we fight fire with fire in the worst code i've ever written: by storing the freed pointers here, we disallow wayland from ever using them again. if something else is created that takes this slot, we remove it from the table.
|
||||||
// *
|
// *
|
||||||
// * To illustrate how bad this code is: if Israel and Palestine found out I was doing this then the Israel/Palestine conflict would be solved because both world leaders would come to the conclusion that this code is the worst thing ever.
|
// * To illustrate how bad this code is: if Israel and Palestine found out I was doing this then the Israel/Palestine conflict would be solved because both world leaders would come to the conclusion that this code is the worst thing ever.
|
||||||
// */
|
// */
|
||||||
// static MwLL* destroyedWidgetsTable;
|
static MwLL* destroyedWidgetsTable;
|
||||||
|
|
||||||
// MwBool MwLLWaylandWidgetIsDestroyed(MwLL self) {
|
MwBool MwLLWaylandWidgetIsDestroyed(MwLL self) {
|
||||||
// int i;
|
int i;
|
||||||
// pthread_mutex_lock(&destroyedWidgetsTableMutex);
|
pthread_mutex_lock(&destroyedWidgetsTableMutex);
|
||||||
// for(i = 0; i < arrlen(destroyedWidgetsTable); i++) {
|
for(i = 0; i < arrlen(destroyedWidgetsTable); i++) {
|
||||||
// if(self == destroyedWidgetsTable[i]) {
|
if(self == destroyedWidgetsTable[i]) {
|
||||||
// pthread_mutex_unlock(&destroyedWidgetsTableMutex);
|
pthread_mutex_unlock(&destroyedWidgetsTableMutex);
|
||||||
// return MwTRUE;
|
return MwTRUE;
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// pthread_mutex_unlock(&destroyedWidgetsTableMutex);
|
pthread_mutex_unlock(&destroyedWidgetsTableMutex);
|
||||||
// return MwFALSE;
|
return MwFALSE;
|
||||||
// }
|
}
|
||||||
// void MwLLWaylandWidgetUndestroy(MwLL self) {
|
void MwLLWaylandWidgetUndestroy(MwLL self) {
|
||||||
// int i;
|
int i;
|
||||||
// pthread_mutex_lock(&destroyedWidgetsTableMutex);
|
pthread_mutex_lock(&destroyedWidgetsTableMutex);
|
||||||
// for(i = 0; i < arrlen(destroyedWidgetsTable); i++) {
|
for(i = 0; i < arrlen(destroyedWidgetsTable); i++) {
|
||||||
// if(self == destroyedWidgetsTable[i]) {
|
if(self == destroyedWidgetsTable[i]) {
|
||||||
// arrdel(destroyedWidgetsTable, i);
|
arrdel(destroyedWidgetsTable, i);
|
||||||
// break;
|
break;
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// pthread_mutex_unlock(&destroyedWidgetsTableMutex);
|
pthread_mutex_unlock(&destroyedWidgetsTableMutex);
|
||||||
// return;
|
return;
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
|
|
||||||
void MwLLWaylandChildrenIterate(MwLL handle, void (*func)(MwLL handle, MwLL child)) {
|
void MwLLWaylandChildrenIterate(MwLL handle, void (*func)(MwLL handle, MwLL child)) {
|
||||||
if(handle->common.user) {
|
if(handle->common.user) {
|
||||||
|
|
@ -988,7 +987,7 @@ static void count_child(MwLL handle, MwLL child) {
|
||||||
handle->wayland.cascading_child_num++;
|
handle->wayland.cascading_child_num++;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cascade_children(MwLL handle) {
|
void MwLLWaylandCascadeChildren(MwLL handle) {
|
||||||
handle->wayland.cascading_child_num = 0;
|
handle->wayland.cascading_child_num = 0;
|
||||||
MwLLWaylandChildrenIterate(handle, count_child);
|
MwLLWaylandChildrenIterate(handle, count_child);
|
||||||
|
|
||||||
|
|
@ -1339,7 +1338,7 @@ static void MwLLEndDrawImpl(MwLL handle) {
|
||||||
}
|
}
|
||||||
MwLLWaylandBufferUpdate(handle, &handle->wayland.framebuffer);
|
MwLLWaylandBufferUpdate(handle, &handle->wayland.framebuffer);
|
||||||
|
|
||||||
cascade_children(handle);
|
MwLLWaylandCascadeChildren(handle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue