Skip to content

Commit

Permalink
Remove focus when clicking on the background
Browse files Browse the repository at this point in the history
  • Loading branch information
serebit committed Nov 4, 2023
1 parent c6859a9 commit ea9e3b4
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/foreign_toplevel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ static void foreign_toplevel_handle_request_activate_notify(wl_listener* listene
(void) data;

handle.view.set_minimized(false);
handle.view.get_server().focus_view(handle.view, handle.view.get_wlr_surface());
handle.view.get_server().focus_view(&handle.view, handle.view.get_wlr_surface());
}

static void foreign_toplevel_handle_request_fullscreen_notify(wl_listener* listener, void* data) {
Expand Down
4 changes: 3 additions & 1 deletion src/input/cursor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,9 @@ static void cursor_button_notify(wl_listener* listener, void* data) {
}
} else if (magpie_surface != nullptr && magpie_surface->is_view()) {
/* Focus that client if the button was _pressed_ */
server.focus_view(*static_cast<View*>(magpie_surface), surface);
server.focus_view(static_cast<View*>(magpie_surface), surface);
} else {
server.focus_view(nullptr);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/input/keyboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ static bool handle_compositor_keybinding(const Keyboard& keyboard, const uint32_
if (server.views.size() < 2) {
return true;
}
View& next_view = **server.views.begin()++;
View* next_view = *server.views.begin()++;
server.focus_view(next_view);
return true;
}
Expand Down
34 changes: 18 additions & 16 deletions src/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,15 @@
#include <wlr/util/log.h>
#include "wlr-wrap-end.hpp"

void Server::focus_view(View& view, wlr_surface* surface) {
Server& server = view.get_server();
wlr_seat* seat = server.seat->seat;
wlr_surface* prev_surface = seat->keyboard_state.focused_surface;
void Server::focus_view(View* view, wlr_surface* surface) {
wlr_surface* prev_surface = seat->seat->keyboard_state.focused_surface;
if (prev_surface == surface) {
/* Don't re-focus an already focused surface. */
return;
}

if (prev_surface) {
wlr_surface* previous = seat->keyboard_state.focused_surface;
wlr_surface* previous = seat->seat->keyboard_state.focused_surface;

if (wlr_surface_is_xdg_surface(previous)) {
wlr_xdg_surface* xdg_previous = wlr_xdg_surface_from_wlr_surface(previous);
Expand All @@ -52,31 +50,35 @@ void Server::focus_view(View& view, wlr_surface* surface) {
}
}

if (view == nullptr) {
return;
}

/* Move the view to the front */
wlr_scene_node_raise_to_top(view.scene_node);
(void) std::remove(server.views.begin(), server.views.end(), &view);
for (auto* view : server.views) {
wlr_scene_node_raise_to_top(view->scene_node);
(void) std::remove(views.begin(), views.end(), view);
for (auto* view : views) {
view->set_activated(false);
}

/* Activate the new surface */
server.views.insert(server.views.begin(), &view);
view.set_activated(true);
focused_view = &view;
views.insert(views.begin(), view);
view->set_activated(true);
focused_view = view;

/*
* Tell the seat to have the keyboard enter this surface. wlroots will keep
* track of this and automatically send key events to the appropriate
* clients without additional work on your part.
*/
wlr_keyboard* keyboard = wlr_seat_get_keyboard(seat);
wlr_keyboard* keyboard = wlr_seat_get_keyboard(seat->seat);
if (keyboard != nullptr) {
wlr_seat_keyboard_notify_enter(seat, view.get_wlr_surface(), keyboard->keycodes, keyboard->num_keycodes, &keyboard->modifiers);
wlr_seat_keyboard_notify_enter(seat->seat, view->get_wlr_surface(), keyboard->keycodes, keyboard->num_keycodes, &keyboard->modifiers);
}

wlr_pointer_constraint_v1* constraint =
wlr_pointer_constraints_v1_constraint_for_surface(server.seat->pointer_constraints, surface, seat);
server.seat->set_constraint(constraint);
wlr_pointer_constraints_v1_constraint_for_surface(seat->pointer_constraints, surface, seat->seat);
seat->set_constraint(constraint);
}

Surface* Server::surface_at(const double lx, const double ly, wlr_surface** wlr, double* sx, double* sy) {
Expand Down Expand Up @@ -206,7 +208,7 @@ static void request_activation_notify(wl_listener* listener, void* data) {
wlr_xdg_surface* xdg_surface = wlr_xdg_surface_from_wlr_surface(event->surface);
auto* view = dynamic_cast<View*>(static_cast<Surface*>(xdg_surface->surface->data));
if (view != nullptr && xdg_surface->mapped) {
server.focus_view(*view, xdg_surface->surface);
server.focus_view(view, xdg_surface->surface);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class Server {
Server();

Surface* surface_at(const double lx, const double ly, wlr_surface** wlr, double* sx, double* sy);
void focus_view(View& view, wlr_surface* surface = nullptr);
void focus_view(View* view, wlr_surface* surface = nullptr);
};

#endif
2 changes: 1 addition & 1 deletion src/surface/xdg_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ void XdgView::map() {

wlr_scene_node_set_enabled(scene_node, true);
is_maximized = xdg_toplevel.current.maximized;
server.focus_view(*this);
server.focus_view(this);
}

void XdgView::unmap() {
Expand Down
2 changes: 1 addition & 1 deletion src/surface/xwayland_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ void XWaylandView::map() {
wlr_scene_node_set_position(scene_node, current.x, current.y);

server.views.insert(server.views.begin(), this);
server.focus_view(*this);
server.focus_view(this);
}

void XWaylandView::unmap() {
Expand Down

0 comments on commit ea9e3b4

Please sign in to comment.