summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Bugaev <bugaevc@gmail.com>2019-09-15 13:53:39 +0300
committerSergey Bugaev <bugaevc@gmail.com>2019-09-16 01:26:19 +0300
commit9d2d90184fa79ee1e62b0d38ab40706a23185cd0 (patch)
treec22035fcec107e118e933b90de8c74dc025ae3c2
parentd342c85bfce0cc345cf20414e85769aa35e52999 (diff)
Make popup surface manage the keyboard and forward its callback
-rw-r--r--src/boilerplate.c16
-rw-r--r--src/types/popup-surface.c34
-rw-r--r--src/types/popup-surface.h8
3 files changed, 40 insertions, 18 deletions
diff --git a/src/boilerplate.c b/src/boilerplate.c
index 58c24db..d2a6621 100644
--- a/src/boilerplate.c
+++ b/src/boilerplate.c
@@ -17,7 +17,6 @@
*/
#include "boilerplate.h"
-#include "types/keyboard.h"
#include "types/shell-surface.h"
#include "types/shell.h"
#include "types/popup-surface.h"
@@ -25,7 +24,7 @@
static struct popup_surface *popup_surface = NULL;
-static void forward_on_focus(struct keyboard *keyboard, uint32_t serial) {
+static void forward_on_focus(struct popup_surface *popup_surface, uint32_t serial) {
if (action_on_popup_surface_getting_focus != NULL) {
action_on_popup_surface_getting_focus(serial);
}
@@ -60,19 +59,10 @@ void popup_tiny_invisible_surface() {
* otherwise we won't be notified of the selection.
*/
- struct keyboard *keyboard = seat_get_keyboard(seat);
- if (keyboard == NULL) {
- bail("This seat has no keyboard");
- }
- keyboard->on_focus = forward_on_focus;
- /* Make sure that we get the keyboard
- * object before creating the surface,
- * so that we get the enter event.
- */
- wl_display_dispatch(display);
-
popup_surface = calloc(1, sizeof(struct popup_surface));
popup_surface->registry = registry;
+ popup_surface->seat = seat;
+ popup_surface->on_focus = forward_on_focus;
popup_surface_init(popup_surface);
}
diff --git a/src/types/popup-surface.c b/src/types/popup-surface.c
index fe2a59f..b629a77 100644
--- a/src/types/popup-surface.c
+++ b/src/types/popup-surface.c
@@ -18,6 +18,8 @@
#include "types/popup-surface.h"
#include "types/registry.h"
+#include "types/seat.h"
+#include "types/keyboard.h"
#include "types/shell.h"
#include "types/shell-surface.h"
#include "util/files.h"
@@ -27,12 +29,36 @@
#include <stdlib.h>
#include <unistd.h>
+static void forward_on_focus(
+ struct keyboard *keyboard,
+ uint32_t serial
+) {
+ struct popup_surface *self = (struct popup_surface *) keyboard->data;
+ if (self->on_focus != NULL) {
+ self->on_focus(self, serial);
+ }
+}
+
void popup_surface_init(struct popup_surface *self) {
self->shell = registry_find_shell(self->registry);
if (self->shell == NULL) {
bail("Missing a shell");
}
+ self->keyboard = seat_get_keyboard(self->seat);
+ if (self->keyboard == NULL) {
+ bail("This seat has no keyboard");
+ }
+ self->keyboard->on_focus = forward_on_focus;
+ self->keyboard->data = self;
+
+ /* Make sure that we get the keyboard
+ * object before we create the surface,
+ * so that we get the enter event.
+ */
+ wl_display_dispatch(self->registry->wl_display);
+
+
struct wl_compositor *wl_compositor = self->registry->wl_compositor;
if (wl_compositor == NULL) {
bail("Missing the compositor");
@@ -50,10 +76,10 @@ void popup_surface_init(struct popup_surface *self) {
if (self->wl_surface == NULL) {
/* It's possible that we were given focus
* (without ever commiting a buffer) during
- * the above roundtrip, in which case the
- * handlers may have already destroyed the
- * surface. No need to do anything further in
- * that case.
+ * the above roundtrip, in which case we have
+ * already fired the callback and have likely
+ * already destroyed the surface. No need to
+ * do anything further in that case.
*/
free(self);
return;
diff --git a/src/types/popup-surface.h b/src/types/popup-surface.h
index bb54f21..8847519 100644
--- a/src/types/popup-surface.h
+++ b/src/types/popup-surface.h
@@ -24,15 +24,21 @@
struct registry;
struct shell;
struct shell_surface;
+struct seat;
+struct keyboard;
struct popup_surface {
- /* This field is initialized by the creator */
+ /* These fields are initialized by the creator */
struct registry *registry;
+ struct seat *seat;
+ void (*on_focus)(struct popup_surface *self, uint32_t serial);
+ void *data;
/* These fields are initialized by the implementation */
struct shell *shell;
struct shell_surface *shell_surface;
struct wl_surface *wl_surface;
+ struct keyboard *keyboard;
int should_free_self;
};