Skip to content

Commit ccec906

Browse files
author
ArenM
committed
WIP: Make a tap on a windows title bar focus it
This is my first attempt, which is basically a simplified copy of the mouse down even handling
1 parent d772471 commit ccec906

File tree

4 files changed

+41
-0
lines changed

4 files changed

+41
-0
lines changed

include/sway/input/seat.h

+3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ struct sway_seatop_impl {
1717
enum wlr_button_state state);
1818
void (*motion)(struct sway_seat *seat, uint32_t time_msec,
1919
double dx, double dy);
20+
void (*touch_down)(struct sway_seat *seat, uint32_t time_msec);
2021
void (*axis)(struct sway_seat *seat, struct wlr_event_pointer_axis *event);
2122
void (*rebase)(struct sway_seat *seat, uint32_t time_msec);
2223
void (*end)(struct sway_seat *seat);
@@ -258,6 +259,8 @@ void seatop_button(struct sway_seat *seat, uint32_t time_msec,
258259
void seatop_motion(struct sway_seat *seat, uint32_t time_msec,
259260
double dx, double dy);
260261

262+
void seatop_touch_down(struct sway_seat *seat, uint32_t time_msec);
263+
261264
void seatop_axis(struct sway_seat *seat, struct wlr_event_pointer_axis *event);
262265

263266
void seatop_rebase(struct sway_seat *seat, uint32_t time_msec);

sway/input/cursor.c

+2
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,8 @@ static void handle_touch_down(struct wl_listener *listener, void *data) {
398398
seat->touch_x = lx;
399399
seat->touch_y = ly;
400400

401+
seatop_touch_down(seat, event->time_msec);
402+
401403
if (!surface) {
402404
return;
403405
}

sway/input/seat.c

+6
Original file line numberDiff line numberDiff line change
@@ -1452,6 +1452,12 @@ void seatop_motion(struct sway_seat *seat, uint32_t time_msec,
14521452
}
14531453
}
14541454

1455+
void seatop_touch_down(struct sway_seat *seat, uint32_t time_msec) {
1456+
if (seat->seatop_impl->touch_down) {
1457+
seat->seatop_impl->touch_down(seat, time_msec);
1458+
}
1459+
}
1460+
14551461
void seatop_axis(struct sway_seat *seat, struct wlr_event_pointer_axis *event) {
14561462
if (seat->seatop_impl->axis) {
14571463
seat->seatop_impl->axis(seat, event);

sway/input/seatop_default.c

+30
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,35 @@ static void handle_axis(struct sway_seat *seat,
610610
}
611611
}
612612

613+
/*-------------------------------------\
614+
* Functions used by handle_touch_down /
615+
* ----------------------------------*/
616+
617+
static void handle_touch_down(struct sway_seat *seat, uint32_t time_msec) {
618+
struct seatop_default_event *e = seat->seatop_data;
619+
struct sway_cursor *cursor = seat->cursor;
620+
621+
// Determine what's under the cursor
622+
struct wlr_surface *surface = NULL;
623+
double sx, sy;
624+
struct sway_node *node = node_at_coords(
625+
seat, seat->touch_x, seat->touch_y, &surface, &sx, &sy);
626+
627+
struct sway_container *cont =
628+
node && node->type == N_CONTAINER ? node->sway_container : NULL;
629+
enum wlr_edges edge =
630+
cont ? find_edge(cont, surface, cursor) : WLR_EDGE_NONE;
631+
bool on_border = edge != WLR_EDGE_NONE;
632+
bool on_titlebar = cont && !on_border && !surface;
633+
634+
if (on_titlebar) {
635+
sway_log(SWAY_ERROR, "Touch Event on Titlebar");
636+
node = seat_get_focus_inactive(seat, &cont->node);
637+
seat_set_focus(seat, node);
638+
return;
639+
}
640+
}
641+
613642
/*----------------------------------\
614643
* Functions used by handle_rebase /
615644
*--------------------------------*/
@@ -627,6 +656,7 @@ static void handle_rebase(struct sway_seat *seat, uint32_t time_msec) {
627656
static const struct sway_seatop_impl seatop_impl = {
628657
.button = handle_button,
629658
.motion = handle_motion,
659+
.touch_down = handle_touch_down,
630660
.axis = handle_axis,
631661
.rebase = handle_rebase,
632662
.allow_set_cursor = true,

0 commit comments

Comments
 (0)