aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2020-02-29 11:52:55 +0000
committerDaniel Eklöf <daniel@ekloef.se>2020-02-29 11:56:04 +0000
commit43b07b122a1fa460bdda3edc529726e3b6a6463d (patch)
tree860825ca093fc4db1e58634ebc8acf4cb9442700
parentwayland: remove all usages of wayl_terminal_from_surface() (diff)
input: csd: add a small delay before initiating a move
This ensures the user has time to double-click to toggle the maximized state.
-rw-r--r--input.c41
-rw-r--r--wayland.c4
-rw-r--r--wayland.h3
3 files changed, 43 insertions, 5 deletions
diff --git a/input.c b/input.c
index a7a78a5d..1db3541f 100644
--- a/input.c
+++ b/input.c
@@ -8,6 +8,7 @@
#include <sys/mman.h>
#include <sys/time.h>
#include <sys/timerfd.h>
+#include <sys/epoll.h>
#include <linux/input-event-codes.h>
@@ -833,6 +834,19 @@ wl_pointer_motion(void *data, struct wl_pointer *wl_pointer,
term, wayl->mouse.button, wayl->mouse.row, wayl->mouse.col);
}
+static bool
+fdm_csd_move(struct fdm *fdm, int fd, int events, void *data)
+{
+ struct wl_window *win = data;
+ struct wayland *wayl = win->term->wl;
+
+ fdm_del(fdm, fd);
+ win->csd.move_timeout_fd = -1;
+
+ xdg_toplevel_move(win->xdg_toplevel, wayl->seat, win->csd.serial);
+ return true;
+}
+
static void
wl_pointer_button(void *data, struct wl_pointer *wl_pointer,
uint32_t serial, uint32_t time, uint32_t button, uint32_t state)
@@ -891,16 +905,33 @@ wl_pointer_button(void *data, struct wl_pointer *wl_pointer,
case TERM_SURF_TITLE:
if (state == WL_POINTER_BUTTON_STATE_PRESSED) {
+ struct wl_window *win = term->window;
+
/* Toggle maximized state on double-click */
if (button == BTN_LEFT && wayl->mouse.count == 2) {
- if (term->window->is_maximized)
- xdg_toplevel_unset_maximized(term->window->xdg_toplevel);
+ if (win->is_maximized)
+ xdg_toplevel_unset_maximized(win->xdg_toplevel);
else
- xdg_toplevel_set_maximized(term->window->xdg_toplevel);
+ xdg_toplevel_set_maximized(win->xdg_toplevel);
}
- else if (button == BTN_LEFT)
- xdg_toplevel_move(term->window->xdg_toplevel, term->wl->seat, serial);
+ else if (button == BTN_LEFT && win->csd.move_timeout_fd == -1) {
+ const struct itimerspec timeout = {
+ .it_value = {.tv_nsec = 100000000},
+ };
+
+ int fd = timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC | TFD_NONBLOCK);
+ if (fd >= 0 &&
+ timerfd_settime(fd, 0, &timeout, NULL) == 0 &&
+ fdm_add(wayl->fdm, fd, EPOLLIN, &fdm_csd_move, win))
+ {
+ win->csd.move_timeout_fd = fd;
+ win->csd.serial = serial;
+ } else {
+ LOG_ERRNO("failed to configure XDG toplevel move timer FD");
+ close(fd);
+ }
+ }
}
return;
diff --git a/wayland.c b/wayland.c
index 5d3a30df..7322a32f 100644
--- a/wayland.c
+++ b/wayland.c
@@ -1014,6 +1014,7 @@ wayl_win_init(struct terminal *term)
struct wl_window *win = calloc(1, sizeof(*win));
win->term = term;
win->use_csd = CSD_UNKNOWN;
+ win->csd.move_timeout_fd = -1;
win->surface = wl_compositor_create_surface(wayl->compositor);
if (win->surface == NULL) {
@@ -1072,6 +1073,9 @@ wayl_win_destroy(struct wl_window *win)
if (win == NULL)
return;
+ if (win->csd.move_timeout_fd != -1)
+ close(win->csd.move_timeout_fd);
+
/*
* First, unmap all surfaces to trigger things like
* keyboard_leave() and wl_pointer_leave().
diff --git a/wayland.h b/wayland.h
index a18b40a3..4d73be42 100644
--- a/wayland.h
+++ b/wayland.h
@@ -106,6 +106,9 @@ struct wl_window {
struct wl_surface *surface[5];
struct wl_subsurface *sub_surface[5];
int x, y;
+
+ int move_timeout_fd;
+ uint32_t serial;
} csd;
/* Scrollback search */