From d3725d8032497e8f3e526e88022f2eeee22fd62e Mon Sep 17 00:00:00 2001 From: project-repo Date: Wed, 27 Dec 2023 16:54:17 +0100 Subject: [PATCH] Fix potential NPD on cursor move. --- seat.c | 56 +++++++++++++++++++++++++++++--------------------------- 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/seat.c b/seat.c index f626481..55eb704 100644 --- a/seat.c +++ b/seat.c @@ -731,35 +731,37 @@ process_cursor_motion(struct cg_seat *seat, uint32_t time) { break; } } - struct cg_tile *c_tile; - bool first = true; - for(c_tile = cg_outp->workspaces[cg_outp->curr_workspace]->focused_tile; - first || - c_tile != cg_outp->workspaces[cg_outp->curr_workspace]->focused_tile; - c_tile = c_tile->next) { - first = false; - double ox = seat->cursor->x, oy = seat->cursor->y; - wlr_output_layout_output_coords(seat->server->output_layout, c_outp, - &ox, &oy); - if(c_tile->tile.x <= ox && c_tile->tile.y <= oy && - c_tile->tile.x + c_tile->tile.width >= ox && - c_tile->tile.y + c_tile->tile.height >= oy) { - break; + if(c_outp) { + struct cg_tile *c_tile; + bool first = true; + for(c_tile = cg_outp->workspaces[cg_outp->curr_workspace]->focused_tile; + first || + c_tile != cg_outp->workspaces[cg_outp->curr_workspace]->focused_tile; + c_tile = c_tile->next) { + first = false; + double ox = seat->cursor->x, oy = seat->cursor->y; + wlr_output_layout_output_coords(seat->server->output_layout, c_outp, + &ox, &oy); + if(c_tile->tile.x <= ox && c_tile->tile.y <= oy && + c_tile->tile.x + c_tile->tile.width >= ox && + c_tile->tile.y + c_tile->tile.height >= oy) { + break; + } } + if(seat->cursor_tile != NULL && seat->cursor_tile != c_tile && + seat->server->running) { + ipc_send_event(seat->server, + "{\"event_name\":\"cursor_switch_tile\",\"old_output\":" + "\"%s\",\"old_output_id\":%d," + "\"old_tile\":%d,\"new_output\":\"%s\",\"new_output_" + "id\":%d,\"new_tile\":%d}", + seat->cursor_tile->workspace->output->name, + output_get_num(seat->cursor_tile->workspace->output), + seat->cursor_tile->id, c_outp->name, + output_get_num(cg_outp), c_tile->id); + } + seat->cursor_tile = c_tile; } - if(seat->cursor_tile != NULL && seat->cursor_tile != c_tile && - seat->server->running) { - ipc_send_event(seat->server, - "{\"event_name\":\"cursor_switch_tile\",\"old_output\":" - "\"%s\",\"old_output_id\":%d," - "\"old_tile\":%d,\"new_output\":\"%s\",\"new_output_" - "id\":%d,\"new_tile\":%d}", - seat->cursor_tile->workspace->output->name, - output_get_num(seat->cursor_tile->workspace->output), - seat->cursor_tile->id, c_outp->name, - output_get_num(cg_outp), c_tile->id); - } - seat->cursor_tile = c_tile; } static void