/* * SPDX-FileCopyrightText: 2016-2016 CSSlayer * * SPDX-License-Identifier: LGPL-2.1-or-later * */ #include "waylandui.h" #include #include #include "fcitx/userinterface.h" #include "classicui.h" #include "common.h" #include "display.h" #include "ext_background_effect_manager_v1.h" #include "waylandcursortheme.h" #include "waylandinputwindow.h" #include "waylandpointer.h" #include "waylandshmwindow.h" #include "wl_compositor.h" #include "wl_seat.h" #include "wl_shm.h" #include "wp_fractional_scale_manager_v1.h" #include "wp_viewporter.h" #include "zwp_input_panel_v1.h" namespace fcitx::m3ui { WaylandUI::WaylandUI(M3UI *parent, const std::string &name, wl_display *display) : UIInterface("wayland:" + name), parent_(parent), display_( static_cast(wl_display_get_user_data(display))) { display_->requestGlobals(); display_->requestGlobals(); display_->requestGlobals(); display_->requestGlobals(); display_->requestGlobals(); display_->requestGlobals(); display_->requestGlobals(); panelConn_ = display_->globalCreated().connect( [this](const std::string &name, const std::shared_ptr &) { if (name == wayland::ZwpInputPanelV1::interface) { if (inputWindow_) { inputWindow_->initPanel(); } } else if (name == wayland::WlCompositor::interface || name == wayland::WlShm::interface) { setupInputWindow(); } else if (name == wayland::WlSeat::interface) { auto seat = display_->getGlobal(); if (seat) { pointer_ = std::make_unique(this, seat.get()); } } else if (name == wayland::ExtBackgroundEffectManagerV1::interface) { if (inputWindow_) { inputWindow_->setBlurManager( display_->getGlobal< wayland::ExtBackgroundEffectManagerV1>()); } } else if (name == wayland::WpFractionalScaleManagerV1::interface || name == wayland::WpViewporter::interface) { if (inputWindow_) { inputWindow_->updateScale(); } } }); panelRemovedConn_ = display_->globalRemoved().connect( [this](const std::string &name, const std::shared_ptr &) { if (name == wayland::ZwpInputPanelV1::interface) { if (inputWindow_) { inputWindow_->resetPanel(); } } else if (name == wayland::ExtBackgroundEffectManagerV1::interface) { if (inputWindow_) { inputWindow_->setBlurManager(nullptr); } } else if (name == wayland::WpFractionalScaleManagerV1::interface || name == wayland::WpViewporter::interface) { if (inputWindow_) { inputWindow_->updateScale(); } } }); auto seat = display_->getGlobal(); if (seat) { pointer_ = std::make_unique(this, seat.get()); } setupInputWindow(); } WaylandUI::~WaylandUI() {} void WaylandUI::update(UserInterfaceComponent component, InputContext *inputContext) { if (inputWindow_ && component == UserInterfaceComponent::InputPanel) { CLASSICUI_DEBUG() << "Update Wayland Input Window"; inputWindow_->update(inputContext); } } void WaylandUI::suspend() { if (!inputWindow_) { return; } inputWindow_->update(nullptr); } void WaylandUI::resume() { CLASSICUI_DEBUG() << "Resume WaylandUI display name:" << display_; CLASSICUI_DEBUG() << "Wayland Input window is initialized:" << !!inputWindow_; } void WaylandUI::setupInputWindow() { if (inputWindow_) { return; } // Unable to draw window. if (!display_->getGlobal()) { return; } // Unable to create surface. if (!display_->getGlobal()) { return; } cursorTheme_ = std::make_unique(this); inputWindow_ = std::make_unique(this); inputWindow_->initPanel(); inputWindow_->setBlurManager( display_->getGlobal()); } std::unique_ptr WaylandUI::newWindow() { return std::make_unique(this); } } // namespace fcitx::m3ui