mirror of
https://github.com/swaywm/sway.git
synced 2024-11-11 21:14:10 +01:00
seat focus on button press
This commit is contained in:
parent
0fdecb4d3a
commit
21626e8153
@ -124,6 +124,10 @@ struct sway_container {
|
||||
* Marks applied to the container, list_t of char*.
|
||||
*/
|
||||
list_t *marks;
|
||||
|
||||
struct {
|
||||
struct wl_signal destroy;
|
||||
} events;
|
||||
};
|
||||
|
||||
void swayc_descendants_of_type(swayc_t *root, enum swayc_types type,
|
||||
|
@ -19,4 +19,7 @@ char* libinput_dev_unique_id(struct libinput_device *dev);
|
||||
struct sway_input_manager *sway_input_manager_create(
|
||||
struct sway_server *server);
|
||||
|
||||
bool sway_input_manager_swayc_has_focus(struct sway_input_manager *input,
|
||||
swayc_t *container);
|
||||
|
||||
#endif
|
||||
|
@ -7,9 +7,13 @@
|
||||
struct sway_seat {
|
||||
struct wlr_seat *seat;
|
||||
struct sway_cursor *cursor;
|
||||
struct sway_input_manager *input;
|
||||
swayc_t *focus;
|
||||
|
||||
struct wl_listener focus_destroy;
|
||||
};
|
||||
|
||||
struct sway_seat *sway_seat_create(struct wl_display *display,
|
||||
struct sway_seat *sway_seat_create(struct sway_input_manager *input,
|
||||
const char *seat_name);
|
||||
|
||||
void sway_seat_add_device(struct sway_seat *seat,
|
||||
@ -20,4 +24,6 @@ void sway_seat_remove_device(struct sway_seat *seat,
|
||||
|
||||
void sway_seat_configure_xcursor(struct sway_seat *seat);
|
||||
|
||||
void sway_seat_set_focus(struct sway_seat *seat, swayc_t *container);
|
||||
|
||||
#endif
|
||||
|
@ -1,4 +1,9 @@
|
||||
#define _XOPEN_SOURCE 700
|
||||
#ifdef __linux__
|
||||
#include <linux/input-event-codes.h>
|
||||
#elif __FreeBSD__
|
||||
#include <dev/evdev/input-event-codes.h>
|
||||
#endif
|
||||
#include <wlr/types/wlr_cursor.h>
|
||||
#include <wlr/types/wlr_xcursor_manager.h>
|
||||
#include "sway/input/cursor.h"
|
||||
@ -57,6 +62,16 @@ static void handle_cursor_button(struct wl_listener *listener, void *data) {
|
||||
struct sway_cursor *cursor =
|
||||
wl_container_of(listener, cursor, button);
|
||||
struct wlr_event_pointer_button *event = data;
|
||||
|
||||
if (event->button == BTN_LEFT) {
|
||||
struct wlr_surface *surface = NULL;
|
||||
double sx, sy;
|
||||
swayc_t *swayc =
|
||||
swayc_at(&root_container, cursor->x, cursor->y, &surface, &sx, &sy);
|
||||
|
||||
sway_seat_set_focus(cursor->seat, swayc);
|
||||
}
|
||||
|
||||
wlr_seat_pointer_notify_button(cursor->seat->seat, event->time_msec,
|
||||
event->button, event->state);
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ static struct sway_seat *input_manager_get_seat(
|
||||
}
|
||||
}
|
||||
|
||||
seat = sway_seat_create(input->server->wl_display, seat_name);
|
||||
seat = sway_seat_create(input, seat_name);
|
||||
list_add(input->seats, seat);
|
||||
|
||||
return seat;
|
||||
@ -131,3 +131,15 @@ char *libinput_dev_unique_id(struct libinput_device *device) {
|
||||
free(name);
|
||||
return identifier;
|
||||
}
|
||||
|
||||
bool sway_input_manager_swayc_has_focus(struct sway_input_manager *input,
|
||||
swayc_t *container) {
|
||||
for (int i = 0; i < input->seats->length; ++i) {
|
||||
struct sway_seat *seat = input->seats->items[i];
|
||||
if (seat->focus == container) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -5,16 +5,17 @@
|
||||
#include "sway/input/cursor.h"
|
||||
#include "sway/input/input-manager.h"
|
||||
#include "sway/output.h"
|
||||
#include "sway/view.h"
|
||||
#include "log.h"
|
||||
|
||||
struct sway_seat *sway_seat_create(struct wl_display *display,
|
||||
struct sway_seat *sway_seat_create(struct sway_input_manager *input,
|
||||
const char *seat_name) {
|
||||
struct sway_seat *seat = calloc(1, sizeof(struct sway_seat));
|
||||
if (!seat) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
seat->seat = wlr_seat_create(display, seat_name);
|
||||
seat->seat = wlr_seat_create(input->server->wl_display, seat_name);
|
||||
if (!sway_assert(seat->seat, "could not allocate seat")) {
|
||||
return NULL;
|
||||
}
|
||||
@ -26,6 +27,8 @@ struct sway_seat *sway_seat_create(struct wl_display *display,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
seat->input = input;
|
||||
|
||||
wlr_seat_set_capabilities(seat->seat,
|
||||
WL_SEAT_CAPABILITY_KEYBOARD |
|
||||
WL_SEAT_CAPABILITY_POINTER |
|
||||
@ -110,3 +113,40 @@ void sway_seat_configure_xcursor(struct sway_seat *seat) {
|
||||
wlr_cursor_warp(seat->cursor->cursor, NULL, seat->cursor->cursor->x,
|
||||
seat->cursor->cursor->y);
|
||||
}
|
||||
|
||||
static void handle_focus_destroy(struct wl_listener *listener, void *data) {
|
||||
struct sway_seat *seat = wl_container_of(listener, seat, focus_destroy);
|
||||
//swayc_t *container = data;
|
||||
|
||||
// TODO set new focus based on the state of the tree
|
||||
sway_seat_set_focus(seat, NULL);
|
||||
}
|
||||
|
||||
void sway_seat_set_focus(struct sway_seat *seat, swayc_t *container) {
|
||||
swayc_t *last_focus = seat->focus;
|
||||
|
||||
if (last_focus == container) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (last_focus) {
|
||||
wl_list_remove(&seat->focus_destroy.link);
|
||||
}
|
||||
|
||||
if (container) {
|
||||
struct sway_view *view = container->sway_view;
|
||||
view->iface.set_activated(view, true);
|
||||
wl_signal_add(&container->events.destroy, &seat->focus_destroy);
|
||||
seat->focus_destroy.notify = handle_focus_destroy;
|
||||
// TODO give keyboard focus
|
||||
}
|
||||
|
||||
seat->focus = container;
|
||||
|
||||
if (last_focus &&
|
||||
!sway_input_manager_swayc_has_focus(seat->input, last_focus)) {
|
||||
struct sway_view *view = last_focus->sway_view;
|
||||
view->iface.set_activated(view, false);
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -40,6 +40,9 @@ static swayc_t *new_swayc(enum swayc_types type) {
|
||||
if (type != C_VIEW) {
|
||||
c->children = create_list();
|
||||
}
|
||||
|
||||
wl_signal_init(&c->events.destroy);
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
@ -119,6 +122,9 @@ static void free_swayc(swayc_t *cont) {
|
||||
if (!sway_assert(cont, "free_swayc passed NULL")) {
|
||||
return;
|
||||
}
|
||||
|
||||
wl_signal_emit(&cont->events.destroy, cont);
|
||||
|
||||
if (cont->children) {
|
||||
// remove children until there are no more, free_swayc calls
|
||||
// remove_child, which removes child from this container
|
||||
|
Loading…
Reference in New Issue
Block a user