Skip to content

Commit

Permalink
use internal content type enum
Browse files Browse the repository at this point in the history
  • Loading branch information
UjinT34 committed Feb 1, 2025
1 parent b12d020 commit 67b2366
Show file tree
Hide file tree
Showing 9 changed files with 124 additions and 107 deletions.
3 changes: 1 addition & 2 deletions src/Compositor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include <cstring>
#include <filesystem>
#include <ranges>
#include <print>
#include <unordered_set>
#include "debug/HyprCtl.hpp"
#include "debug/CrashReporter.hpp"
Expand Down Expand Up @@ -2336,7 +2335,7 @@ void CCompositor::setWindowFullscreenState(const PHLWINDOW PWINDOW, SFullscreenS

// send a scanout tranche if we are entering fullscreen, and send a regular one if we aren't.
// ignore if DS is disabled.
if (*PDIRECTSCANOUT == 1 || (*PDIRECTSCANOUT == 2 && PWINDOW->getContentType() == WP_CONTENT_TYPE_V1_TYPE_GAME))
if (*PDIRECTSCANOUT == 1 || (*PDIRECTSCANOUT == 2 && PWINDOW->getContentType() == NContentType::GAME))
g_pHyprRenderer->setSurfaceScanoutMode(PWINDOW->m_pWLSurface->resource(), EFFECTIVE_MODE != FSMODE_NONE ? PMONITOR->self.lock() : nullptr);

g_pConfigManager->ensureVRR(PMONITOR);
Expand Down
6 changes: 3 additions & 3 deletions src/desktop/Window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1731,11 +1731,11 @@ void CWindow::sendWindowSize(Vector2D size, bool force, std::optional<Vector2D>
m_vPendingSizeAcks.emplace_back(m_pXDGSurface->toplevel->setSize(size), size.floor());
}

wpContentTypeV1Type CWindow::getContentType() {
return m_pWLSurface->resource()->contentType.valid() ? m_pWLSurface->resource()->contentType->value : WP_CONTENT_TYPE_V1_TYPE_NONE;
NContentType::eContentType CWindow::getContentType() {
return m_pWLSurface->resource()->contentType.valid() ? m_pWLSurface->resource()->contentType->value : NContentType::NONE;
}

void CWindow::setContentType(wpContentTypeV1Type contentType) {
void CWindow::setContentType(NContentType::eContentType contentType) {
if (!m_pWLSurface->resource()->contentType.valid())
m_pWLSurface->resource()->contentType = PROTO::contentType->getContentType(m_pWLSurface->resource());
// else disallow content type change if proto is used?
Expand Down
164 changes: 82 additions & 82 deletions src/desktop/Window.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include "WLSurface.hpp"
#include "Workspace.hpp"
#include "WindowRule.hpp"
#include "../protocols/content-type-v1.hpp"
#include "protocols/types/ContentType.hpp"

class CXDGSurfaceResource;
class CXWaylandSurface;
Expand Down Expand Up @@ -394,87 +394,87 @@ class CWindow {
}

// methods
CBox getFullWindowBoundingBox();
SBoxExtents getFullWindowExtents();
CBox getWindowBoxUnified(uint64_t props);
CBox getWindowIdealBoundingBoxIgnoreReserved();
void addWindowDeco(UP<IHyprWindowDecoration> deco);
void updateWindowDecos();
void removeWindowDeco(IHyprWindowDecoration* deco);
void uncacheWindowDecos();
bool checkInputOnDecos(const eInputType, const Vector2D&, std::any = {});
pid_t getPID();
IHyprWindowDecoration* getDecorationByType(eDecorationType);
void updateToplevel();
void updateSurfaceScaleTransformDetails(bool force = false);
void moveToWorkspace(PHLWORKSPACE);
PHLWINDOW x11TransientFor();
void onUnmap();
void onMap();
void setHidden(bool hidden);
bool isHidden();
void applyDynamicRule(const SP<CWindowRule>& r);
void updateDynamicRules();
SBoxExtents getFullWindowReservedArea();
Vector2D middle();
bool opaque();
float rounding();
float roundingPower();
bool canBeTorn();
void setSuspended(bool suspend);
bool visibleOnMonitor(PHLMONITOR pMonitor);
WORKSPACEID workspaceID();
MONITORID monitorID();
bool onSpecialWorkspace();
void activate(bool force = false);
int surfacesCount();
void clampWindowSize(const std::optional<Vector2D> minSize, const std::optional<Vector2D> maxSize);
bool isFullscreen();
bool isEffectiveInternalFSMode(const eFullscreenMode);
int getRealBorderSize();
float getScrollMouse();
float getScrollTouchpad();
void updateWindowData();
void updateWindowData(const struct SWorkspaceRule&);
void onBorderAngleAnimEnd(WP<Hyprutils::Animation::CBaseAnimatedVariable> pav);
bool isInCurvedCorner(double x, double y);
bool hasPopupAt(const Vector2D& pos);
int popupsCount();
void applyGroupRules();
void createGroup();
void destroyGroup();
PHLWINDOW getGroupHead();
PHLWINDOW getGroupTail();
PHLWINDOW getGroupCurrent();
PHLWINDOW getGroupPrevious();
PHLWINDOW getGroupWindowByIndex(int);
int getGroupSize();
bool canBeGroupedInto(PHLWINDOW pWindow);
void setGroupCurrent(PHLWINDOW pWindow);
void insertWindowToGroup(PHLWINDOW pWindow);
void updateGroupOutputs();
void switchWithWindowInGroup(PHLWINDOW pWindow);
void setAnimationsToMove();
void onWorkspaceAnimUpdate();
void onFocusAnimUpdate();
void onUpdateState();
void onUpdateMeta();
void onX11Configure(CBox box);
void onResourceChangeX11();
std::string fetchTitle();
std::string fetchClass();
void warpCursor(bool force = false);
PHLWINDOW getSwallower();
void unsetWindowData(eOverridePriority priority);
bool isX11OverrideRedirect();
bool isModal();
Vector2D requestedMinSize();
Vector2D requestedMaxSize();
void sendWindowSize(Vector2D size, bool force = false, std::optional<Vector2D> overridePos = std::nullopt);
wpContentTypeV1Type getContentType();
void setContentType(wpContentTypeV1Type contentType);

CBox getWindowMainSurfaceBox() const {
CBox getFullWindowBoundingBox();
SBoxExtents getFullWindowExtents();
CBox getWindowBoxUnified(uint64_t props);
CBox getWindowIdealBoundingBoxIgnoreReserved();
void addWindowDeco(UP<IHyprWindowDecoration> deco);
void updateWindowDecos();
void removeWindowDeco(IHyprWindowDecoration* deco);
void uncacheWindowDecos();
bool checkInputOnDecos(const eInputType, const Vector2D&, std::any = {});
pid_t getPID();
IHyprWindowDecoration* getDecorationByType(eDecorationType);
void updateToplevel();
void updateSurfaceScaleTransformDetails(bool force = false);
void moveToWorkspace(PHLWORKSPACE);
PHLWINDOW x11TransientFor();
void onUnmap();
void onMap();
void setHidden(bool hidden);
bool isHidden();
void applyDynamicRule(const SP<CWindowRule>& r);
void updateDynamicRules();
SBoxExtents getFullWindowReservedArea();
Vector2D middle();
bool opaque();
float rounding();
float roundingPower();
bool canBeTorn();
void setSuspended(bool suspend);
bool visibleOnMonitor(PHLMONITOR pMonitor);
WORKSPACEID workspaceID();
MONITORID monitorID();
bool onSpecialWorkspace();
void activate(bool force = false);
int surfacesCount();
void clampWindowSize(const std::optional<Vector2D> minSize, const std::optional<Vector2D> maxSize);
bool isFullscreen();
bool isEffectiveInternalFSMode(const eFullscreenMode);
int getRealBorderSize();
float getScrollMouse();
float getScrollTouchpad();
void updateWindowData();
void updateWindowData(const struct SWorkspaceRule&);
void onBorderAngleAnimEnd(WP<Hyprutils::Animation::CBaseAnimatedVariable> pav);
bool isInCurvedCorner(double x, double y);
bool hasPopupAt(const Vector2D& pos);
int popupsCount();
void applyGroupRules();
void createGroup();
void destroyGroup();
PHLWINDOW getGroupHead();
PHLWINDOW getGroupTail();
PHLWINDOW getGroupCurrent();
PHLWINDOW getGroupPrevious();
PHLWINDOW getGroupWindowByIndex(int);
int getGroupSize();
bool canBeGroupedInto(PHLWINDOW pWindow);
void setGroupCurrent(PHLWINDOW pWindow);
void insertWindowToGroup(PHLWINDOW pWindow);
void updateGroupOutputs();
void switchWithWindowInGroup(PHLWINDOW pWindow);
void setAnimationsToMove();
void onWorkspaceAnimUpdate();
void onFocusAnimUpdate();
void onUpdateState();
void onUpdateMeta();
void onX11Configure(CBox box);
void onResourceChangeX11();
std::string fetchTitle();
std::string fetchClass();
void warpCursor(bool force = false);
PHLWINDOW getSwallower();
void unsetWindowData(eOverridePriority priority);
bool isX11OverrideRedirect();
bool isModal();
Vector2D requestedMinSize();
Vector2D requestedMaxSize();
void sendWindowSize(Vector2D size, bool force = false, std::optional<Vector2D> overridePos = std::nullopt);
NContentType::eContentType getContentType();
void setContentType(NContentType::eContentType contentType);

CBox getWindowMainSurfaceBox() const {
return {m_vRealPosition->value().x, m_vRealPosition->value().y, m_vRealSize->value().x, m_vRealSize->value().y};
}

Expand Down
4 changes: 1 addition & 3 deletions src/helpers/Monitor.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "Monitor.hpp"
#include "MiscFunctions.hpp"
#include "../macros.hpp"
#include "content-type-v1.hpp"
#include "math/Math.hpp"
#include "sync/SyncReleaser.hpp"
#include "../Compositor.hpp"
Expand All @@ -18,7 +17,6 @@
#include "../managers/PointerManager.hpp"
#include "../managers/eventLoop/EventLoopManager.hpp"
#include "../protocols/core/Compositor.hpp"
#include "../protocols/content-type-v1.hpp"
#include "../render/Renderer.hpp"
#include "../managers/EventManager.hpp"
#include "../managers/LayoutManager.hpp"
Expand Down Expand Up @@ -790,7 +788,7 @@ bool CMonitor::shouldSkipScheduleFrameOnMouseEvent() {

// skip scheduling extra frames for fullsreen apps with vrr
const bool shouldSkip = activeWorkspace && activeWorkspace->m_bHasFullscreenWindow && activeWorkspace->m_efFullscreenMode == FSMODE_FULLSCREEN &&
(*PNOBREAK == 1 || (*PNOBREAK == 2 && activeWorkspace->getFullscreenWindow()->getContentType() == WP_CONTENT_TYPE_V1_TYPE_GAME)) && output->state->state().adaptiveSync;
(*PNOBREAK == 1 || (*PNOBREAK == 2 && activeWorkspace->getFullscreenWindow()->getContentType() == NContentType::GAME)) && output->state->state().adaptiveSync;

// keep requested minimum refresh rate
if (shouldSkip && *PMINRR && lastPresentationTimer.getMillis() > 1000.0f / *PMINRR) {
Expand Down
3 changes: 2 additions & 1 deletion src/protocols/ContentType.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "ContentType.hpp"
#include "content-type-v1.hpp"
#include "protocols/types/ContentType.hpp"

CContentTypeManager::CContentTypeManager(SP<CWpContentTypeManagerV1> resource) : m_resource(resource) {
if UNLIKELY (!good())
Expand Down Expand Up @@ -53,7 +54,7 @@ CContentType::CContentType(SP<CWpContentTypeV1> resource) : m_resource(resource)
resource->setDestroy([this](CWpContentTypeV1* r) { PROTO::contentType->destroyResource(this); });
resource->setOnDestroy([this](CWpContentTypeV1* r) { PROTO::contentType->destroyResource(this); });

resource->setSetContentType([this](CWpContentTypeV1* r, wpContentTypeV1Type type) { value = type; });
resource->setSetContentType([this](CWpContentTypeV1* r, wpContentTypeV1Type type) { value = NContentType::fromWP(type); });
}

bool CContentType::good() {
Expand Down
9 changes: 5 additions & 4 deletions src/protocols/ContentType.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "WaylandProtocol.hpp"
#include "core/Compositor.hpp"
#include "content-type-v1.hpp"
#include "protocols/types/ContentType.hpp"

class CContentTypeManager {
public:
Expand All @@ -19,11 +20,11 @@ class CContentType {
CContentType(SP<CWpContentTypeV1> resource);
CContentType(WP<CWLSurfaceResource> surface);

bool good();
wl_client* client();
wpContentTypeV1Type value = WP_CONTENT_TYPE_V1_TYPE_NONE;
bool good();
wl_client* client();
NContentType::eContentType value = NContentType::NONE;

WP<CContentType> self;
WP<CContentType> self;

private:
SP<CWpContentTypeV1> m_resource;
Expand Down
25 changes: 17 additions & 8 deletions src/protocols/types/ContentType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,32 @@
#include <format>

namespace NContentType {
static std::unordered_map<std::string, wpContentTypeV1Type> const table = {
{"none", WP_CONTENT_TYPE_V1_TYPE_NONE}, {"photo", WP_CONTENT_TYPE_V1_TYPE_PHOTO}, {"video", WP_CONTENT_TYPE_V1_TYPE_VIDEO}, {"game", WP_CONTENT_TYPE_V1_TYPE_GAME}};
static std::unordered_map<std::string, eContentType> const table = {{"none", NONE}, {"photo", PHOTO}, {"video", VIDEO}, {"game", GAME}};

wpContentTypeV1Type fromString(const std::string name) {
eContentType fromString(const std::string name) {
auto it = table.find(name);
if (it != table.end())
return it->second;
else
throw std::invalid_argument(std::format("Unknown content type {}", name));
}

uint16_t toDRM(wpContentTypeV1Type contentType) {
eContentType fromWP(wpContentTypeV1Type contentType) {
switch (contentType) {
case WP_CONTENT_TYPE_V1_TYPE_NONE: return DRM_MODE_CONTENT_TYPE_GRAPHICS;
case WP_CONTENT_TYPE_V1_TYPE_PHOTO: return DRM_MODE_CONTENT_TYPE_PHOTO;
case WP_CONTENT_TYPE_V1_TYPE_VIDEO: return DRM_MODE_CONTENT_TYPE_CINEMA;
case WP_CONTENT_TYPE_V1_TYPE_GAME: return DRM_MODE_CONTENT_TYPE_GAME;
case WP_CONTENT_TYPE_V1_TYPE_NONE: return NONE;
case WP_CONTENT_TYPE_V1_TYPE_PHOTO: return PHOTO;
case WP_CONTENT_TYPE_V1_TYPE_VIDEO: return VIDEO;
case WP_CONTENT_TYPE_V1_TYPE_GAME: return GAME;
default: return NONE;
}
}

uint16_t toDRM(eContentType contentType) {
switch (contentType) {
case NONE: return DRM_MODE_CONTENT_TYPE_GRAPHICS;
case PHOTO: return DRM_MODE_CONTENT_TYPE_PHOTO;
case VIDEO: return DRM_MODE_CONTENT_TYPE_CINEMA;
case GAME: return DRM_MODE_CONTENT_TYPE_GAME;
default: return DRM_MODE_CONTENT_TYPE_NO_DATA;
}
}
Expand Down
13 changes: 11 additions & 2 deletions src/protocols/types/ContentType.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@
#include <cstdint>

namespace NContentType {
wpContentTypeV1Type fromString(const std::string name);
uint16_t toDRM(wpContentTypeV1Type contentType);

enum eContentType : uint8_t {
NONE = 0,
PHOTO = 1,
VIDEO = 2,
GAME = 3,
};

eContentType fromString(const std::string name);
eContentType fromWP(wpContentTypeV1Type contentType);
uint16_t toDRM(eContentType contentType);
}
4 changes: 2 additions & 2 deletions src/render/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1194,7 +1194,7 @@ void CHyprRenderer::renderMonitor(PHLMONITOR pMonitor) {

pMonitor->tearingState.activelyTearing = shouldTear;

if ((*PDIRECTSCANOUT == 1 || (*PDIRECTSCANOUT == 2 && pMonitor->activeWorkspace->getFullscreenWindow()->getContentType() == WP_CONTENT_TYPE_V1_TYPE_GAME)) && !shouldTear) {
if ((*PDIRECTSCANOUT == 1 || (*PDIRECTSCANOUT == 2 && pMonitor->activeWorkspace->getFullscreenWindow()->getContentType() == NContentType::GAME)) && !shouldTear) {
if (pMonitor->attemptDirectScanout()) {
return;
} else if (!pMonitor->lastScanout.expired()) {
Expand Down Expand Up @@ -1516,7 +1516,7 @@ bool CHyprRenderer::commitPendingAndDoExplicitSync(PHLMONITOR pMonitor) {
const auto WINDOW = pMonitor->activeWorkspace->getFullscreenWindow();
pMonitor->output->state->setContentType(NContentType::toDRM(WINDOW->getContentType()));
} else
pMonitor->output->state->setContentType(NContentType::toDRM(WP_CONTENT_TYPE_V1_TYPE_NONE));
pMonitor->output->state->setContentType(NContentType::toDRM(NContentType::NONE));
#endif

if (pMonitor->ctmUpdated) {
Expand Down

0 comments on commit 67b2366

Please sign in to comment.