Skip to content

Commit

Permalink
Implement the session lock protocol (#2162)
Browse files Browse the repository at this point in the history
* Make wlr_{surface,subsurface}_controller_t common utilities.

These classes are useful and needed by any code that deals with
surfaces, because such code usually needs to deal with
subsurfaces as well.

Move the include files into api/wayfire/unstable so they can be
used by code all over the tree, and rename them to reflect the
utility classes that they contain.

* Add a public API to inhibit/uninhibit outputs.

This will allow lockscreens to be implemented in plugins.

* Factor the text label rendering out of wset into a utility class.

This adds a simple node that can display text.

* Add a LOCK scenegraph layer.

This will be used by the upcoming implementation of the
ext-session-lock protocol.

* Implement the session lock protocol

Currently implemented:

- Locking and unlocking.
- Display above all desktop layers, including OVERLAY (but below
  DWIDGET).
- Waiting for the client to display locked surfaces before
  declaring the screen to be locked. If the client does not
  display all surfaces, locks anyway after a timeout.
- Multiple outputs, including outputs being added/removed while
  locking or locked.
- Leaving the screen locked if the client crashes (but allows a
  new client to come in and lock the screen).

TODO:
- Deal with outputs being resized.
- Properly display text if the screenlocker crashes. Currently it
  just displays two a big "explosion" emoji.
- Use a view instead of a plain wlr_surface_node?

Tested with swaylock.

Fixes #1494
Fixes #1358
  • Loading branch information
lcolitti authored Mar 21, 2024
1 parent dba4f22 commit ec91bfb
Show file tree
Hide file tree
Showing 28 changed files with 561 additions and 108 deletions.
1 change: 1 addition & 0 deletions metadata/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,4 @@ install_data('shortcuts-inhibit.xml', install_dir: conf_data.get('PLUGIN_XML_DIR
install_data('wsets.xml', install_dir: conf_data.get('PLUGIN_XML_DIR'))
install_data('wayfire-shell.xml', install_dir: conf_data.get('PLUGIN_XML_DIR'))
install_data('xdg-activation.xml', install_dir: conf_data.get('PLUGIN_XML_DIR'))
install_data('session-lock.xml', install_dir: conf_data.get('PLUGIN_XML_DIR'))
8 changes: 8 additions & 0 deletions metadata/session-lock.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0"?>
<wayfire>
<plugin name="session-lock">
<_short>Session Lock Protocol</_short>
<_long>An implementation of the ext-session-lock-v1 protocol. Provides more secure screen locking.</_long>
<category>Utility</category>
</plugin>
</wayfire>
72 changes: 72 additions & 0 deletions plugins/common/wayfire/plugins/common/simple-text-node.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#include "wayfire/opengl.hpp"
#include "wayfire/output.hpp"
#include "wayfire/scene.hpp"
#include <wayfire/plugins/common/cairo-util.hpp>

class simple_text_node_t : public wf::scene::node_t
{
class render_instance_t : public wf::scene::simple_render_instance_t<simple_text_node_t>
{
public:
using simple_render_instance_t::simple_render_instance_t;

void render(const wf::render_target_t& target, const wf::region_t& region)
{
OpenGL::render_begin(target);

auto g = self->get_bounding_box();
for (auto box : region)
{
target.logic_scissor(wlr_box_from_pixman_box(box));
OpenGL::render_texture(self->cr_text.tex.tex, target, g, glm::vec4(1.0f),
OpenGL::TEXTURE_TRANSFORM_INVERT_Y);
}

OpenGL::render_end();
}
};

wf::cairo_text_t cr_text;

public:
simple_text_node_t() : node_t(false)
{}

void gen_render_instances(std::vector<wf::scene::render_instance_uptr>& instances,
wf::scene::damage_callback push_damage, wf::output_t *output) override
{
instances.push_back(std::make_unique<render_instance_t>(this, push_damage, output));
}

wf::geometry_t get_bounding_box() override
{
return wf::construct_box(position, size.value_or(cr_text.get_size()));
}

void set_position(wf::point_t position)
{
this->position = position;
}

void set_size(wf::dimensions_t size)
{
this->size = size;
}

void set_text_params(wf::cairo_text_t::params params)
{
this->params = params;
}

void set_text(std::string text)
{
wf::scene::damage_node(this->shared_from_this(), get_bounding_box());
cr_text.render_text(text, params);
wf::scene::damage_node(this->shared_from_this(), get_bounding_box());
}

private:
wf::cairo_text_t::params params;
std::optional<wf::dimensions_t> size;
wf::point_t position;
};
5 changes: 3 additions & 2 deletions plugins/protocols/meson.build
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
protocol_plugins = [
'foreign-toplevel', 'gtk-shell', 'wayfire-shell', 'xdg-activation', 'shortcuts-inhibit', 'input-method-v1'
'foreign-toplevel', 'gtk-shell', 'wayfire-shell', 'xdg-activation', 'shortcuts-inhibit',
'input-method-v1', 'session-lock'
]

all_include_dirs = [wayfire_api_inc, wayfire_conf_inc, plugins_common_inc]
all_deps = [wlroots, pixman, wfconfig, wf_protos, json]
all_deps = [wlroots, pixman, wfconfig, wf_protos, json, cairo, pango]

foreach plugin : protocol_plugins
shared_module(plugin, plugin + '.cpp',
Expand Down
Loading

0 comments on commit ec91bfb

Please sign in to comment.