Merge ~mustafakemalgilor/ubuntu/+source/metacity:ubuntu/jammy-devel into ubuntu/+source/metacity:ubuntu/jammy-devel

Proposed by Mustafa Kemal Gilor
Status: Needs review
Proposed branch: ~mustafakemalgilor/ubuntu/+source/metacity:ubuntu/jammy-devel
Merge into: ubuntu/+source/metacity:ubuntu/jammy-devel
Diff against target: 282 lines (+250/-0)
5 files modified
debian/changelog (+9/-0)
debian/patches/0001-add-meta-window-is-focusable.patch (+69/-0)
debian/patches/0002-focus-only-ancestors-that-are-focusable.patch (+74/-0)
debian/patches/0003-remove-extra-unmap-events-window-and-serial.patch (+95/-0)
debian/patches/series (+3/-0)
Reviewer Review Type Date Requested Status
Dmitry Shachnev Pending
Review via email: mp+435960@code.launchpad.net

Description of the change

Metacity crashes when a docked window in an application is un-docked, and the owning parent window is minimized. This MP includes two patches for fixing the crash (0001,0002), and another one (0003) for fixing restoring docked windows back when the main window is minimized and unminimized while a docked window is un-docked.

SRU LP#2003176

To post a comment you must log in.

Unmerged commits

a59bbed... by Mustafa Kemal Gilor

changelog

Signed-off-by: Mustafa Kemal Gilor <email address hidden>

9883bab... by Mustafa Kemal Gilor

