Skip to content

Commit

Permalink
Initial version of layer focus - untested
Browse files Browse the repository at this point in the history
  • Loading branch information
serebit committed Jul 5, 2024
1 parent f9ac0e5 commit 595aa39
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
42 changes: 42 additions & 0 deletions src/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,48 @@ void Server::focus_view(std::shared_ptr<View>&& view) {
view->set_activated(true);
}

void Server::try_focus_next_exclusive_layer() {
std::shared_ptr<Layer> topmost_exclusive_layer = nullptr;

// find the topmost layer in exclusive focus mode. if there are multiple within a single scene layer, the spec defines that
// focus order within that scene layer is implementation defined, so it doesn't matter which is chosen
for (const auto& output : outputs) {
for (const auto& layer : output->layers) {
if (layer->wlr.current.keyboard_interactive == ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_EXCLUSIVE &&
(topmost_exclusive_layer == nullptr || layer->scene_layer > topmost_exclusive_layer->scene_layer)) {
topmost_exclusive_layer = layer;
}
}
}

focus_layer(topmost_exclusive_layer);
}

void Server::focus_layer(std::shared_ptr<Layer> layer) {
if (layer == nullptr) {
focused_layer.reset();
if (focused_view.lock() != nullptr) {
focused_view.lock()->set_activated(true);
}
}

// if there's already an exclusive focused shell layer with an equal or higher scene layer, just return
auto focused_layer_locked = focused_layer.lock();
if (focused_layer_locked != nullptr &&
focused_layer_locked->wlr.current.keyboard_interactive == ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_EXCLUSIVE &&
focused_layer_locked->scene_layer >= layer->scene_layer) {
return;
}

focused_layer = layer;

const auto* keyboard = wlr_seat_get_keyboard(seat->wlr);
if (keyboard != nullptr) {
wlr_seat_keyboard_notify_enter(
seat->wlr, layer->get_wlr_surface(), keyboard->keycodes, keyboard->num_keycodes, &keyboard->modifiers);
}
}

std::weak_ptr<Surface> Server::surface_at(const double lx, const double ly, wlr_surface** wlr, double* sx, double* sy) const {
/* This returns the topmost node in the scene at the given layout coords.
* we only care about surface nodes as we are specifically looking for a
Expand Down
2 changes: 2 additions & 0 deletions src/server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ class Server final : public std::enable_shared_from_this<Server> {

std::weak_ptr<Surface> surface_at(double lx, double ly, wlr_surface** wlr, double* sx, double* sy) const;
void focus_view(std::shared_ptr<View>&& view);
void focus_layer(std::shared_ptr<Layer> layer);
void try_focus_next_exclusive_layer();
bool is_restricted(const wl_global* global) const;
};

Expand Down
14 changes: 13 additions & 1 deletion src/surface/layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ static void wlr_layer_surface_v1_destroy_notify(wl_listener* listener, [[maybe_u
static void wlr_layer_surface_v1_commit_notify(wl_listener* listener, [[maybe_unused]] void* data) {
Layer& layer = magpie_container_of(listener, layer, commit);

const Server& server = layer.output.server;
Server& server = layer.output.server;
const wlr_layer_surface_v1& surface = layer.wlr;

const uint32_t committed = surface.current.committed;
Expand All @@ -88,6 +88,18 @@ static void wlr_layer_surface_v1_commit_notify(wl_listener* listener, [[maybe_un
wlr_scene_node_reparent(layer.scene_node, server.scene_layers[layer.scene_layer]);
}

if ((committed & WLR_LAYER_SURFACE_V1_STATE_KEYBOARD_INTERACTIVITY) != 0) {
switch (layer.wlr.current.keyboard_interactive) {
case ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_NONE:
server.try_focus_next_exclusive_layer();
break;
case ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_ON_DEMAND:
case ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_EXCLUSIVE:
server.focus_layer(std::dynamic_pointer_cast<Layer>(layer.shared_from_this()));
break;
}
}

if (committed != 0) {
layer.output.update_layout();
}
Expand Down

0 comments on commit 595aa39

Please sign in to comment.