mirror of
https://github.com/hyprwm/Hyprland.git
synced 2025-08-09 16:41:53 -07:00
internal: new shared_ptr and weak_ptr implementation (#5883)
moves std::shared_ptrs to a new implementation Advantages: - you can dereference a weak_ptr directly. This will obviously segfault on a nullptr deref if it's expired. - this is useful to avoid the .lock() hell where we are 100% sure the pointer _should_ be valid. (and if it isn't, it should throw.) - weak_ptrs are still valid while the SP is being destroyed. - reasoning: while an object (e.g. CWindow) is being destroyed, its `weak_ptr self` should be accessible (the sp is still alive, and so is CWindow), but it's not because by stl it's already expired (to prevent resurrection) - this impl solves it differently. w_p is expired, but can still be dereferenced and used. Creating `s_p`s is not possible anymore, though. - this is useful in destructors and callbacks.
This commit is contained in:
@@ -18,7 +18,7 @@ COutputManager::COutputManager(SP<CZwlrOutputManagerV1> resource_) : resource(re
|
||||
LOGM(LOG, "Creating new configuration");
|
||||
|
||||
const auto RESOURCE = PROTO::outputManagement->m_vConfigurations.emplace_back(
|
||||
std::make_shared<COutputConfiguration>(std::make_shared<CZwlrOutputConfigurationV1>(resource->client(), resource->version(), id), self.lock()));
|
||||
makeShared<COutputConfiguration>(makeShared<CZwlrOutputConfigurationV1>(resource->client(), resource->version(), id), self.lock()));
|
||||
|
||||
if (!RESOURCE->good()) {
|
||||
resource->noMemory();
|
||||
@@ -49,7 +49,7 @@ void COutputManager::makeAndSendNewHead(CMonitor* pMonitor) {
|
||||
return;
|
||||
|
||||
const auto RESOURCE =
|
||||
PROTO::outputManagement->m_vHeads.emplace_back(std::make_shared<COutputHead>(std::make_shared<CZwlrOutputHeadV1>(resource->client(), resource->version(), 0), pMonitor));
|
||||
PROTO::outputManagement->m_vHeads.emplace_back(makeShared<COutputHead>(makeShared<CZwlrOutputHeadV1>(resource->client(), resource->version(), 0), pMonitor));
|
||||
|
||||
if (!RESOURCE->good()) {
|
||||
resource->noMemory();
|
||||
@@ -205,8 +205,7 @@ void COutputHead::updateMode() {
|
||||
}
|
||||
|
||||
void COutputHead::makeAndSendNewMode(wlr_output_mode* mode) {
|
||||
const auto RESOURCE =
|
||||
PROTO::outputManagement->m_vModes.emplace_back(std::make_shared<COutputMode>(std::make_shared<CZwlrOutputModeV1>(resource->client(), resource->version(), 0), mode));
|
||||
const auto RESOURCE = PROTO::outputManagement->m_vModes.emplace_back(makeShared<COutputMode>(makeShared<CZwlrOutputModeV1>(resource->client(), resource->version(), 0), mode));
|
||||
|
||||
if (!RESOURCE->good()) {
|
||||
resource->noMemory();
|
||||
@@ -275,7 +274,7 @@ COutputConfiguration::COutputConfiguration(SP<CZwlrOutputConfigurationV1> resour
|
||||
}
|
||||
|
||||
const auto RESOURCE = PROTO::outputManagement->m_vConfigurationHeads.emplace_back(
|
||||
std::make_shared<COutputConfigurationHead>(std::make_shared<CZwlrOutputConfigurationHeadV1>(resource->client(), resource->version(), id), PMONITOR));
|
||||
makeShared<COutputConfigurationHead>(makeShared<CZwlrOutputConfigurationHeadV1>(resource->client(), resource->version(), id), PMONITOR));
|
||||
|
||||
if (!RESOURCE->good()) {
|
||||
resource->noMemory();
|
||||
@@ -326,7 +325,7 @@ COutputConfiguration::COutputConfiguration(SP<CZwlrOutputConfigurationV1> resour
|
||||
else
|
||||
resource->sendFailed();
|
||||
|
||||
owner.lock()->sendDone();
|
||||
owner->sendDone();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -359,8 +358,8 @@ bool COutputConfiguration::applyTestConfiguration(bool test) {
|
||||
newRule.name = PMONITOR->szName;
|
||||
|
||||
if (head->committedProperties & COutputConfigurationHead::eCommittedProperties::OUTPUT_HEAD_COMMITTED_MODE) {
|
||||
newRule.resolution = {head->state.mode.lock()->getMode()->width, head->state.mode.lock()->getMode()->height};
|
||||
newRule.refreshRate = head->state.mode.lock()->getMode()->refresh / 1000.F;
|
||||
newRule.resolution = {head->state.mode->getMode()->width, head->state.mode->getMode()->height};
|
||||
newRule.refreshRate = head->state.mode->getMode()->refresh / 1000.F;
|
||||
} else if (head->committedProperties & COutputConfigurationHead::eCommittedProperties::OUTPUT_HEAD_COMMITTED_CUSTOM_MODE) {
|
||||
newRule.resolution = head->state.customMode.size;
|
||||
newRule.refreshRate = head->state.customMode.refresh / 1000.F;
|
||||
@@ -539,7 +538,7 @@ COutputManagementProtocol::COutputManagementProtocol(const wl_interface* iface,
|
||||
}
|
||||
|
||||
void COutputManagementProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) {
|
||||
const auto RESOURCE = m_vManagers.emplace_back(std::make_shared<COutputManager>(std::make_shared<CZwlrOutputManagerV1>(client, ver, id)));
|
||||
const auto RESOURCE = m_vManagers.emplace_back(makeShared<COutputManager>(makeShared<CZwlrOutputManagerV1>(client, ver, id)));
|
||||
|
||||
if (!RESOURCE->good()) {
|
||||
wl_client_post_no_memory(client);
|
||||
|
Reference in New Issue
Block a user