* d/p/0001-add-meta-window-is-focusable.patch: add meta_window
  is_focusable function (needed by patch #0002) (LP: #2003176)
* d/p/0002-focus-only-ancestors-that-are-focusable.patch: patch that
  fixes undocked window parent minimize crash (LP: #2003176)
* d/p/0003-remove-extra-unmap-events-window-and-serial.patch: fix docked
  child window restore on main window unminimize (LP: #2003176)

Signed-off-by: Mustafa Kemal Gilor <email address hidden>

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/debian/changelog b/debian/changelog
2index 139d6ae..4d3a354 100644
3--- a/debian/changelog
4+++ b/debian/changelog
5@@ -1,3 +1,12 @@
6+metacity (1:3.44.0-1ubuntu1) jammy; urgency=medium
7+
8+ * Backport upstream patch to fix metacity crash when a parent window is
9+ minimized while a docked window is undocked.
10+ * Backport upstream patch to fix restoring docked window when the parent
11+ window is unminimized.
12+
13+ -- Mustafa Kemal GILOR <mustafa.gilor@canonical.com> Wed, 18 Jan 2023 15:50:17 +0300
14+
15 metacity (1:3.44.0-1) unstable; urgency=medium
16
17 * New upstream release.
18diff --git a/debian/patches/0001-add-meta-window-is-focusable.patch b/debian/patches/0001-add-meta-window-is-focusable.patch
19new file mode 100644
20index 0000000..dc2f380
21--- /dev/null
22+++ b/debian/patches/0001-add-meta-window-is-focusable.patch
23@@ -0,0 +1,69 @@
24+From abcbdcce1e67a7c652a21c7578aba69e1bda08c4 Mon Sep 17 00:00:00 2001
25+From: =?UTF-8?q?Alberts=20Muktup=C4=81vels?= <alberts.muktupavels@gmail.com>
26+Date: Mon, 3 Oct 2022 19:52:39 +0300
27+Subject: [PATCH] window: add meta_window_is_focusable
28+
29+Based on mutter commits:
30+https://gitlab.gnome.org/GNOME/mutter/-/commit/43633d6b2f6f602ba87956d5c20ee336b8b56236
31+https://gitlab.gnome.org/GNOME/mutter/-/commit/58d2a674c466b607e18e6c8e129a6cf1646fde7f
32+---
33+ src/core/stack.c | 2 +-
34+ src/core/window-private.h | 2 ++
35+ src/core/window.c | 10 ++++++++--
36+ 3 files changed, 11 insertions(+), 3 deletions(-)
37+
38+--- a/src/core/stack.c
39++++ b/src/core/stack.c
40+@@ -1243,7 +1243,7 @@
41+ if (window->unmanaging)
42+ continue;
43+
44+- if (!(window->input || window->take_focus))
45++ if (!meta_window_is_focusable (window))
46+ continue;
47+
48+ if (!meta_window_should_be_showing_on_workspace (window, workspace))
49+--- a/src/core/window-private.h
50++++ b/src/core/window-private.h
51+@@ -592,6 +592,8 @@
52+ void meta_window_set_focused_internal (MetaWindow *window,
53+ gboolean focused);
54+
55++gboolean meta_window_is_focusable (MetaWindow *self);
56++
57+ void meta_window_set_current_workspace_hint (MetaWindow *window);
58+
59+ unsigned long meta_window_get_net_wm_desktop (MetaWindow *window);
60+--- a/src/core/window.c
61++++ b/src/core/window.c
62+@@ -2043,7 +2043,7 @@
63+ /* don't initially focus windows that are intended to not accept
64+ * focus
65+ */
66+- if (!(window->input || window->take_focus))
67++ if (!meta_window_is_focusable (window))
68+ {
69+ *takes_focus = FALSE;
70+ return;
71+@@ -4417,7 +4417,7 @@
72+ */
73+ if (window->frame &&
74+ (window->shaded ||
75+- !(window->input || window->take_focus)))
76++ !meta_window_is_focusable (window)))
77+ {
78+ if (window->frame)
79+ {
80+@@ -5902,6 +5902,12 @@
81+ }
82+ }
83+
84++gboolean
85++meta_window_is_focusable (MetaWindow *self)
86++{
87++ return self->input || self->take_focus;
88++}
89++
90+ static gboolean
91+ process_property_notify (MetaWindow *window,
92+ XPropertyEvent *event)
93diff --git a/debian/patches/0002-focus-only-ancestors-that-are-focusable.patch b/debian/patches/0002-focus-only-ancestors-that-are-focusable.patch
94new file mode 100644
95index 0000000..8f57831
96--- /dev/null
97+++ b/debian/patches/0002-focus-only-ancestors-that-are-focusable.patch
98@@ -0,0 +1,74 @@
99+From 398fa63cff7b791e78c0a7b7e2234b0344959819 Mon Sep 17 00:00:00 2001
100+From: =?UTF-8?q?Alberts=20Muktup=C4=81vels?= <alberts.muktupavels@gmail.com>
101+Date: Mon, 3 Oct 2022 20:19:38 +0300
102+Subject: [PATCH] workspace: focus only ancestors that are focusable
103+
104+Based on mutter commit:
105+https://gitlab.gnome.org/GNOME/mutter/-/commit/eccc791f3b3451216f957e67fec47a73b65ed2b2
106+---
107+ src/core/workspace.c | 39 ++++++++++++++++++++++++++++++++-------
108+ 1 file changed, 32 insertions(+), 7 deletions(-)
109+
110+diff --git a/src/core/workspace.c b/src/core/workspace.c
111+index 19e3a9a8..45306dd6 100644
112+--- a/src/core/workspace.c
113++++ b/src/core/workspace.c
114+@@ -969,14 +969,30 @@ meta_workspace_focus_default_window (MetaWorkspace *workspace,
115+ }
116+ }
117+
118++typedef struct
119++{
120++ MetaWorkspace *workspace;
121++ MetaWindow *ancestor;
122++} FindFocusableAncestorData;
123++
124+ static gboolean
125+-record_ancestor (MetaWindow *window,
126+- void *data)
127++find_focusable_ancestor (MetaWindow *window,
128++ gpointer user_data)
129+ {
130+- MetaWindow **result = data;
131++ FindFocusableAncestorData *data;
132+
133+- *result = window;
134+- return FALSE; /* quit with the first ancestor we find */
135++ data = user_data;
136++
137++ if (!window->unmanaging &&
138++ meta_window_is_focusable (window) &&
139++ meta_window_located_on_workspace (window, data->workspace) &&
140++ meta_window_showing_on_its_workspace (window))
141++ {
142++ data->ancestor = window;
143++ return FALSE;
144++ }
145++
146++ return TRUE;
147+ }
148+
149+ /* Focus ancestor of not_this_one if there is one */
150+@@ -998,8 +1014,17 @@ focus_ancestor_or_top_window (MetaWorkspace *workspace,
151+ if (not_this_one)
152+ {
153+ MetaWindow *ancestor;
154+- ancestor = NULL;
155+- meta_window_foreach_ancestor (not_this_one, record_ancestor, &ancestor);
156++ FindFocusableAncestorData data;
157++
158++ data.workspace = workspace;
159++ data.ancestor = NULL;
160++
161++ meta_window_foreach_ancestor (not_this_one,
162++ find_focusable_ancestor,
163++ &data);
164++
165++ ancestor = data.ancestor;
166++
167+ if (ancestor != NULL)
168+ {
169+ meta_topic (META_DEBUG_FOCUS,
170+--
171+GitLab
172+
173diff --git a/debian/patches/0003-remove-extra-unmap-events-window-and-serial.patch b/debian/patches/0003-remove-extra-unmap-events-window-and-serial.patch
174new file mode 100644
175index 0000000..01cca21
176--- /dev/null
177+++ b/debian/patches/0003-remove-extra-unmap-events-window-and-serial.patch
178@@ -0,0 +1,95 @@
179+From 3db07fafa1c7ff9749b6a82ccb36d8b62f2304d9 Mon Sep 17 00:00:00 2001
180+From: =?UTF-8?q?Alberts=20Muktup=C4=81vels?= <alberts.muktupavels@gmail.com>
181+Date: Wed, 5 Oct 2022 01:57:04 +0300
182+Subject: [PATCH] display: remove extra unmap events with same window and
183+ serial
184+
185+Single XUnmapWindow call can result in multiple UnmapNotify events.
186+
187+Linked issue has attached python code intended to reproduce original
188+bug and can be used to reproduce multiple UnmapNotify events for the
189+same window.
190+
191+Steps to reproduce problem:
192+1. Run python3 Untitled.py;
193+2. Undock one of the application's child windows;
194+3. Minimize main window;
195+4. Unminimize main window.
196+
197+On drag start metacity gets map event - new MetaWindow is created.
198+This window has override_redirect set to true, metacity selects
199+StructureNotifyMask events. When child window is dropped outside
200+main window we get 3 unmap events!
201+
202+One event was sent because we asked X server to do that by selecting
203+StructureNotifyMask events. Second event was sent because child
204+window parent was root window. We have asked for such events on root
205+window by selecting SubstructureNotifyMask events. Third event seems
206+to come from XSendEvent.
207+
208+At this point these multiple events are not problem. MetaWindow is
209+destroyed when we get first event and rest are ignored.
210+
211+After that application sends map request and we create new
212+MetaWindow. This time override_redirect is not set and we choose to
213+not select StructureNotifyMask events. Unfortunately this mask is
214+already in your_event_mask as we are not unselecting events when
215+window is unmanaged.
216+
217+Now when we minimize main window (step 3) also dock window is
218+minimized. We are just hiding window so we are adding pending unmap
219+event so we can ignore it when it will arrive. On first event we
220+correctly detect that it should be ignored but once second event
221+arrives we are unmanaging this window.
222+
223+And here is our problem - trying to unminimize main window only
224+main window gets restored! Main window does not find child window
225+because it is destroyed.
226+
227+Use XCheckIfEvent to remove extra UnmapNotify events that has same
228+window and serial preventing unnecessary window destruction.
229+
230+https://gitlab.gnome.org/GNOME/metacity/-/issues/31
231+---
232+ src/core/display.c | 23 +++++++++++++++++++++++
233+ 1 file changed, 23 insertions(+)
234+
235+--- a/src/core/display.c
236++++ b/src/core/display.c
237+@@ -1696,6 +1696,20 @@
238+ }
239+ }
240+
241++static Bool
242++unmap_predicate (Display *display,
243++ XEvent *event,
244++ XPointer arg)
245++{
246++ XUnmapEvent *unmap;
247++
248++ unmap = (XUnmapEvent *) arg;
249++
250++ return event->type == UnmapNotify &&
251++ event->xunmap.window == unmap->window &&
252++ event->xunmap.serial == unmap->serial;
253++}
254++
255+ /**
256+ * This is the most important function in the whole program. It is the heart,
257+ * it is the nexus, it is the Grand Central Station of Metacity's world.
258+@@ -2283,6 +2297,15 @@
259+
260+ if (!frame_was_receiver)
261+ {
262++ XEvent unmap_event;
263++
264++ while (XCheckIfEvent (display->xdisplay,
265++ &unmap_event,
266++ unmap_predicate,
267++ (XPointer) &event->xunmap))
268++ {
269++ }
270++
271+ if (!meta_window_remove_pending_unmap (window, event->xany.serial))
272+ {
273+ meta_topic (META_DEBUG_WINDOW_STATE,
274diff --git a/debian/patches/series b/debian/patches/series
275new file mode 100644
276index 0000000..aebba11
277--- /dev/null
278+++ b/debian/patches/series
279@@ -0,0 +1,3 @@
280+0001-add-meta-window-is-focusable.patch
281+0002-focus-only-ancestors-that-are-focusable.patch
282+0003-remove-extra-unmap-events-window-and-serial.patch

Subscribers

People subscribed via source and target branches