Skip to content

Commit

Permalink
simplify xid resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
MoAlyousef committed Jul 19, 2024
1 parent 37eaab1 commit 8c0bd81
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 22 deletions.
7 changes: 1 addition & 6 deletions include/cfl_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@
extern "C" {
#endif

typedef union {
unsigned long x_id;
void *opaque;
} winid;

#define WINDOW_DECLARE(widget) \
void widget##_make_modal(widget *, unsigned int boolean); \
void widget##_fullscreen(widget *, unsigned int boolean); \
Expand Down Expand Up @@ -70,7 +65,7 @@ Fl_Window *Fl_Window_new_wh(int width, int height, const char *title);

Fl_Window *Fl_Window_find_by_handle(void *handle);

winid resolve_raw_handle(void *handle);
void *resolve_raw_handle(void *handle);

void *Fl_display(void);

Expand Down
24 changes: 8 additions & 16 deletions src/cfl_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,8 @@ struct Window_Derived : public Widget_Derived<Win> {
return ret; \
} \
void *widget##_raw_handle(const widget *w) { \
LOCK(Window temp = fl_xid(w); \
if (!temp) { return nullptr; } auto *xid = new Window; \
if (!xid) return nullptr; \
memcpy(xid, &temp, sizeof(Window))); \
return xid; \
LOCK(void *temp = (void *)fl_xid(w)); \
return temp; \
} \
void widget##_set_border(widget *self, int flag) { \
LOCK(self->border(flag)); \
Expand Down Expand Up @@ -300,18 +297,13 @@ Fl_Window *Fl_Window_find_by_handle(void *handle) {
return ret;
}

winid resolve_raw_handle(void *handle) {
winid w;
#if defined(_WIN32) || defined(__APPLE__) || defined(__ANDROID__)
w.opaque = *(Window *)handle;
#elif defined(FLTK_USE_WAYLAND)
void *resolve_raw_handle(void *handle) {
void *ret = handle;
#if defined(FLTK_USE_WAYLAND)
auto h = fl_wl_surface((wld_window *)(*(Window *)handle));
w.opaque = h;
#else
w.x_id = *(Window *)handle;
ret = h;
#endif
delete (Window *)handle;
return w;
return ret;
}

void *Fl_display(void) {
Expand Down Expand Up @@ -340,7 +332,7 @@ void Fl_Window_set_raw_handle(Fl_Window *self, void *handle) {
return;
#if !defined(_WIN32) && !defined(__APPLE__) && !defined(__ANDROID__) && \
!defined(FLTK_USE_WAYLAND)
LOCK(Fl_X::set_xid(self, *(Window *)handle));
LOCK(Fl_X::set_xid(self, (Window )handle));
#else
// LOCK(Fl_X *xp = new Fl_X; if (!xp) return; Window h = *(Window
// *)handle; xp->xid = h;
Expand Down

0 comments on commit 8c0bd81

Please sign in to comment.