-
-
Notifications
You must be signed in to change notification settings - Fork 912
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
186 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; }); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters