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

Demonstrate using the window decoration strategy #3459

Merged
merged 2 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
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
26 changes: 26 additions & 0 deletions examples/miral-shell/shell_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,38 @@
#include <miral/internal_client.h>
#include <miral/command_line_option.h>
#include <miral/cursor_theme.h>
#include <miral/decorations.h>
#include <miral/keymap.h>
#include <miral/toolkit_event.h>
#include <miral/x11_support.h>
#include <miral/wayland_extensions.h>

#include <xkbcommon/xkbcommon-keysyms.h>

#include <cstring>

namespace
{
struct ConfigureDecorations
{
miral::Decorations const decorations{[]
{
if (auto const strategy = getenv("MIRAL_SHELL_DECORATIONS"))
{
if (strcmp(strategy, "always-ssd") == 0) return miral::Decorations::always_ssd();
if (strcmp(strategy, "prefer-ssd") == 0) return miral::Decorations::prefer_ssd();
if (strcmp(strategy, "always-csd") == 0) return miral::Decorations::always_csd();
}
return miral::Decorations::prefer_csd();
}()};
Comment on lines +44 to +53
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is quite neat!
I would've done it like so:

ConfigureDecorations() 
    : decorations{init_decorations()}
{
}

// somewhere private
static auto init_decorations() -> miral::Decorations 
{
  // lambda code
}

I'll definitely add this to my arsenal though

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, immediately-executed lambdas are a way of turning C++ into an expression language. It can be particularly useful for const initialisation.


void operator()(mir::Server& s) const
{
decorations(s);
}
};
mattkae marked this conversation as resolved.
Show resolved Hide resolved
}

int main(int argc, char const* argv[])
{
using namespace miral;
Expand Down Expand Up @@ -113,6 +138,7 @@ int main(int argc, char const* argv[])
CursorTheme{"default:DMZ-White"},
WaylandExtensions{},
X11Support{},
ConfigureDecorations{},
window_managers,
display_configuration_options,
external_client_launcher,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,8 @@ auto mf::get_standard_extensions() -> std::vector<std::string>
mw::TextInputManagerV1::interface_name,
mw::TextInputManagerV2::interface_name,
mw::TextInputManagerV3::interface_name,
mw::MirShellV1::interface_name};
mw::MirShellV1::interface_name,
mw::XdgDecorationManagerV1::interface_name};
Comment on lines +322 to +323
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like I forgot this one in my original PR, thanks for fixing it :)

}

auto mf::get_supported_extensions() -> std::vector<std::string>
Expand Down
Loading