diff options
-rw-r--r-- | include/sway/input/cursor.h | 2 | ||||
-rw-r--r-- | sway/commands/seat/cursor.c | 16 | ||||
-rw-r--r-- | sway/desktop/xwayland.c | 5 | ||||
-rw-r--r-- | sway/input/cursor.c | 18 | ||||
-rw-r--r-- | sway/input/seat.c | 8 | ||||
-rw-r--r-- | swaybar/bar.c | 18 | ||||
-rw-r--r-- | swaybar/event_loop.c | 42 |
7 files changed, 63 insertions, 46 deletions
diff --git a/include/sway/input/cursor.h b/include/sway/input/cursor.h index fcd94437..20c1c903 100644 --- a/include/sway/input/cursor.h +++ b/include/sway/input/cursor.h @@ -29,7 +29,7 @@ struct sway_cursor { void sway_cursor_destroy(struct sway_cursor *cursor); struct sway_cursor *sway_cursor_create(struct sway_seat *seat); -void cursor_send_pointer_motion(struct sway_cursor *cursor, uint32_t time); +void cursor_send_pointer_motion(struct sway_cursor *cursor, uint32_t time_msec); void dispatch_cursor_button(struct sway_cursor *cursor, uint32_t time_msec, uint32_t button, enum wlr_button_state state); diff --git a/sway/commands/seat/cursor.c b/sway/commands/seat/cursor.c index 5dad97f1..929384b0 100644 --- a/sway/commands/seat/cursor.c +++ b/sway/commands/seat/cursor.c @@ -11,7 +11,7 @@ #include "sway/input/cursor.h" static struct cmd_results *press_or_release(struct sway_cursor *cursor, - char *action, char *button_str, uint32_t time); + char *action, char *button_str); static const char *expected_syntax = "Expected 'cursor <move> <x> <y>' or " "'cursor <set> <x> <y>' or " @@ -29,10 +29,6 @@ struct cmd_results *seat_cmd_cursor(int argc, char **argv) { struct sway_cursor *cursor = seat->cursor; - struct timespec now; - clock_gettime(CLOCK_MONOTONIC, &now); - uint32_t time = now.tv_nsec / 1000; - if (strcasecmp(argv[0], "move") == 0) { if (argc < 3) { return cmd_results_new(CMD_INVALID, "cursor", expected_syntax); @@ -40,7 +36,7 @@ struct cmd_results *seat_cmd_cursor(int argc, char **argv) { int delta_x = strtol(argv[1], NULL, 10); int delta_y = strtol(argv[2], NULL, 10); wlr_cursor_move(cursor->cursor, NULL, delta_x, delta_y); - cursor_send_pointer_motion(cursor, time); + cursor_send_pointer_motion(cursor, 0); } else if (strcasecmp(argv[0], "set") == 0) { if (argc < 3) { return cmd_results_new(CMD_INVALID, "cursor", expected_syntax); @@ -49,12 +45,12 @@ struct cmd_results *seat_cmd_cursor(int argc, char **argv) { float x = strtof(argv[1], NULL) / root_container.width; float y = strtof(argv[2], NULL) / root_container.height; wlr_cursor_warp_absolute(cursor->cursor, NULL, x, y); - cursor_send_pointer_motion(cursor, time); + cursor_send_pointer_motion(cursor, 0); } else { if (argc < 2) { return cmd_results_new(CMD_INVALID, "cursor", expected_syntax); } - if ((error = press_or_release(cursor, argv[0], argv[1], time))) { + if ((error = press_or_release(cursor, argv[0], argv[1]))) { return error; } } @@ -63,7 +59,7 @@ struct cmd_results *seat_cmd_cursor(int argc, char **argv) { } static struct cmd_results *press_or_release(struct sway_cursor *cursor, - char *action, char *button_str, uint32_t time) { + char *action, char *button_str) { enum wlr_button_state state; uint32_t button; if (strcasecmp(action, "press") == 0) { @@ -84,6 +80,6 @@ static struct cmd_results *press_or_release(struct sway_cursor *cursor, return cmd_results_new(CMD_INVALID, "cursor", expected_syntax); } } - dispatch_cursor_button(cursor, time, button, state); + dispatch_cursor_button(cursor, 0, button, state); return cmd_results_new(CMD_SUCCESS, NULL, NULL); } diff --git a/sway/desktop/xwayland.c b/sway/desktop/xwayland.c index 46eaa84c..cad9156d 100644 --- a/sway/desktop/xwayland.c +++ b/sway/desktop/xwayland.c @@ -257,11 +257,6 @@ static void handle_map(struct wl_listener *listener, void *data) { static void handle_destroy(struct wl_listener *listener, void *data) { struct sway_xwayland_view *xwayland_view = wl_container_of(listener, xwayland_view, destroy); - struct sway_view *view = &xwayland_view->view; - struct wlr_xwayland_surface *xsurface = view->wlr_xwayland_surface; - if (xsurface->mapped) { - handle_unmap(&xwayland_view->unmap, xsurface); - } view_destroy(&xwayland_view->view); } diff --git a/sway/input/cursor.c b/sway/input/cursor.c index 5ed4f1f7..831109dc 100644 --- a/sway/input/cursor.c +++ b/sway/input/cursor.c @@ -15,6 +15,12 @@ #include "sway/tree/workspace.h" #include "wlr-layer-shell-unstable-v1-protocol.h" +static uint32_t get_current_time_msec() { + struct timespec now; + clock_gettime(CLOCK_MONOTONIC, &now); + return now.tv_nsec / 1000; +} + static struct wlr_surface *layer_surface_at(struct sway_output *output, struct wl_list *layer, double ox, double oy, double *sx, double *sy) { struct sway_layer_surface *sway_layer; @@ -128,7 +134,11 @@ static struct sway_container *container_at_cursor(struct sway_cursor *cursor, return output->swayc; } -void cursor_send_pointer_motion(struct sway_cursor *cursor, uint32_t time) { +void cursor_send_pointer_motion(struct sway_cursor *cursor, uint32_t time_msec) { + if (time_msec == 0) { + time_msec = get_current_time_msec(); + } + struct wlr_seat *seat = cursor->seat->wlr_seat; struct wlr_surface *surface = NULL; double sx, sy; @@ -152,7 +162,7 @@ void cursor_send_pointer_motion(struct sway_cursor *cursor, uint32_t time) { if (surface != NULL) { if (seat_is_input_allowed(cursor->seat, surface)) { wlr_seat_pointer_notify_enter(seat, surface, sx, sy); - wlr_seat_pointer_notify_motion(seat, time, sx, sy); + wlr_seat_pointer_notify_motion(seat, time_msec, sx, sy); } } else { wlr_seat_pointer_clear_focus(seat); @@ -178,6 +188,10 @@ static void handle_cursor_motion_absolute( void dispatch_cursor_button(struct sway_cursor *cursor, uint32_t time_msec, uint32_t button, enum wlr_button_state state) { + if (time_msec == 0) { + time_msec = get_current_time_msec(); + } + struct wlr_surface *surface = NULL; double sx, sy; struct sway_container *cont = diff --git a/sway/input/seat.c b/sway/input/seat.c index 631a273f..d1fc62c4 100644 --- a/sway/input/seat.c +++ b/sway/input/seat.c @@ -550,9 +550,7 @@ void seat_set_focus_warp(struct sway_seat *seat, wlr_output, seat->cursor->cursor->x, seat->cursor->cursor->y)) { wlr_cursor_warp(seat->cursor->cursor, NULL, x, y); - struct timespec now; - clock_gettime(CLOCK_MONOTONIC, &now); - cursor_send_pointer_motion(seat->cursor, now.tv_nsec / 1000); + cursor_send_pointer_motion(seat->cursor, 0); } } } @@ -565,9 +563,7 @@ void seat_set_focus_warp(struct sway_seat *seat, } if (last_workspace && last_workspace != new_workspace) { - struct timespec now; - clock_gettime(CLOCK_MONOTONIC, &now); - cursor_send_pointer_motion(seat->cursor, now.tv_nsec / 1000); + cursor_send_pointer_motion(seat->cursor, 0); } seat->has_focus = (container != NULL); diff --git a/swaybar/bar.c b/swaybar/bar.c index d51c4ec7..669cb11a 100644 --- a/swaybar/bar.c +++ b/swaybar/bar.c @@ -401,24 +401,28 @@ void bar_setup(struct swaybar *bar, render_all_frames(bar); } -static void display_in(int fd, short mask, void *_bar) { - struct swaybar *bar = (struct swaybar *)_bar; +static void display_in(int fd, short mask, void *data) { + struct swaybar *bar = data; if (wl_display_dispatch(bar->display) == -1) { bar_teardown(bar); exit(0); } } -static void ipc_in(int fd, short mask, void *_bar) { - struct swaybar *bar = (struct swaybar *)_bar; +static void ipc_in(int fd, short mask, void *data) { + struct swaybar *bar = data; if (handle_ipc_readable(bar)) { render_all_frames(bar); } } -static void status_in(int fd, short mask, void *_bar) { - struct swaybar *bar = (struct swaybar *)_bar; - if (status_handle_readable(bar->status)) { +static void status_in(int fd, short mask, void *data) { + struct swaybar *bar = data; + if (mask & (POLLHUP | POLLERR)) { + status_error(bar->status, "[error reading from status command]"); + render_all_frames(bar); + remove_event(fd); + } else if (status_handle_readable(bar->status)) { render_all_frames(bar); } } diff --git a/swaybar/event_loop.c b/swaybar/event_loop.c index 748372ed..bc4053be 100644 --- a/swaybar/event_loop.c +++ b/swaybar/event_loop.c @@ -72,24 +72,18 @@ void add_event(int fd, short mask, } bool remove_event(int fd) { - int index = -1; + /* + * Instead of removing events immediately, we mark them for deletion + * and clean them up later. This is so we can call remove_event inside + * an event callback safely. + */ for (int i = 0; i < event_loop.fds.length; ++i) { if (event_loop.fds.items[i].fd == fd) { - index = i; + event_loop.fds.items[i].fd = -1; + return true; } } - if (index != -1) { - free(event_loop.items->items[index]); - - --event_loop.fds.length; - memmove(&event_loop.fds.items[index], &event_loop.fds.items[index + 1], - sizeof(struct pollfd) * event_loop.fds.length - index); - - list_del(event_loop.items, index); - return true; - } else { - return false; - } + return false; } static int timer_item_timer_cmp(const void *_timer_item, const void *_timer) { @@ -118,11 +112,29 @@ void event_loop_poll() { struct pollfd pfd = event_loop.fds.items[i]; struct event_item *item = (struct event_item *)event_loop.items->items[i]; - if (pfd.revents & pfd.events) { + // Always send these events + unsigned events = pfd.events | POLLHUP | POLLERR; + + if (pfd.revents & events) { item->cb(pfd.fd, pfd.revents, item->data); } } + // Cleanup removed events + int end = 0; + int length = event_loop.fds.length; + for (int i = 0; i < length; ++i) { + if (event_loop.fds.items[i].fd == -1) { + free(event_loop.items->items[i]); + list_del(event_loop.items, i); + --event_loop.fds.length; + } else if (end != i) { + event_loop.fds.items[end++] = event_loop.fds.items[i]; + } else { + end = i + 1; + } + } + // check timers // not tested, but seems to work for (int i = 0; i < event_loop.timers->length; ++i) { |