Skip to content

Commit

Permalink
Fix issue in window_OnMoved
Browse files Browse the repository at this point in the history
  • Loading branch information
frang75 committed Dec 29, 2023
1 parent 294475f commit 9873420
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 27 deletions.
2 changes: 2 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@
* GTK3 focus a control when NO tabstops in window.
* GTK3 issue in TextView editable.
* GTK3 get screen resolution.
* window_OnMoved crash on macOS.
* window_OnMoved GTK implementation.

### Removed

Expand Down
10 changes: 10 additions & 0 deletions demo/drawbig/drawbig.c
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,15 @@ static Panel *i_panel(App *app)

/*---------------------------------------------------------------------------*/

static void i_OnMoved(App *app, Event *e)
{
const EvPos *p = event_params(e, EvPos);
bstd_printf("Window moved: (%d, %d)\n", (uint32_t)p->x, (uint32_t)p->y);
unref(app);
}

/*---------------------------------------------------------------------------*/

static void i_OnClose(App *app, Event *e)
{
osapp_finish();
Expand Down Expand Up @@ -413,6 +422,7 @@ static App *i_create(void)
window_panel(app->window, panel);
window_title(app->window, "Big drawing area");
window_origin(app->window, v2df(500, 200));
window_OnMoved(app->window, listener(app, i_OnMoved, App));
window_OnClose(app->window, listener(app, i_OnClose, App));
window_show(app->window);
i_scroll_to_cell(app);
Expand Down
2 changes: 1 addition & 1 deletion prj/build.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4766
4770
32 changes: 28 additions & 4 deletions src/gui/window.c
Original file line number Diff line number Diff line change
Expand Up @@ -350,12 +350,36 @@ void window_panel(Window *window, Panel *panel)

/*---------------------------------------------------------------------------*/

static void i_update_listener(
Window *window,
Listener **listener,
Listener *new_listener,
FPtr_event_handler func_event_handler,
FPtr_gctx_set_listener func_set_listener)
{
Listener *renderable_listener = NULL;
cassert_no_null(window);
cassert_no_null(listener);
cassert_no_nullf(func_set_listener);

if (new_listener != NULL)
{
cassert_no_nullf(func_event_handler);
renderable_listener = obj_listener_imp(window, func_event_handler);
}

func_set_listener(window->ositem, renderable_listener);
listener_update(listener, new_listener);
}

/*---------------------------------------------------------------------------*/

void window_OnMoved(Window *window, Listener *listener)
{
component_update_listener(
window, &window->OnMoved, listener, i_OnWindowMoved,
window->context->func_window_OnMoved,
Window);
i_update_listener(
window, &window->OnMoved, listener,
(FPtr_event_handler)i_OnWindowMoved,
window->context->func_window_OnMoved);
}

/*---------------------------------------------------------------------------*/
Expand Down
1 change: 0 additions & 1 deletion src/osapp/osx/osapp_osx.m
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ - (void)applicationDidFinishLaunching:(NSNotification*)aNotification
[[NSRunLoop currentRunLoop] addTimer:timer forMode:NSModalPanelRunLoopMode];
}


#if defined (MAC_OS_X_VERSION_10_9) && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_9
[NSDistributedNotificationCenter.defaultCenter addObserver:self selector:@selector(themeChanged:) name:@"AppleInterfaceThemeChangedNotification" object: nil];
#endif
Expand Down
14 changes: 11 additions & 3 deletions src/osgui/gtk3/oswindow.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,15 @@ static gboolean i_OnConfigure(GtkWidget *widget, GdkEventConfigure *event, OSWin
/* Window dimensions have not changed */
else
{
/* When window is moved dragging the titlebar */
if (window->OnMoved != NULL)
{
EvPos p;
p.x = (real32_t)event->x;
p.y = (real32_t)event->y;
listener_event(window->OnMoved, ekGUI_EVENT_WND_MOVED, window, &p, NULL, OSWindow, EvPos, void);
}

/* When window is moved dragging the titlebar, the focus is lost */
ostabstop_restore(&window->tabstop);
}
Expand Down Expand Up @@ -374,9 +383,8 @@ void oswindow_destroy(OSWindow **window)

void oswindow_OnMoved(OSWindow *window, Listener *listener)
{
unref(window);
unref(listener);
cassert(FALSE);
cassert_no_null(window);
listener_update(&window->OnMoved, listener);
}

/*---------------------------------------------------------------------------*/
Expand Down
27 changes: 9 additions & 18 deletions src/osgui/osx/oswindow.m
Original file line number Diff line number Diff line change
Expand Up @@ -112,20 +112,9 @@ - (void)windowDidBecomeKey:(NSNotification*)notification

/*---------------------------------------------------------------------------*/

- (void)windowWillMove:(NSNotification*)notification
{
OSXWindow *window;
window = [notification object];
cassert_no_null(window);
window->last_moved_by_interface = NO;
}

/*---------------------------------------------------------------------------*/

- (void)windowDidMove:(NSNotification*)notification
{
OSXWindow *window;
window = [notification object];
OSXWindow *window = [notification object];
cassert_no_null(window);
if (self->OnMoved != NULL && window->last_moved_by_interface == NO)
{
Expand All @@ -139,7 +128,7 @@ - (void)windowDidMove:(NSNotification*)notification
listener_event(self->OnMoved, ekGUI_EVENT_WND_MOVED, (OSWindow*)window, &params, NULL, OSWindow, EvPos, void);
}

window->last_moved_by_interface = YES;
window->last_moved_by_interface = NO;
}

/*---------------------------------------------------------------------------*/
Expand Down Expand Up @@ -350,7 +339,7 @@ -(BOOL)processKeyDown:(NSEvent*)theEvent
{
if (i_close([self delegate], self, ekGUI_CLOSE_INTRO) == TRUE)
[self orderOut:nil];

return YES;
}

Expand Down Expand Up @@ -442,7 +431,7 @@ static NSUInteger i_window_style_mask(const uint32_t flags)
window->origin.y = 0.f;
window->in_window_destroy = NO;
window->destroy_main_view = YES;
window->last_moved_by_interface = YES;
window->last_moved_by_interface = NO;
window->launch_resize_event = YES;
window->flags = flags;
window->alpha = .5f;
Expand Down Expand Up @@ -494,7 +483,7 @@ void oswindow_destroy(OSWindow **window)

if (windowp->text_editor != nil)
[windowp->text_editor release];

if (windowp->destroy_main_view == YES)
{
OSPanel *panel = (OSPanel*)[windowp contentView];
Expand Down Expand Up @@ -893,15 +882,17 @@ void oswindow_get_origin(const OSWindow *window, real32_t *x, real32_t *y)

void oswindow_origin(OSWindow *window, const real32_t x, const real32_t y)
{
OSXWindow *windowp = (OSXWindow*)window;
NSRect window_frame;
NSPoint origin;
cassert_no_null(window);
cassert([(NSResponder*)window isKindOfClass:[OSXWindow class]] == YES);
window_frame = [(OSXWindow*)window frame];
window_frame = [windowp frame];
window_frame.origin.x = (CGFloat)x;
window_frame.origin.y = (CGFloat)y;
_oscontrol_origin_in_screen_coordinates(&window_frame, &origin.x, &origin.y);
[(OSXWindow*)window setFrameOrigin:origin];
windowp->last_moved_by_interface = YES;
[(OSXWindow*)windowp setFrameOrigin:origin];
}

/*---------------------------------------------------------------------------*/
Expand Down

0 comments on commit 9873420

Please sign in to comment.