mirror of
https://github.com/hyprwm/Hyprland
synced 2024-11-07 17:25:58 +01:00
xdg-dialog: implement new protocol
This commit is contained in:
parent
242e06b242
commit
1c9d56998d
9 changed files with 187 additions and 10 deletions
|
@ -315,6 +315,7 @@ protocolnew("stable/viewporter" "viewporter" false)
|
||||||
protocolnew("stable/linux-dmabuf" "linux-dmabuf-v1" false)
|
protocolnew("stable/linux-dmabuf" "linux-dmabuf-v1" false)
|
||||||
protocolnew("staging/drm-lease" "drm-lease-v1" false)
|
protocolnew("staging/drm-lease" "drm-lease-v1" false)
|
||||||
protocolnew("staging/linux-drm-syncobj" "linux-drm-syncobj-v1" false)
|
protocolnew("staging/linux-drm-syncobj" "linux-drm-syncobj-v1" false)
|
||||||
|
protocolnew("staging/xdg-dialog" "xdg-dialog-v1" false)
|
||||||
|
|
||||||
protocolwayland()
|
protocolwayland()
|
||||||
|
|
||||||
|
|
|
@ -60,6 +60,7 @@ new_protocols = [
|
||||||
[wl_protocol_dir, 'stable/linux-dmabuf/linux-dmabuf-v1.xml'],
|
[wl_protocol_dir, 'stable/linux-dmabuf/linux-dmabuf-v1.xml'],
|
||||||
[wl_protocol_dir, 'staging/drm-lease/drm-lease-v1.xml'],
|
[wl_protocol_dir, 'staging/drm-lease/drm-lease-v1.xml'],
|
||||||
[wl_protocol_dir, 'staging/linux-drm-syncobj/linux-drm-syncobj-v1.xml'],
|
[wl_protocol_dir, 'staging/linux-drm-syncobj/linux-drm-syncobj-v1.xml'],
|
||||||
|
[wl_protocol_dir, 'staging/xdg-dialog/xdg-dialog-v1.xml'],
|
||||||
]
|
]
|
||||||
|
|
||||||
wl_protos_src = []
|
wl_protos_src = []
|
||||||
|
|
|
@ -1888,6 +1888,8 @@ void CCompositor::updateWindowAnimatedDecorationValues(PHLWINDOW pWindow) {
|
||||||
pWindow->m_fBorderFadeAnimationProgress = 1.f;
|
pWindow->m_fBorderFadeAnimationProgress = 1.f;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const bool IS_SHADOWED_BY_MODAL = pWindow->m_pXDGSurface && pWindow->m_pXDGSurface->toplevel && pWindow->m_pXDGSurface->toplevel->anyChildModal();
|
||||||
|
|
||||||
// border
|
// border
|
||||||
const auto RENDERDATA = g_pLayoutManager->getCurrentLayout()->requestRenderHints(pWindow);
|
const auto RENDERDATA = g_pLayoutManager->getCurrentLayout()->requestRenderHints(pWindow);
|
||||||
if (RENDERDATA.isBorderGradient)
|
if (RENDERDATA.isBorderGradient)
|
||||||
|
@ -1921,11 +1923,16 @@ void CCompositor::updateWindowAnimatedDecorationValues(PHLWINDOW pWindow) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// dim
|
// dim
|
||||||
if (pWindow == m_pLastWindow.lock() || pWindow->m_sWindowData.noDim.valueOrDefault() || !*PDIMENABLED) {
|
float goalDim = 1.F;
|
||||||
pWindow->m_fDimPercent = 0;
|
if (pWindow == m_pLastWindow.lock() || pWindow->m_sWindowData.noDim.valueOrDefault() || !*PDIMENABLED)
|
||||||
} else {
|
goalDim = 0;
|
||||||
pWindow->m_fDimPercent = *PDIMSTRENGTH;
|
else
|
||||||
}
|
goalDim = *PDIMSTRENGTH;
|
||||||
|
|
||||||
|
if (IS_SHADOWED_BY_MODAL)
|
||||||
|
goalDim += (1.F - goalDim) / 2.F;
|
||||||
|
|
||||||
|
pWindow->m_fDimPercent = goalDim;
|
||||||
|
|
||||||
// shadow
|
// shadow
|
||||||
if (!pWindow->isX11OverrideRedirect() && !pWindow->m_bX11DoesntWantBorders) {
|
if (!pWindow->isX11OverrideRedirect() && !pWindow->m_bX11DoesntWantBorders) {
|
||||||
|
|
|
@ -43,6 +43,7 @@
|
||||||
#include "../protocols/ToplevelExport.hpp"
|
#include "../protocols/ToplevelExport.hpp"
|
||||||
#include "../protocols/TextInputV1.hpp"
|
#include "../protocols/TextInputV1.hpp"
|
||||||
#include "../protocols/GlobalShortcuts.hpp"
|
#include "../protocols/GlobalShortcuts.hpp"
|
||||||
|
#include "../protocols/XDGDialog.hpp"
|
||||||
|
|
||||||
#include "../protocols/core/Seat.hpp"
|
#include "../protocols/core/Seat.hpp"
|
||||||
#include "../protocols/core/DataDevice.hpp"
|
#include "../protocols/core/DataDevice.hpp"
|
||||||
|
@ -150,6 +151,7 @@ CProtocolManager::CProtocolManager() {
|
||||||
PROTO::screencopy = std::make_unique<CScreencopyProtocol>(&zwlr_screencopy_manager_v1_interface, 3, "Screencopy");
|
PROTO::screencopy = std::make_unique<CScreencopyProtocol>(&zwlr_screencopy_manager_v1_interface, 3, "Screencopy");
|
||||||
PROTO::toplevelExport = std::make_unique<CToplevelExportProtocol>(&hyprland_toplevel_export_manager_v1_interface, 2, "ToplevelExport");
|
PROTO::toplevelExport = std::make_unique<CToplevelExportProtocol>(&hyprland_toplevel_export_manager_v1_interface, 2, "ToplevelExport");
|
||||||
PROTO::globalShortcuts = std::make_unique<CGlobalShortcutsProtocol>(&hyprland_global_shortcuts_manager_v1_interface, 1, "GlobalShortcuts");
|
PROTO::globalShortcuts = std::make_unique<CGlobalShortcutsProtocol>(&hyprland_global_shortcuts_manager_v1_interface, 1, "GlobalShortcuts");
|
||||||
|
PROTO::xdgDialog = std::make_unique<CXDGDialogProtocol>(&xdg_dialog_v1_interface, 1, "XDGDialog");
|
||||||
|
|
||||||
for (auto const& b : g_pCompositor->m_pAqBackend->getImplementations()) {
|
for (auto const& b : g_pCompositor->m_pAqBackend->getImplementations()) {
|
||||||
if (b->type() != Aquamarine::AQ_BACKEND_DRM)
|
if (b->type() != Aquamarine::AQ_BACKEND_DRM)
|
||||||
|
|
88
src/protocols/XDGDialog.cpp
Normal file
88
src/protocols/XDGDialog.cpp
Normal file
|
@ -0,0 +1,88 @@
|
||||||
|
#include "XDGDialog.hpp"
|
||||||
|
#include "XDGShell.hpp"
|
||||||
|
#include "../desktop/WLSurface.hpp"
|
||||||
|
#include "../Compositor.hpp"
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
CXDGDialogV1Resource::CXDGDialogV1Resource(SP<CXdgDialogV1> resource_, SP<CXDGToplevelResource> toplevel_) : resource(resource_), toplevel(toplevel_) {
|
||||||
|
if (!good())
|
||||||
|
return;
|
||||||
|
|
||||||
|
resource->setDestroy([this](CXdgDialogV1* r) { PROTO::xdgDialog->destroyResource(this); });
|
||||||
|
resource->setOnDestroy([this](CXdgDialogV1* r) { PROTO::xdgDialog->destroyResource(this); });
|
||||||
|
|
||||||
|
resource->setSetModal([this](CXdgDialogV1* r) {
|
||||||
|
modal = true;
|
||||||
|
updateWindow();
|
||||||
|
});
|
||||||
|
|
||||||
|
resource->setUnsetModal([this](CXdgDialogV1* r) {
|
||||||
|
modal = false;
|
||||||
|
updateWindow();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void CXDGDialogV1Resource::updateWindow() {
|
||||||
|
if (!toplevel || !toplevel->parent || !toplevel->parent->owner)
|
||||||
|
return;
|
||||||
|
|
||||||
|
auto HLSurface = CWLSurface::fromResource(toplevel->parent->owner->surface.lock());
|
||||||
|
if (!HLSurface || !HLSurface->getWindow())
|
||||||
|
return;
|
||||||
|
|
||||||
|
g_pCompositor->updateWindowAnimatedDecorationValues(HLSurface->getWindow());
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CXDGDialogV1Resource::good() {
|
||||||
|
return resource->resource();
|
||||||
|
}
|
||||||
|
|
||||||
|
CXDGWmDialogManagerResource::CXDGWmDialogManagerResource(SP<CXdgWmDialogV1> resource_) : resource(resource_) {
|
||||||
|
if (!good())
|
||||||
|
return;
|
||||||
|
|
||||||
|
resource->setDestroy([this](CXdgWmDialogV1* r) { PROTO::xdgDialog->destroyResource(this); });
|
||||||
|
resource->setOnDestroy([this](CXdgWmDialogV1* r) { PROTO::xdgDialog->destroyResource(this); });
|
||||||
|
|
||||||
|
resource->setGetXdgDialog([this](CXdgWmDialogV1* r, uint32_t id, wl_resource* toplevel) {
|
||||||
|
auto tl = CXDGToplevelResource::fromResource(toplevel);
|
||||||
|
if (!tl) {
|
||||||
|
r->error(-1, "Toplevel inert");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto RESOURCE = PROTO::xdgDialog->m_vDialogs.emplace_back(makeShared<CXDGDialogV1Resource>(makeShared<CXdgDialogV1>(r->client(), r->version(), id), tl));
|
||||||
|
|
||||||
|
if (!RESOURCE->good()) {
|
||||||
|
r->noMemory();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
tl->dialog = RESOURCE;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CXDGWmDialogManagerResource::good() {
|
||||||
|
return resource->resource();
|
||||||
|
}
|
||||||
|
|
||||||
|
CXDGDialogProtocol::CXDGDialogProtocol(const wl_interface* iface, const int& ver, const std::string& name) : IWaylandProtocol(iface, ver, name) {
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CXDGDialogProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) {
|
||||||
|
const auto RESOURCE = m_vManagers.emplace_back(makeShared<CXDGWmDialogManagerResource>(makeShared<CXdgWmDialogV1>(client, ver, id)));
|
||||||
|
|
||||||
|
if (!RESOURCE->good()) {
|
||||||
|
wl_client_post_no_memory(client);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CXDGDialogProtocol::destroyResource(CXDGWmDialogManagerResource* res) {
|
||||||
|
std::erase_if(m_vManagers, [&](const auto& other) { return other.get() == res; });
|
||||||
|
}
|
||||||
|
|
||||||
|
void CXDGDialogProtocol::destroyResource(CXDGDialogV1Resource* res) {
|
||||||
|
std::erase_if(m_vDialogs, [&](const auto& other) { return other.get() == res; });
|
||||||
|
}
|
57
src/protocols/XDGDialog.hpp
Normal file
57
src/protocols/XDGDialog.hpp
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
#include <vector>
|
||||||
|
#include <unordered_map>
|
||||||
|
#include "WaylandProtocol.hpp"
|
||||||
|
#include "xdg-dialog-v1.hpp"
|
||||||
|
|
||||||
|
class CXDGToplevelResource;
|
||||||
|
|
||||||
|
class CXDGDialogV1Resource {
|
||||||
|
public:
|
||||||
|
CXDGDialogV1Resource(SP<CXdgDialogV1> resource_, SP<CXDGToplevelResource> toplevel_);
|
||||||
|
|
||||||
|
bool good();
|
||||||
|
|
||||||
|
bool modal = false;
|
||||||
|
|
||||||
|
private:
|
||||||
|
SP<CXdgDialogV1> resource;
|
||||||
|
WP<CXDGToplevelResource> toplevel;
|
||||||
|
|
||||||
|
void updateWindow();
|
||||||
|
};
|
||||||
|
|
||||||
|
class CXDGWmDialogManagerResource {
|
||||||
|
public:
|
||||||
|
CXDGWmDialogManagerResource(SP<CXdgWmDialogV1> resource_);
|
||||||
|
|
||||||
|
bool good();
|
||||||
|
|
||||||
|
private:
|
||||||
|
SP<CXdgWmDialogV1> resource;
|
||||||
|
};
|
||||||
|
|
||||||
|
class CXDGDialogProtocol : public IWaylandProtocol {
|
||||||
|
public:
|
||||||
|
CXDGDialogProtocol(const wl_interface* iface, const int& ver, const std::string& name);
|
||||||
|
|
||||||
|
virtual void bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void onManagerResourceDestroy(wl_resource* res);
|
||||||
|
void destroyResource(CXDGWmDialogManagerResource* res);
|
||||||
|
void destroyResource(CXDGDialogV1Resource* res);
|
||||||
|
|
||||||
|
//
|
||||||
|
std::vector<SP<CXDGWmDialogManagerResource>> m_vManagers;
|
||||||
|
std::vector<SP<CXDGDialogV1Resource>> m_vDialogs;
|
||||||
|
|
||||||
|
friend class CXDGWmDialogManagerResource;
|
||||||
|
friend class CXDGDialogV1Resource;
|
||||||
|
};
|
||||||
|
|
||||||
|
namespace PROTO {
|
||||||
|
inline UP<CXDGDialogProtocol> xdgDialog;
|
||||||
|
};
|
|
@ -1,10 +1,12 @@
|
||||||
#include "XDGShell.hpp"
|
#include "XDGShell.hpp"
|
||||||
|
#include "XDGDialog.hpp"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include "../Compositor.hpp"
|
#include "../Compositor.hpp"
|
||||||
#include "../managers/SeatManager.hpp"
|
#include "../managers/SeatManager.hpp"
|
||||||
#include "core/Seat.hpp"
|
#include "core/Seat.hpp"
|
||||||
#include "core/Compositor.hpp"
|
#include "core/Compositor.hpp"
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
#include <ranges>
|
||||||
|
|
||||||
void SXDGPositionerState::setAnchor(xdgPositionerAnchor edges) {
|
void SXDGPositionerState::setAnchor(xdgPositionerAnchor edges) {
|
||||||
anchor.setTop(edges == XDG_POSITIONER_ANCHOR_TOP || edges == XDG_POSITIONER_ANCHOR_TOP_LEFT || edges == XDG_POSITIONER_ANCHOR_TOP_RIGHT);
|
anchor.setTop(edges == XDG_POSITIONER_ANCHOR_TOP || edges == XDG_POSITIONER_ANCHOR_TOP_LEFT || edges == XDG_POSITIONER_ANCHOR_TOP_RIGHT);
|
||||||
|
@ -207,15 +209,25 @@ CXDGToplevelResource::CXDGToplevelResource(SP<CXdgToplevel> resource_, SP<CXDGSu
|
||||||
});
|
});
|
||||||
|
|
||||||
resource->setSetParent([this](CXdgToplevel* r, wl_resource* parentR) {
|
resource->setSetParent([this](CXdgToplevel* r, wl_resource* parentR) {
|
||||||
|
auto oldParent = parent;
|
||||||
|
|
||||||
|
if (parent)
|
||||||
|
std::erase(parent->children, self);
|
||||||
|
|
||||||
auto newp = parentR ? CXDGToplevelResource::fromResource(parentR) : nullptr;
|
auto newp = parentR ? CXDGToplevelResource::fromResource(parentR) : nullptr;
|
||||||
parent = newp;
|
parent = newp;
|
||||||
|
|
||||||
LOGM(LOG, "Toplevel {:x} sets parent to {:x}", (uintptr_t)this, (uintptr_t)newp.get());
|
if (parent)
|
||||||
|
parent->children.emplace_back(self);
|
||||||
|
|
||||||
|
LOGM(LOG, "Toplevel {:x} sets parent to {:x}{}", (uintptr_t)this, (uintptr_t)newp.get(), (oldParent ? std::format(" (was {:x})", (uintptr_t)oldParent.get()) : ""));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
CXDGToplevelResource::~CXDGToplevelResource() {
|
CXDGToplevelResource::~CXDGToplevelResource() {
|
||||||
events.destroy.emit();
|
events.destroy.emit();
|
||||||
|
if (parent)
|
||||||
|
std::erase_if(parent->children, [this](const auto& other) { return !other || other.get() == this; });
|
||||||
}
|
}
|
||||||
|
|
||||||
SP<CXDGToplevelResource> CXDGToplevelResource::fromResource(wl_resource* res) {
|
SP<CXDGToplevelResource> CXDGToplevelResource::fromResource(wl_resource* res) {
|
||||||
|
@ -227,6 +239,10 @@ bool CXDGToplevelResource::good() {
|
||||||
return resource->resource();
|
return resource->resource();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CXDGToplevelResource::anyChildModal() {
|
||||||
|
return std::ranges::any_of(children, [](const auto& child) { return child && child->dialog && child->dialog->modal; });
|
||||||
|
}
|
||||||
|
|
||||||
uint32_t CXDGToplevelResource::setSize(const Vector2D& size) {
|
uint32_t CXDGToplevelResource::setSize(const Vector2D& size) {
|
||||||
pendingApply.size = size;
|
pendingApply.size = size;
|
||||||
applyState();
|
applyState();
|
||||||
|
|
|
@ -18,6 +18,7 @@ class CXDGToplevelResource;
|
||||||
class CXDGPopupResource;
|
class CXDGPopupResource;
|
||||||
class CSeatGrab;
|
class CSeatGrab;
|
||||||
class CWLSurfaceResource;
|
class CWLSurfaceResource;
|
||||||
|
class CXDGDialogV1Resource;
|
||||||
|
|
||||||
struct SXDGPositionerState {
|
struct SXDGPositionerState {
|
||||||
Vector2D requestedSize;
|
Vector2D requestedSize;
|
||||||
|
@ -135,6 +136,11 @@ class CXDGToplevelResource {
|
||||||
} pending, current;
|
} pending, current;
|
||||||
|
|
||||||
WP<CXDGToplevelResource> parent;
|
WP<CXDGToplevelResource> parent;
|
||||||
|
WP<CXDGDialogV1Resource> dialog;
|
||||||
|
|
||||||
|
bool anyChildModal();
|
||||||
|
|
||||||
|
std::vector<WP<CXDGToplevelResource>> children;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SP<CXdgToplevel> resource;
|
SP<CXdgToplevel> resource;
|
||||||
|
|
|
@ -1378,7 +1378,6 @@ void CHyprOpenGLImpl::renderTextureInternalWithDamage(SP<CTexture> tex, CBox* pB
|
||||||
CBox newBox = *pBox;
|
CBox newBox = *pBox;
|
||||||
m_RenderData.renderModif.applyToBox(newBox);
|
m_RenderData.renderModif.applyToBox(newBox);
|
||||||
|
|
||||||
static auto PDIMINACTIVE = CConfigValue<Hyprlang::INT>("decoration:dim_inactive");
|
|
||||||
static auto PDT = CConfigValue<Hyprlang::INT>("debug:damage_tracking");
|
static auto PDT = CConfigValue<Hyprlang::INT>("debug:damage_tracking");
|
||||||
|
|
||||||
// get the needed transform for this texture
|
// get the needed transform for this texture
|
||||||
|
@ -1493,7 +1492,7 @@ void CHyprOpenGLImpl::renderTextureInternalWithDamage(SP<CTexture> tex, CBox* pB
|
||||||
glUniform2f(shader->fullSize, FULLSIZE.x, FULLSIZE.y);
|
glUniform2f(shader->fullSize, FULLSIZE.x, FULLSIZE.y);
|
||||||
glUniform1f(shader->radius, round);
|
glUniform1f(shader->radius, round);
|
||||||
|
|
||||||
if (allowDim && m_pCurrentWindow.lock() && *PDIMINACTIVE) {
|
if (allowDim && m_pCurrentWindow.lock()) {
|
||||||
glUniform1i(shader->applyTint, 1);
|
glUniform1i(shader->applyTint, 1);
|
||||||
const auto DIM = m_pCurrentWindow->m_fDimPercent.value();
|
const auto DIM = m_pCurrentWindow->m_fDimPercent.value();
|
||||||
glUniform3f(shader->tint, 1.f - DIM, 1.f - DIM, 1.f - DIM);
|
glUniform3f(shader->tint, 1.f - DIM, 1.f - DIM, 1.f - DIM);
|
||||||
|
|
Loading…
Reference in a new issue