From 97ef5306a1c084b31766db58346e8a2ceed7a859 Mon Sep 17 00:00:00 2001 From: project-repo Date: Sun, 25 Sep 2022 11:05:51 +0200 Subject: [PATCH] Add ipc message on cursor switching tile --- output.c | 1 - seat.c | 31 +++++++++++++++++++++++++------ seat.h | 2 +- workspace.c | 4 ++++ 4 files changed, 30 insertions(+), 8 deletions(-) diff --git a/output.c b/output.c index b37001b..e815f90 100644 --- a/output.c +++ b/output.c @@ -371,7 +371,6 @@ output_make_workspace_fullscreen(struct cg_output *output,int ws) { struct cg_server *server=output->server; struct cg_view *current_view = seat_get_focus(server->seat); - /* We are focused on the background */ if(current_view == NULL||ws != output->curr_workspace) { struct cg_view *it = NULL; wl_list_for_each(it, &output->workspaces[ws]->views, diff --git a/seat.c b/seat.c index 167ec82..976f6fc 100644 --- a/seat.c +++ b/seat.c @@ -634,6 +634,31 @@ process_cursor_motion(struct cg_seat *seat, uint32_t time) { } wlr_idle_notify_activity(seat->server->idle, seat->seat); + + /* Check if cursor switched tile */ + struct wlr_output *c_outp = wlr_output_layout_output_at(seat->server->output_layout,seat->cursor->x,seat->cursor->y); + struct cg_output *cg_outp = NULL; + wl_list_for_each(cg_outp,&seat->server->outputs,link) { + if(cg_outp->wlr_output == c_outp) { + 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(seat->cursor_tile != NULL && seat->cursor_tile != c_tile) { + ipc_send_event(seat->server, "{\"event_name\":\"cursor_switch_tile\",\"old_output\":\"%s\",\"old_tile\":\"%d\",\"new_output\":\"%s\",\"new_tile\":\"%d\"}", + seat->cursor_tile->workspace->output->wlr_output->name, seat->cursor_tile->id,c_outp->name,c_tile->id); + } + seat->cursor_tile=c_tile; } static void @@ -656,12 +681,6 @@ handle_cursor_motion(struct wl_listener *listener, void *data) { event->delta_y); process_cursor_motion(seat, event->time_msec); wlr_idle_notify_activity(seat->server->idle, seat->seat); - struct wlr_output *c_outp = wlr_output_layout_output_at(seat->server->output_layout,seat->cursor->x,seat->cursor->y); - if(seat->cursor_output != NULL && seat->cursor_output != c_outp) { - ipc_send_event(seat->server, "{\"event_name\":\"cursor_switch_output\",\"old_output\":\"%s\",\"new_output\":\"%s\"}", - seat->cursor_output->name, c_outp->name); - } - seat->cursor_output=c_outp; } static void diff --git a/seat.h b/seat.h index 66474b6..32ef586 100644 --- a/seat.h +++ b/seat.h @@ -28,7 +28,7 @@ struct cg_seat { uint16_t num_touch; struct wlr_cursor *cursor; - struct wlr_output *cursor_output; + struct cg_tile *cursor_tile; struct wlr_xcursor_manager *xcursor_manager; struct wl_listener cursor_motion; struct wl_listener cursor_motion_absolute; diff --git a/workspace.c b/workspace.c index 53554d6..7bfe929 100644 --- a/workspace.c +++ b/workspace.c @@ -16,6 +16,7 @@ #include #include "message.h" +#include "seat.h" #include "output.h" #include "server.h" #include "workspace.h" @@ -90,6 +91,9 @@ void workspace_free_tiles(struct cg_workspace *workspace) { workspace->focused_tile->prev->next = NULL; while(workspace->focused_tile != NULL) { + if(workspace->output->server->running&&workspace->output->server->seat->cursor_tile==workspace->focused_tile) { + workspace->output->server->seat->cursor_tile=NULL; + } struct cg_tile *next = workspace->focused_tile->next; free(workspace->focused_tile); workspace->focused_tile = next;