Skip to content

Commit 07b3714

Browse files
committed
session-manager: implement configurable server-side decoration
1 parent 6d9ada9 commit 07b3714

File tree

7 files changed

+30
-5
lines changed

7 files changed

+30
-5
lines changed

scripts/snap-wrapper.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ if [ "$(snapctl get touch-emulation.enable)" = false ]; then
4747
export ANBOX_ENABLE_TOUCH_EMULATION=false
4848
fi
4949

50+
if [ "$(snapctl get server-side-decoration.enable)" = true ]; then
51+
export ANBOX_FORCE_SERVER_SIDE_DECORATION=true
52+
fi
53+
5054
# Use custom Anbox binary for debugging purposes if available
5155
ANBOX="$SNAP"/usr/bin/anbox
5256
if [ -e "$SNAP_COMMON"/anbox.debug ]; then

src/anbox/cmds/session_manager.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ anbox::cmds::SessionManager::SessionManager()
115115
flag(cli::make_flag(cli::Name{"no-touch-emulation"},
116116
cli::Description{"Disable touch emulation applied on mouse inputs"},
117117
no_touch_emulation_));
118+
flag(cli::make_flag(cli::Name{"server-side-decoration"},
119+
cli::Description{"Prefer to use server-side decoration instead of client-side decoration"},
120+
server_side_decoration_));
118121

119122
action([this](const cli::Command::Context &) {
120123
auto trap = core::posix::trap_signals_for_process(
@@ -161,10 +164,15 @@ anbox::cmds::SessionManager::SessionManager()
161164
if (should_enable_touch_emulation == "false" || no_touch_emulation_)
162165
no_touch_emulation_ = true;
163166

167+
const auto should_force_server_side_decoration = utils::get_env_value("ANBOX_FORCE_SERVER_SIDE_DECORATION", "false");
168+
if (should_force_server_side_decoration == "true")
169+
server_side_decoration_ = true;
170+
164171
platform::Configuration platform_config;
165172
platform_config.single_window = single_window_;
166173
platform_config.no_touch_emulation = no_touch_emulation_;
167174
platform_config.display_frame = display_frame;
175+
platform_config.server_side_decoration = server_side_decoration_;
168176

169177
auto platform = platform::create(utils::get_env_value("ANBOX_PLATFORM", "sdl"),
170178
input_manager,
@@ -259,6 +267,9 @@ anbox::cmds::SessionManager::SessionManager()
259267
// See https://github.com/anbox/anbox/issues/780 for further details.
260268
container_configuration.extra_properties.push_back("ro.boot.fake_battery=1");
261269

270+
if (server_side_decoration_)
271+
container_configuration.extra_properties.push_back("ro.anbox.no_decorations=1");
272+
262273
if (!standalone_) {
263274
container_configuration.bind_mounts = {
264275
{qemu_pipe_connector->socket_file(), "/dev/qemu_pipe"},

src/anbox/cmds/session_manager.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class SessionManager : public cli::CommandWithFlagsAndAction {
5151
bool use_system_dbus_ = false;
5252
bool use_software_rendering_ = false;
5353
bool no_touch_emulation_ = false;
54+
bool server_side_decoration_ = false;
5455
};
5556
} // namespace cmds
5657
} // namespace anbox

src/anbox/platform/base_platform.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ struct Configuration {
6464
graphics::Rect display_frame = graphics::Rect::Invalid;
6565
bool single_window = false;
6666
bool no_touch_emulation = false;
67+
bool server_side_decoration = false;
6768
};
6869

6970
std::shared_ptr<BasePlatform> create(const std::string &name,

src/anbox/platform/sdl/platform.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,8 @@ std::shared_ptr<wm::Window> Platform::create_window(
418418
}
419419

420420
auto id = next_window_id();
421-
auto w = std::make_shared<Window>(renderer_, id, task, shared_from_this(), frame, title, !window_size_immutable_);
421+
auto w = std::make_shared<Window>(renderer_, id, task, shared_from_this(), frame, title,
422+
!window_size_immutable_, !config_.server_side_decoration);
422423
focused_sdl_window_id_ = w->window_id();
423424
windows_.insert({id, w});
424425
return w;

src/anbox/platform/sdl/window.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ Window::Window(const std::shared_ptr<Renderer> &renderer,
4646
const std::shared_ptr<Observer> &observer,
4747
const graphics::Rect &frame,
4848
const std::string &title,
49-
bool resizable)
49+
bool resizable,
50+
bool borderless)
5051
: wm::Window(renderer, task, frame, title),
5152
id_(id),
5253
observer_(observer),
@@ -59,7 +60,9 @@ Window::Window(const std::shared_ptr<Renderer> &renderer,
5960
// initializing GL here will cause a surface to be created and the
6061
// renderer will attempt to create one too which will not work as
6162
// only a single surface per EGLNativeWindowType is supported.
62-
std::uint32_t flags = SDL_WINDOW_BORDERLESS;
63+
std::uint32_t flags = 0;
64+
if (borderless)
65+
flags |= SDL_WINDOW_BORDERLESS;
6366
if (resizable)
6467
flags |= SDL_WINDOW_RESIZABLE;
6568

@@ -72,7 +75,10 @@ Window::Window(const std::shared_ptr<Renderer> &renderer,
7275
BOOST_THROW_EXCEPTION(std::runtime_error(message));
7376
}
7477

75-
if (utils::get_env_value("ANBOX_NO_SDL_WINDOW_HIT_TEST", "false") == "false")
78+
// If we create a window with border (server-side decoration), We
79+
// should not set hit test handler beacuse we don't need to simulate
80+
// the behavior of the title bar and resize area.
81+
if (borderless && utils::get_env_value("ANBOX_NO_SDL_WINDOW_HIT_TEST", "false") == "false")
7682
if (SDL_SetWindowHitTest(window_, &Window::on_window_hit, this) < 0)
7783
BOOST_THROW_EXCEPTION(std::runtime_error("Failed to register for window hit test"));
7884

src/anbox/platform/sdl/window.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ class Window : public std::enable_shared_from_this<Window>, public wm::Window {
5252
const std::shared_ptr<Observer> &observer,
5353
const graphics::Rect &frame,
5454
const std::string &title,
55-
bool resizable);
55+
bool resizable,
56+
bool borderless);
5657
~Window();
5758

5859
void process_event(const SDL_Event &event);

0 commit comments

Comments
 (0)