mirror of
https://github.com/labwc/labwc.git
synced 2025-10-29 05:40:24 -04:00
desktop: simplify interface for view raise/focus
Split desktop_focus_view() into the following two functions: - desktop_focus_and_activate_view() - desktop_raise_view() Always call view_set_activated() rather than using the private set_activated(). This keeps the code cleaner and ensures wlr_foreign_toplevel_handle_v1_set_activated() is called.
This commit is contained in:
parent
70144ac113
commit
9a290feeea
6 changed files with 72 additions and 29 deletions
|
|
@ -340,8 +340,22 @@ void view_update_title(struct view *view);
|
|||
|
||||
void foreign_toplevel_handle_create(struct view *view);
|
||||
|
||||
/*
|
||||
* desktop.c routines deal with a collection of views
|
||||
*
|
||||
* Definition of a few keywords used in desktop.c
|
||||
* raise - Bring view to front.
|
||||
* focus - Give keyboard focus to view.
|
||||
* activate - Set view surface as active so that client window decorations
|
||||
* are painted to show that the window is active,typically by
|
||||
* using a different color. Although xdg-shell protocol says you
|
||||
* cannot assume this means that the window actually has keyboard
|
||||
* or pointer focus, in this compositor are they called together.
|
||||
*/
|
||||
|
||||
void desktop_set_focus_view_only(struct seat *seat, struct view *view);
|
||||
void desktop_focus_view(struct seat *seat, struct view *view);
|
||||
void desktop_raise_view(struct view *view);
|
||||
void desktop_focus_and_activate_view(struct seat *seat, struct view *view);
|
||||
|
||||
/**
|
||||
* desktop_cycle_view - return view to 'cycle' to
|
||||
|
|
|
|||
|
|
@ -182,7 +182,8 @@ process_cursor_motion(struct server *server, uint32_t time)
|
|||
|
||||
if (view && rc.focus_follow_mouse) {
|
||||
if (rc.raise_on_focus) {
|
||||
desktop_focus_view(&server->seat, view);
|
||||
desktop_focus_and_activate_view(&server->seat, view);
|
||||
desktop_raise_view(view);
|
||||
} else {
|
||||
desktop_set_focus_view_only(&server->seat, view);
|
||||
}
|
||||
|
|
@ -384,7 +385,8 @@ cursor_button(struct wl_listener *listener, void *data)
|
|||
}
|
||||
|
||||
/* Handle _press_ on view */
|
||||
desktop_focus_view(&server->seat, view);
|
||||
desktop_focus_and_activate_view(&server->seat, view);
|
||||
desktop_raise_view(view);
|
||||
damage_all_outputs(server);
|
||||
|
||||
if (is_double_click(rc.doubleclick_time)
|
||||
|
|
|
|||
|
|
@ -95,7 +95,31 @@ desktop_set_focus_view_only(struct seat *seat, struct view *view)
|
|||
}
|
||||
|
||||
void
|
||||
desktop_focus_view(struct seat *seat, struct view *view)
|
||||
desktop_raise_view(struct view *view)
|
||||
{
|
||||
if (!view) {
|
||||
return;
|
||||
}
|
||||
move_to_front(view);
|
||||
#if HAVE_XWAYLAND
|
||||
move_xwayland_sub_views_to_front(view);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void
|
||||
deactivate_all_views(struct server *server)
|
||||
{
|
||||
struct view *view;
|
||||
wl_list_for_each (view, &server->views, link) {
|
||||
if (!view->mapped) {
|
||||
continue;
|
||||
}
|
||||
view_set_activated(view, false);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
desktop_focus_and_activate_view(struct seat *seat, struct view *view)
|
||||
{
|
||||
if (!view) {
|
||||
seat_focus_surface(seat, NULL);
|
||||
|
|
@ -106,30 +130,28 @@ desktop_focus_view(struct seat *seat, struct view *view)
|
|||
}
|
||||
|
||||
if (view->minimized) {
|
||||
/* this will unmap and then focus */
|
||||
/*
|
||||
* Unminimizing will map the view which triggers a call to this
|
||||
* function again.
|
||||
*/
|
||||
view_minimize(view, false);
|
||||
return;
|
||||
} else if (view->mapped) {
|
||||
struct wlr_surface *prev_surface;
|
||||
prev_surface = seat->seat->keyboard_state.focused_surface;
|
||||
if (prev_surface == view->surface) {
|
||||
/* Don't re-focus an already focused surface. */
|
||||
move_to_front(view);
|
||||
#if HAVE_XWAYLAND
|
||||
move_xwayland_sub_views_to_front(view);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
if (prev_surface) {
|
||||
set_activated(prev_surface, false);
|
||||
}
|
||||
move_to_front(view);
|
||||
set_activated(view->surface, true);
|
||||
seat_focus_surface(seat, view->surface);
|
||||
#if HAVE_XWAYLAND
|
||||
move_xwayland_sub_views_to_front(view);
|
||||
#endif
|
||||
}
|
||||
if (!view->mapped) {
|
||||
return;
|
||||
}
|
||||
|
||||
struct wlr_surface *prev_surface;
|
||||
prev_surface = seat->seat->keyboard_state.focused_surface;
|
||||
|
||||
/* Do not re-focus an already focused surface. */
|
||||
if (prev_surface == view->surface) {
|
||||
return;
|
||||
}
|
||||
|
||||
deactivate_all_views(view->server);
|
||||
view_set_activated(view, true);
|
||||
seat_focus_surface(seat, view->surface);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -236,7 +258,8 @@ void
|
|||
desktop_focus_topmost_mapped_view(struct server *server)
|
||||
{
|
||||
struct view *view = topmost_mapped_view(server);
|
||||
desktop_focus_view(&server->seat, view);
|
||||
desktop_focus_and_activate_view(&server->seat, view);
|
||||
desktop_raise_view(view);
|
||||
}
|
||||
|
||||
static bool
|
||||
|
|
|
|||
|
|
@ -43,7 +43,9 @@ keyboard_modifiers_notify(struct wl_listener *listener, void *data)
|
|||
if ((event->state == WL_KEYBOARD_KEY_STATE_RELEASED)
|
||||
&& !any_modifiers_pressed(device->keyboard)) {
|
||||
/* end cycle */
|
||||
desktop_focus_view(&server->seat, server->cycle_view);
|
||||
desktop_focus_and_activate_view(&server->seat,
|
||||
server->cycle_view);
|
||||
desktop_raise_view(server->cycle_view);
|
||||
server->cycle_view = NULL;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -343,7 +343,8 @@ xdg_toplevel_view_map(struct view *view)
|
|||
wl_signal_add(&view->surface->events.new_subsurface,
|
||||
&view->new_subsurface);
|
||||
|
||||
desktop_focus_view(&view->server->seat, view);
|
||||
desktop_focus_and_activate_view(&view->server->seat, view);
|
||||
desktop_raise_view(view);
|
||||
damage_all_outputs(view->server);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -208,7 +208,8 @@ map(struct view *view)
|
|||
&view->commit);
|
||||
view->commit.notify = handle_commit;
|
||||
|
||||
desktop_focus_view(&view->server->seat, view);
|
||||
desktop_focus_and_activate_view(&view->server->seat, view);
|
||||
desktop_raise_view(view);
|
||||
damage_all_outputs(view->server);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue