Skip to content

Commit 30b5837

Browse files
committed
xdg-shell, xwayland: always focus dialogs on map if parent is focused
Dialogs are identified as a view with a parent. This commit also moves shared code between xdg-shell and xwayland to a common location (toplevel_view_interface_t::focus_toplevel_on_map())
1 parent 5b096a5 commit 30b5837

File tree

4 files changed

+43
-30
lines changed

4 files changed

+43
-30
lines changed

src/api/wayfire/toplevel-view.hpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,17 @@ class toplevel_view_interface_t : public virtual wf::view_interface_t
203203
* This function is useful for view implementations only.
204204
*/
205205
void set_toplevel(std::shared_ptr<wf::toplevel_t> toplevel);
206+
207+
/**
208+
* Potentially focus this view on first map. Newly mapped views are
209+
* focused if either:
210+
* - the "core/focus_on_map" option is set
211+
* - no toplevel view is currently focused (i.e. no view is focused
212+
* or the currently focused view has role VIEW_ROLE_DESKTOP_ENVIRONMENT)
213+
* - the newly mapped view is a dialog (i.e. has a non-null parent)
214+
* and its parent is focused
215+
*/
216+
void focus_toplevel_on_map();
206217
};
207218

208219
inline wayfire_toplevel_view toplevel_cast(wayfire_view view)

src/view/toplevel-view.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <wayfire/window-manager.hpp>
99
#include <wayfire/txn/transaction-manager.hpp>
1010
#include <wayfire/seat.hpp>
11+
#include <wayfire/view-helpers.hpp>
1112
#include "view-impl.hpp"
1213
#include "wayfire/core.hpp"
1314
#include "wayfire/scene.hpp"
@@ -329,6 +330,35 @@ void wf::toplevel_view_interface_t::set_toplevel(
329330
priv->toplevel = toplevel;
330331
}
331332

333+
void wf::toplevel_view_interface_t::focus_toplevel_on_map()
334+
{
335+
/* We only focus a newly mapped view if the corresponding option is
336+
* set or if there is no currently active view. */
337+
wayfire_view active_view = nullptr;
338+
bool should_focus = wf::get_core().default_wm->focus_on_map;
339+
if (!should_focus)
340+
{
341+
active_view = wf::get_core().seat->get_active_view();
342+
if (active_view && (active_view->role == wf::VIEW_ROLE_DESKTOP_ENVIRONMENT))
343+
{
344+
active_view = nullptr;
345+
}
346+
347+
if (!active_view || (active_view == this->parent))
348+
{
349+
should_focus = true;
350+
}
351+
}
352+
353+
if (should_focus)
354+
{
355+
wf::get_core().default_wm->focus_request(self());
356+
} else if (active_view)
357+
{
358+
wf::view_bring_to_front(active_view);
359+
}
360+
}
361+
332362
wayfire_toplevel_view wf::find_view_for_toplevel(
333363
std::shared_ptr<wf::toplevel_t> toplevel)
334364
{

src/view/xdg-shell/xdg-toplevel-view.cpp

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -311,21 +311,7 @@ void wf::xdg_toplevel_view_t::map()
311311

312312
xdg_toplevel_view_base_t::map();
313313

314-
/* We only focus a newly mapped view if the corresponding option is
315-
* set or if there is no currently active view. */
316-
auto active_view = wf::get_core().seat->get_active_view();
317-
if (active_view && (active_view->role == wf::VIEW_ROLE_DESKTOP_ENVIRONMENT))
318-
{
319-
active_view = nullptr;
320-
}
321-
322-
if (wf::get_core().default_wm->focus_on_map || (active_view == nullptr))
323-
{
324-
wf::get_core().default_wm->focus_request(self());
325-
} else if (active_view)
326-
{
327-
wf::view_bring_to_front(active_view);
328-
}
314+
focus_toplevel_on_map();
329315

330316
/* Might trigger repositioning */
331317
set_toplevel_parent(this->parent);

src/view/xwayland/xwayland-toplevel-view.hpp

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -378,21 +378,7 @@ class wayfire_xwayland_view : public wf::toplevel_view_interface_t, public wayfi
378378
const bool wants_focus = (wlr_xwayland_icccm_input_model(xw) != WLR_ICCCM_INPUT_MODEL_NONE);
379379
if (wants_focus)
380380
{
381-
/* We only focus a newly mapped view if the corresponding option is
382-
* set or if there is no currently active view. */
383-
auto active_view = wf::get_core().seat->get_active_view();
384-
if (active_view && (active_view->role == wf::VIEW_ROLE_DESKTOP_ENVIRONMENT))
385-
{
386-
active_view = nullptr;
387-
}
388-
389-
if (wf::get_core().default_wm->focus_on_map || (active_view == nullptr))
390-
{
391-
wf::get_core().default_wm->focus_request(self());
392-
} else if (active_view)
393-
{
394-
wf::view_bring_to_front(active_view);
395-
}
381+
focus_toplevel_on_map();
396382
}
397383

398384
/* Might trigger repositioning */

0 commit comments

Comments
 (0)