Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

session-lock: lock the screen even if the client provides no lock surface #2550

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 38 additions & 16 deletions plugins/protocols/session-lock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,20 +134,30 @@ class lock_crashed_node : public lock_base_node<simple_text_node_t>
set_size(output->get_screen_size());
}

void display()
void display(std::string text)
{
wf::cairo_text_t::params params(
1280 /* font_size */,
wf::color_t{0, 0, 0, 1} /* bg_color */,
wf::color_t{0.9, 0.9, 0.9, 1} /* fg_color */);
set_text_params(params);
// TODO: make the text smaller and display a useful message instead of a big explosion.
set_text("💥");
set_text(text);
auto layer_node = output->node_for_layer(wf::scene::layer::LOCK);
wf::scene::add_back(layer_node, shared_from_this());
if (!is_displayed)
{
wf::scene::add_back(layer_node, shared_from_this());
is_displayed = true;
}

wf::get_core().seat->set_active_node(shared_from_this());
}

void display_crashed()
{
display("💥");
}

// Ensure pointer interaction is not passed to views behind this node.
std::optional<wf::scene::input_node_t> find_node_at(const wf::pointf_t& at) override
{
Expand All @@ -156,6 +166,9 @@ class lock_crashed_node : public lock_base_node<simple_text_node_t>
result.local_coords = at;
return result;
}

private:
bool is_displayed = false;
};

class wf_session_lock_plugin : public wf::plugin_interface_t
Expand Down Expand Up @@ -253,7 +266,7 @@ class wf_session_lock_plugin : public wf::plugin_interface_t
output_states[output]->surface_node.reset();
if (output_states[output]->crashed_node)
{
output_states[output]->crashed_node->display();
output_states[output]->crashed_node->display_crashed();
}
}

Expand Down Expand Up @@ -285,6 +298,12 @@ class wf_session_lock_plugin : public wf::plugin_interface_t
{
disconnect_signals();
set_state(state == UNLOCKED ? DESTROYED : ZOMBIE);
if (state == ZOMBIE)
{
// ensure that the crashed node is displayed in this case as well
lock_all();
}

LOGC(LSHELL, "session lock destroyed");
});
destroy.connect(&lock->events.destroy);
Expand All @@ -310,17 +329,11 @@ class wf_session_lock_plugin : public wf::plugin_interface_t
void handle_output_added(wf::output_t *output)
{
output_states[output] = std::make_shared<output_state>(output);
if (state == LOCKED)
if ((state == LOCKED) || (state == ZOMBIE))
{
lock_output(output, output_states[output]);
}

if (state == ZOMBIE)
{
output->set_inhibited(true);
output_states[output]->crashed_node->display();
}

output->connect(&output_changed);
}

Expand All @@ -346,12 +359,17 @@ class wf_session_lock_plugin : public wf::plugin_interface_t
void lock_output(wf::output_t *output, std::shared_ptr<output_state> output_state)
{
output->set_inhibited(true);
if (output_state->surface_node)
if (state == ZOMBIE)
{
output_state->crashed_node->display_crashed();
} else if (output_state->surface_node)
{
output_state->surface_node->display();
} else
{
// if the surface node has not yet been displayed we show an empty surface
output_state->crashed_node->display("");
}

// TODO: if the surface node has not yet been displayed, display... something?
}

void lock_all()
Expand All @@ -361,8 +379,12 @@ class wf_session_lock_plugin : public wf::plugin_interface_t
lock_output(output, output_state);
}

wlr_session_lock_v1_send_locked(lock);
set_state(LOCKED);
if (state != ZOMBIE)
{
wlr_session_lock_v1_send_locked(lock);
set_state(LOCKED);
}

LOGC(LSHELL, "lock");
}

Expand Down