summaryrefslogtreecommitdiff
path: root/D133634.diff
blob: 3c9d642d035d658eee1894e0657769f232885961 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
diff --git a/widget/gtk/nsGtkKeyUtils.cpp b/widget/gtk/nsGtkKeyUtils.cpp
--- a/widget/gtk/nsGtkKeyUtils.cpp
+++ b/widget/gtk/nsGtkKeyUtils.cpp
@@ -2424,17 +2424,23 @@
 #ifdef MOZ_WAYLAND
 void KeymapWrapper::SetFocusIn(wl_surface* aFocusSurface,
                                uint32_t aFocusSerial) {
+  LOGW("KeymapWrapper::SetFocusIn() surface %p ID %d serial %d", aFocusSurface,
+       aFocusSurface ? wl_proxy_get_id((struct wl_proxy*)aFocusSurface) : 0,
+       aFocusSerial);
+
   KeymapWrapper* keymapWrapper = KeymapWrapper::GetInstance();
   keymapWrapper->mFocusSurface = aFocusSurface;
   keymapWrapper->mFocusSerial = aFocusSerial;
 }
 
+// aFocusSurface can be null in case that focused surface is already destroyed.
 void KeymapWrapper::SetFocusOut(wl_surface* aFocusSurface) {
   KeymapWrapper* keymapWrapper = KeymapWrapper::GetInstance();
-  if (aFocusSurface == keymapWrapper->mFocusSurface) {
-    keymapWrapper->mFocusSurface = nullptr;
-    keymapWrapper->mFocusSerial = 0;
-  }
+  LOGW("KeymapWrapper::SetFocusOut surface %p ID %d", aFocusSurface,
+       aFocusSurface ? wl_proxy_get_id((struct wl_proxy*)aFocusSurface) : 0);
+
+  keymapWrapper->mFocusSurface = nullptr;
+  keymapWrapper->mFocusSerial = 0;
 }
 
 void KeymapWrapper::GetFocusInfo(wl_surface** aFocusSurface,
@@ -2453,7 +2459,6 @@
   KeymapWrapper* keymapWrapper = KeymapWrapper::GetInstance();
   return keymapWrapper->mSeat;
 }
-
 #endif
 
 }  // namespace widget
diff --git a/widget/gtk/nsWindow.h b/widget/gtk/nsWindow.h
--- a/widget/gtk/nsWindow.h
+++ b/widget/gtk/nsWindow.h
@@ -386,8 +386,7 @@
 
 #ifdef MOZ_WAYLAND
   // Use xdg-activation protocol to transfer focus from gFocusWindow to aWindow.
-  // RequestFocusWaylandWindow needs to be called on focused window only.
-  void RequestFocusWaylandWindow(RefPtr<nsWindow> aWindow);
+  static void RequestFocusWaylandWindow(RefPtr<nsWindow> aWindow);
   void FocusWaylandWindow(const char* aTokenID);
 
   bool GetCSDDecorationOffset(int* aDx, int* aDy);
diff --git a/widget/gtk/nsWindow.cpp b/widget/gtk/nsWindow.cpp
--- a/widget/gtk/nsWindow.cpp
+++ b/widget/gtk/nsWindow.cpp
@@ -2845,6 +2845,9 @@
     return;
   }
 
+  LOG("  requesting xdg-activation, surface ID %d",
+      wl_proxy_get_id((struct wl_proxy*)surface));
+
   xdg_activation_v1* xdg_activation = WaylandDisplayGet()->GetXdgActivation();
   xdg_activation_v1_activate(xdg_activation, aTokenID, surface);
 }
@@ -2862,12 +2865,17 @@
 };
 
 void nsWindow::RequestFocusWaylandWindow(RefPtr<nsWindow> aWindow) {
-  LOG("nsWindow::RequestWindowFocusWayland(%p)", (void*)aWindow);
+  LOGW("nsWindow::RequestFocusWaylandWindow(%p) gFocusWindow %p",
+       (void*)aWindow, gFocusWindow);
+
+  if (!gFocusWindow) {
+    LOGW("  missing gFocusWindow, quit.");
+  }
 
   RefPtr<nsWaylandDisplay> display = WaylandDisplayGet();
   xdg_activation_v1* xdg_activation = display->GetXdgActivation();
   if (!xdg_activation) {
-    LOG("  xdg-activation is missing, quit.");
+    LOGW("  xdg-activation is missing, quit.");
     return;
   }
 
@@ -2875,13 +2883,25 @@
   uint32_t focusSerial;
   KeymapWrapper::GetFocusInfo(&focusSurface, &focusSerial);
   if (!focusSurface) {
-    LOG("  We're missing focused window, quit.");
-    return;
-  }
-
-  LOG("  requesting xdg-activation token, surface ID %d serial %d seat ID %d",
-      wl_proxy_get_id((struct wl_proxy*)focusSurface), focusSerial,
-      wl_proxy_get_id((struct wl_proxy*)KeymapWrapper::GetSeat()));
+    LOGW("  We're missing focused window, quit.");
+    return;
+  }
+
+  GdkWindow* gdkWindow = gtk_widget_get_window(gFocusWindow->mShell);
+  wl_surface* surface =
+      gdkWindow ? gdk_wayland_window_get_wl_surface(gdkWindow) : nullptr;
+  if (focusSurface != surface) {
+    LOGW("  focused surface %p and gFocusWindow surface %p don't match, quit.",
+         focusSurface, surface);
+    return;
+  }
+
+  LOGW(
+      "  requesting xdg-activation token, surface %p ID %d serial %d seat ID "
+      "%d",
+      focusSurface,
+      focusSurface ? wl_proxy_get_id((struct wl_proxy*)focusSurface) : 0,
+      focusSerial, wl_proxy_get_id((struct wl_proxy*)KeymapWrapper::GetSeat()));
 
   // Store activation token at activated window for further release.
   g_clear_pointer(&aWindow->mXdgToken, xdg_activation_token_v1_destroy);

bgstack15