view: check view->impl functions exist before using

Avoids segfault when using disappearing notification in Thunderbird
This commit is contained in:
Johan Malm 2021-10-18 19:35:41 +01:00
parent 846ccb9eb9
commit 40da2f34a5
2 changed files with 20 additions and 13 deletions

View file

@ -79,7 +79,7 @@ process_cursor_move(struct server *server, uint32_t time)
struct view *view = server->grabbed_view; struct view *view = server->grabbed_view;
/* Move the grabbed view to the new position. */ /* Move the grabbed view to the new position. */
view->impl->move(view, server->grab_box.x + dx, server->grab_box.y + dy); view_move(view, server->grab_box.x + dx, server->grab_box.y + dy);
} }
static void static void

View file

@ -19,14 +19,18 @@ view_set_activated(struct view *view, bool activated)
void void
view_move_resize(struct view *view, struct wlr_box geo) view_move_resize(struct view *view, struct wlr_box geo)
{ {
view->impl->configure(view, geo); if (view->impl->configure) {
view->impl->configure(view, geo);
}
ssd_update_title(view); ssd_update_title(view);
} }
void void
view_move(struct view *view, double x, double y) view_move(struct view *view, double x, double y)
{ {
view->impl->move(view, x, y); if (view->impl->move) {
view->impl->move(view, x, y);
}
} }
#define MIN_VIEW_WIDTH (100) #define MIN_VIEW_WIDTH (100)
@ -112,7 +116,9 @@ view_maximize(struct view *view, bool maximize)
if (view->maximized == maximize) { if (view->maximized == maximize) {
return; return;
} }
view->impl->maximize(view, maximize); if (view->impl->maximize) {
view->impl->maximize(view, maximize);
}
if (view->toplevel_handle) { if (view->toplevel_handle) {
wlr_foreign_toplevel_handle_v1_set_maximized(view->toplevel_handle, wlr_foreign_toplevel_handle_v1_set_maximized(view->toplevel_handle,
maximize); maximize);
@ -207,17 +213,18 @@ void
view_for_each_surface(struct view *view, wlr_surface_iterator_func_t iterator, view_for_each_surface(struct view *view, wlr_surface_iterator_func_t iterator,
void *user_data) void *user_data)
{ {
view->impl->for_each_surface(view, iterator, user_data); if (view->impl->for_each_surface) {
view->impl->for_each_surface(view, iterator, user_data);
}
} }
void void
view_for_each_popup_surface(struct view *view, wlr_surface_iterator_func_t iterator, view_for_each_popup_surface(struct view *view,
void *data) wlr_surface_iterator_func_t iterator, void *data)
{ {
if (!view->impl->for_each_popup_surface) { if (view->impl->for_each_popup_surface) {
return; view->impl->for_each_popup_surface(view, iterator, data);
} }
view->impl->for_each_popup_surface(view, iterator, data);
} }
static struct border static struct border
@ -242,8 +249,8 @@ view_move_to_edge(struct view *view, const char *direction)
struct output *output = view_output(view); struct output *output = view_output(view);
if (!output) { if (!output) {
wlr_log(WLR_ERROR, "no output"); wlr_log(WLR_ERROR, "no output");
return; return;
} }
struct border border = view_border(view); struct border border = view_border(view);
struct wlr_box usable = output_usable_area_in_layout_coords(output); struct wlr_box usable = output_usable_area_in_layout_coords(output);
@ -376,7 +383,7 @@ view_snap_to_edge(struct view *view, const char *direction)
case VIEW_EDGE_DOWN: dst.y += (usable.height / 2) + 1; break; case VIEW_EDGE_DOWN: dst.y += (usable.height / 2) + 1; break;
default: break; default: break;
} }
struct output *new_output = struct output *new_output =
output_from_wlr_output(view->server, output_from_wlr_output(view->server,
wlr_output_layout_output_at(view->server->output_layout, dst.x, dst.y)); wlr_output_layout_output_at(view->server->output_layout, dst.x, dst.y));